ScanArtifactMojo extends AbstractITestWithPlanMojo { final @NotNull File getScanArtifactFile() throws MojoFailureException { Optional<File> packageArtifact = getProject() .flatMap(p -> Optional.ofNullable(p.getArtifact())) .flatMap(a -> Optional.ofNullable(a.getFile())); if (packageArtifact.isPresent() && packageArtifact.get().exists()) { return packageArtifact.get(); } else { throw new MojoFailureException("Failed to resolve file for project artifact."); } }   @Parameter(property = "oakpal.scan.skip")
    public boolean skip; }
@Test(expected = MojoFailureException.class) public void testGetScanArtifactFile_failWhenEmpty() throws Exception { newMojo().getScanArtifactFile(); }
@Test public void testGetScanArtifactFile() throws Exception { final File testOutDir = new File(testOutBaseDir, "testGetScanArtifactFile"); FileUtils.deleteDirectory(testOutDir); testOutDir.mkdirs(); final File artifactFile = new File(testOutDir, "test-artifact.zip"); FileUtils.touch(artifactFile); final MavenProject project = mock(MavenProject.class); ScanArtifactMojo mojo = newMojo(); mojo.project = project; final Artifact artifact = mock(Artifact.class); when(project.getArtifact()).thenReturn(artifact); when(artifact.getFile()).thenReturn(artifactFile); assertSame("expect same artifact", artifactFile, mojo.getScanArtifactFile()); }