CmdGenerator implements ResourceGenerator<RunAsParams> { @NotNull @Override public String create(@NotNull final RunAsParams settings) { final StringBuilder sb = new StringBuilder(); sb.append("@ECHO OFF"); sb.append(LINE_SEPARATOR); boolean first = true; for (CommandLineArgument arg: settings.getCommandLineArguments()) { if(first) { first = false; } else { sb.append(' '); } sb.append(myArgumentConverter.convert(arg.getValue())); } sb.append(LINE_SEPARATOR); sb.append("SET \"EXIT_CODE=%ERRORLEVEL%\""); sb.append(LINE_SEPARATOR); sb.append("EXIT /B %EXIT_CODE%"); return sb.toString(); } CmdGenerator(
    @NotNull final Converter<String, String> argumentConverter); @NotNull @Override String create(@NotNull final RunAsParams settings);  }
@Test(dataProvider = "cmdLinesCases") public void shouldGenerateContent(@NotNull final RunAsParams runAsParams, @NotNull final String expectedCmdLine) { final ResourceGenerator<RunAsParams> instance = createInstance(); myCtx.checking(new Expectations() {{ allowing(myArgumentConverter).convert(with(any(String.class))); will(new CustomAction("convert") { @Override public Object invoke(final Invocation invocation) throws Throwable { return "'" + invocation.getParameter(0) + "'"; } }); }}); final String content = instance.create(runAsParams); then(content).isEqualTo("@ECHO OFF" + LINE_SEPARATOR + expectedCmdLine + LINE_SEPARATOR + "SET \"EXIT_CODE=%ERRORLEVEL%\"" + LINE_SEPARATOR + "EXIT /B %EXIT_CODE%"); }