### Question:
DomainMapperMojo extends AbstractMojo { @Override public void execute() throws MojoExecutionException, MojoFailureException { if (packages.isEmpty()) throw new MojoFailureException("No packages defined for scanning."); try { List<URL> projectClasspathList = getClasspathUrls(); DomainMapper mapper = DomainMapper.create(packages, new URLClassLoader(projectClasspathList.toArray(new URL[projectClasspathList.size()]))); Files.write(Paths.get(outputDirectory.getPath(), "domainmap.dot"), mapper.describeDomain().getBytes()); } catch (ClassNotFoundException | DependencyResolutionRequiredException | IOException e) { throw new MojoExecutionException(e.getMessage(), e); } }  @Override void execute();  }### Answer:
@SuppressWarnings({"rawtypes", "unchecked"}) @Test public void testExecute() throws MojoExecutionException, ClassNotFoundException, MojoFailureException, IOException { packages.add("com.nitorcreations.testdomain"); mojo.execute(); assertThat(Files.exists(Paths.get("domainmap.dot")), is(true)); Files.delete(Paths.get("domainmap.dot")); }
@Test(expected = MojoFailureException.class) public void failsWithNoPackagesDefined() throws MojoExecutionException, ClassNotFoundException, MojoFailureException { mojo.execute(); }