CreateMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { try { getLog().info(String.format("Preparing contents for plugin: %s", pluginName)); preparePluginContents(); } catch (Exception e) { throw new MojoExecutionException(String.format("Failed to prepare contents for plugin [%s]", pluginName), e); } }  @Override void execute();  }
@Test public void testExecute() throws Exception { CreateMojo mojo = (CreateMojo) rule.lookupConfiguredMojo(mavenProject, "create"); assertThat(mojo, notNullValue()); mojo.execute(); Path generatedDataDir = targetDir.resolve("plugin-generator"); assertThat(generatedDataDir, exists()); assertThat(generatedDataDir, isDirectory()); Path pluginFile = generatedDataDir.resolve("plugin-test-1.0.jar"); assertThat(pluginFile, exists()); assertThat(pluginFile, isRegularFile()); Path pluginDataDir = generatedDataDir.resolve("data"); assertThat(pluginDataDir, exists()); assertThat(pluginDataDir, isDirectory()); Path libDir = pluginDataDir.resolve("lib"); assertThat(libDir, exists()); assertThat(libDir, isDirectory()); Path dependencyFile = libDir.resolve(ARTIFACT_FILE); assertThat(dependencyFile, exists()); assertThat(dependencyFile, isRegularFile()); }