ValidateTargetMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { File outputDirectory = new File( this.project.getBuild().getOutputDirectory()); if( ! outputDirectory.isDirectory()) throw new MojoExecutionException( "The target directory could not be found. " + outputDirectory ); List<ModelError> errors = TargetValidator.parseDirectory( outputDirectory ); MavenPluginUtils.formatErrors( errors, getLog()); if( RoboconfErrorHelpers.containsCriticalErrors( errors )) throw new MojoFailureException( "The project contains one or several errors." ); }  @Override void execute();  }
@Test( expected = MojoFailureException.class ) public void testEmptyTargetProject() throws Exception { ValidateTargetMojo mojo = (ValidateTargetMojo) super.findMojo( "target-ok-single", "validate-target" ); MavenProject project = (MavenProject) this.rule.getVariableValueFromObject( mojo, "project" ); Assert.assertNotNull( project ); Utils.createDirectory( new File( project.getBuild().getOutputDirectory())); mojo.execute(); }