### Question:
SampleMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException { if (outputDirectory == null) { throw new MojoExecutionException("outputDirectory is required"); } getLog().info("sample plugin start!"); getLog().debug("outputDirectory is " + outputDirectory.getAbsolutePath()); }  @Override void execute();  }### Answer:
@Test public void testMojoHasHelpGoal() throws Exception { File baseDir = resources.getBasedir("no-output-dir"); File pom = new File(baseDir, "pom.xml"); Mojo samplePlugin = mojo.lookupMojo("help", pom); assertNotNull(samplePlugin); samplePlugin.setLog(log); samplePlugin.execute(); }
@Test(expected = MojoExecutionException.class) public void testSampleGoalRequiresOutputDir() throws Exception { File baseDir = resources.getBasedir("no-output-dir"); File pom = new File(baseDir, "pom.xml"); Mojo samplePlugin = mojo.lookupMojo("sample", pom); samplePlugin.execute(); }
@Test public void testSampleGoalPrintsOutputDirectory() throws Exception { File baseDir = resources.getBasedir("simple"); File pom = new File(baseDir, "pom.xml"); Mojo samplePlugin = mojo.lookupMojo("sample", pom); samplePlugin.setLog(log); samplePlugin.execute(); Mockito.verify(log).debug("outputDirectory is /tmp/target"); }