MvnDependencyTreeAnalyzer extends AbstractAnalyzer { @Override public WorkflowStepResult yield() { Optional<WrappedDependencyNodes> wrappedProjectsOptional = context.getGeneric(WrappedDependencyNodes.class); if (!wrappedProjectsOptional.isPresent()) { throw new ExecutionException("No Maven dependency tree was provided for analysis."); } List<DependencyNode> projectList = wrappedProjectsOptional.get().getDependencyNodes(); final List<Artifact> collect = projectList.stream() .map(this::getArtifactFromNode) .collect(Collectors.toList()); return new WorkflowStepResult(collect); } MvnDependencyTreeAnalyzer(); @Override WorkflowStepResult yield(); @Override String getName();  }
@Test public void testProjectIsAnalyzedCorrectly() { MvnDependencyTreeAnalyzer analyzer = new MvnDependencyTreeAnalyzer(); analyzer.setAntennaContext(antennaContextMock); when(antennaContextMock.getGeneric(WrappedDependencyNodes.class)) .thenReturn(Optional.of(getNodes(1))); WorkflowStepResult result = analyzer.yield(); assertThat(result.getArtifacts()).hasSize(1); Artifact actualArtifact = result.getArtifacts().iterator().next(); Artifact expectedArtifact = getExpectedArtifact(0); assertThat(actualArtifact.getAnalysisSource()).isEqualTo(expectedArtifact.getAnalysisSource()); assertThat(actualArtifact.askFor(ArtifactMatchingMetadata.class).get().getMatchState()) .isEqualTo(expectedArtifact.askFor(ArtifactMatchingMetadata.class).get().getMatchState()); assertThat(actualArtifact.getArtifactIdentifiers()) .isEqualTo(expectedArtifact.getArtifactIdentifiers()); }
@Test public void testResultSize() { int size = 3; MvnDependencyTreeAnalyzer analyzer = new MvnDependencyTreeAnalyzer(); analyzer.setAntennaContext(antennaContextMock); when(antennaContextMock.getGeneric(WrappedDependencyNodes.class)) .thenReturn(Optional.of(getNodes(size))); WorkflowStepResult result = analyzer.yield(); assertThat(result.getArtifacts()).hasSize(size); }