EchoMojo extends AbstractMojo { void setup() throws MojoFailureException { try { PluginParameters pluginParameters = new PluginParametersBuilder() .setMessage(message, fromFile) .setFile(basePath, toFile, append, force) .setLevel(level) .setFormatting(encoding, lineSeparator) .setDebug(characterOutput) .createPluginParameters(); echoPlugin = new EchoPlugin(mavenLogger, pluginParameters, echoOutput); } catch (FailureException fex) { new ExceptionHandler(fex).throwMojoFailureException(); } }  @Override void execute();  }
@Test public void setupShouldSetupEchoPluginInstance() throws Exception { echoMojo.setup(); EchoPlugin echoPlugin = new ReflectionHelper(echoMojo).getField(EchoPlugin.class); assertThat(echoPlugin, notNullValue()); }
@Test public void exceptionInSetupShouldBeConverted() throws Exception { new ReflectionHelper(echoMojo).setField("level", "Gurka"); expectedException.expect(MojoFailureException.class); expectedException.expectMessage(is("level must be either FAIL, ERROR, WARNING, INFO or DEBUG. Was: Gurka")); echoMojo.setup(); }