RunAsSetupBuilder implements CommandLineSetupBuilder { @NotNull @Override public Iterable<CommandLineSetup> build(@NotNull final CommandLineSetup commandLineSetup) { CommandLineSetupBuilder setupBuilder = myRunAsUnixSetupBuilder; switch (myEnvironment.getOperationSystem()) { case Windows: setupBuilder = myRunAsWindowsSetupBuilder; break; case Mac: setupBuilder = myRunAsMacSetupBuilder; break; } return setupBuilder.build(commandLineSetup); } RunAsSetupBuilder(
    @NotNull final Environment environment,
    @NotNull final CommandLineSetupBuilder runAsWindowsSetupBuilder,
    @NotNull final CommandLineSetupBuilder runAsUnixSetupBuilder,
    @NotNull final CommandLineSetupBuilder runAsMacSetupBuilder); @NotNull @Override Iterable<CommandLineSetup> build(@NotNull final CommandLineSetup commandLineSetup);  }
@Test() public void shouldBuildSetupWhenWindows() { final CommandLineSetup commandLineSetup = new CommandLineSetup("aa", new ArrayList<CommandLineArgument>(), new ArrayList<CommandLineResource>()); final CommandLineSetup runAsCommandLineSetup = new CommandLineSetup("aa", new ArrayList<CommandLineArgument>(), new ArrayList<CommandLineResource>()); myCtx.checking(new Expectations() {{ oneOf(myEnvironment).getOperationSystem(); will(returnValue(OperationSystem.Windows)); oneOf(myRunAsWindowsSetupBuilder).build(commandLineSetup); will(returnValue(Arrays.asList(runAsCommandLineSetup))); never(myRunAsUnixSetupBuilder).build(commandLineSetup); never(myRunAsMacSetupBuilder).build(commandLineSetup); }}); final CommandLineSetupBuilder instance = createInstance(); final CommandLineSetup setup = instance.build(commandLineSetup).iterator().next(); myCtx.assertIsSatisfied(); then(setup).isEqualTo(runAsCommandLineSetup); }
@Test() public void shouldBuildSetupWhenLinux() { final CommandLineSetup commandLineSetup = new CommandLineSetup("aa", new ArrayList<CommandLineArgument>(), new ArrayList<CommandLineResource>()); final CommandLineSetup runAsCommandLineSetup = new CommandLineSetup("aa", new ArrayList<CommandLineArgument>(), new ArrayList<CommandLineResource>()); myCtx.checking(new Expectations() {{ oneOf(myEnvironment).getOperationSystem(); will(returnValue(OperationSystem.Other)); oneOf(myRunAsUnixSetupBuilder).build(commandLineSetup); will(returnValue(Arrays.asList(runAsCommandLineSetup))); never(myRunAsWindowsSetupBuilder).build(commandLineSetup); never(myRunAsMacSetupBuilder).build(commandLineSetup); }}); final CommandLineSetupBuilder instance = createInstance(); final CommandLineSetup setup = instance.build(commandLineSetup).iterator().next(); myCtx.assertIsSatisfied(); then(setup).isEqualTo(runAsCommandLineSetup); }
@Test() public void shouldBuildSetupWhenMac() { final CommandLineSetup commandLineSetup = new CommandLineSetup("aa", new ArrayList<CommandLineArgument>(), new ArrayList<CommandLineResource>()); final CommandLineSetup runAsCommandLineSetup = new CommandLineSetup("aa", new ArrayList<CommandLineArgument>(), new ArrayList<CommandLineResource>()); myCtx.checking(new Expectations() {{ oneOf(myEnvironment).getOperationSystem(); will(returnValue(OperationSystem.Mac)); oneOf(myRunAsMacSetupBuilder).build(commandLineSetup); will(returnValue(Arrays.asList(runAsCommandLineSetup))); never(myRunAsWindowsSetupBuilder).build(commandLineSetup); never(myRunAsUnixSetupBuilder).build(commandLineSetup); }}); final CommandLineSetupBuilder instance = createInstance(); final CommandLineSetup setup = instance.build(commandLineSetup).iterator().next(); myCtx.assertIsSatisfied(); then(setup).isEqualTo(runAsCommandLineSetup); }