NinjaRunMojo extends AbstractMojo { protected void alertAndStopExecutionIfDirectoryWithCompiledClassesOfThisProjectDoesNotExist( String directoryWithCompiledClassesOfThisProject) throws MojoExecutionException { File classesDir = null; if (directoryWithCompiledClassesOfThisProject != null) { classesDir = new File(directoryWithCompiledClassesOfThisProject); } if (classesDir == null || !classesDir.exists()) { getLog().error("Directory with classes does not exist: " + directoryWithCompiledClassesOfThisProject); getLog().error("Maybe running 'mvn compile' before running 'mvn ninja:run' helps :)"); throw new MojoExecutionException("Directory with classes does not exist: " + directoryWithCompiledClassesOfThisProject); } }  @Override void execute();  }
@Test public void alertAndStopExecutionIfDirectoryWithCompiledClassesOfThisProjectDoesNotExist() throws Exception { ninjaRunMojo.buildOutputDirectory = "target/doesnotexist"; try { ninjaRunMojo.execute(); fail(); } catch (MojoExecutionException e) { assertThat(e.getMessage(), containsString("Directory with classes does not exist")); } }