Search in sources :

Example 6 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class ApplicableEvaluatorTest method testEvaluationSuccess.

@Test
public void testEvaluationSuccess() {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ApplicableEvaluator evaluator = new ApplicableEvaluator(evaluationOptions);
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, false, true);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).applicableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setDetectableEnvironment(Mockito.any(DetectableEnvironment.class));
    Mockito.verify(detectorEvaluation).setDetectable(Mockito.any(Detectable.class));
    Mockito.verify(detectorEvaluatorListener).applicableEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Detectable(com.synopsys.integration.detectable.Detectable) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Example 7 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class ApplicableEvaluatorTest method testEvaluationNotApplicable.

@Test
public void testEvaluationNotApplicable() {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ApplicableEvaluator evaluator = new ApplicableEvaluator(evaluationOptions);
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, true, true);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).applicableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setDetectableEnvironment(Mockito.any(DetectableEnvironment.class));
    Mockito.verify(detectorEvaluation).setDetectable(Mockito.any(Detectable.class));
    Mockito.verify(detectorEvaluatorListener).applicableEnded(detectorEvaluation);
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Detectable(com.synopsys.integration.detectable.Detectable) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) Test(org.junit.jupiter.api.Test)

Example 8 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class DetectorAggregateEvaluationResultTest method generateDetectorEvaluationTreeMock.

@NotNull
private DetectorEvaluationTree generateDetectorEvaluationTreeMock(DetectorType detectorType) {
    DetectorEvaluationTree evaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    List<DetectorEvaluation> evaluations = new ArrayList<>();
    DetectorEvaluation topLevelEvaluation = Mockito.mock(DetectorEvaluation.class);
    Mockito.when(topLevelEvaluation.isApplicable()).thenReturn(true);
    DetectorRule rule = Mockito.mock(DetectorRule.class);
    Mockito.when(rule.getDetectorType()).thenReturn(detectorType);
    Mockito.when(topLevelEvaluation.getDetectorRule()).thenReturn(rule);
    evaluations.add(topLevelEvaluation);
    Mockito.when(evaluationTree.getOrderedEvaluations()).thenReturn(evaluations);
    return evaluationTree;
}
Also used : DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ArrayList(java.util.ArrayList) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) NotNull(org.jetbrains.annotations.NotNull)

Example 9 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class DetectorEvaluatorTest method testEvaluation.

@Test
public void testEvaluation() {
    DetectorEvaluatorListener listener = Mockito.mock(DetectorEvaluatorListener.class);
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
    DetectorEvaluationTree rootEvaluation = Mockito.mock(DetectorEvaluationTree.class);
    DetectorEvaluator detectorEvaluator = new DetectorEvaluator(evaluationOptions, extractionEnvironmentProvider);
    detectorEvaluator.setDetectorEvaluatorListener(listener);
    DetectorAggregateEvaluationResult result = detectorEvaluator.evaluate(rootEvaluation);
    Optional<DetectorEvaluatorListener> actualListener = detectorEvaluator.getDetectorEvaluatorListener();
    assertTrue(actualListener.isPresent());
    assertEquals(listener, actualListener.get());
    assertEquals(rootEvaluation, result.getEvaluationTree());
}
Also used : Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Assertions.assertTrue(org.junit.jupiter.api.Assertions.assertTrue) Optional(java.util.Optional) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Function(java.util.function.Function) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Test(org.junit.jupiter.api.Test)

Example 10 with DetectorEvaluation

use of com.synopsys.integration.detector.base.DetectorEvaluation in project synopsys-detect by blackducksoftware.

the class ExtractableEvaluatorTest method testEvaluationExtractableAlreadyPerformed.

@Test
public void testEvaluationExtractableAlreadyPerformed() throws DetectableException {
    DetectorEvaluationOptions evaluationOptions = Mockito.mock(DetectorEvaluationOptions.class);
    ExtractionEnvironment extractionEnvironment = Mockito.mock(ExtractionEnvironment.class);
    Function<DetectorEvaluation, ExtractionEnvironment> extractionEnvironmentProvider = (detectorEvaluation) -> extractionEnvironment;
    ExtractableEvaluator evaluator = new ExtractableEvaluator(evaluationOptions, extractionEnvironmentProvider);
    DetectorEvaluationTree detectorEvaluationTree = Mockito.mock(DetectorEvaluationTree.class);
    Mockito.when(detectorEvaluationTree.getDirectory()).thenReturn(new File("."));
    DetectorEvaluatorListener detectorEvaluatorListener = Mockito.mock(DetectorEvaluatorListener.class);
    evaluator.setDetectorEvaluatorListener(detectorEvaluatorListener);
    DetectorEvaluation detectorEvaluation = createEvaluationMocks(evaluationOptions, detectorEvaluationTree, true, false);
    DetectorAggregateEvaluationResult result = evaluator.evaluate(detectorEvaluationTree);
    assertEquals(detectorEvaluationTree, result.getEvaluationTree());
    Mockito.verify(detectorEvaluatorListener).extractableStarted(detectorEvaluation);
    Mockito.verify(detectorEvaluation).setExtractable(Mockito.any(DetectorResult.class));
    Mockito.verify(detectorEvaluatorListener).extractableEnded(detectorEvaluation);
}
Also used : DetectableResult(com.synopsys.integration.detectable.detectable.result.DetectableResult) Predicate(java.util.function.Predicate) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) Function(java.util.function.Function) File(java.io.File) Test(org.junit.jupiter.api.Test) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) Mockito(org.mockito.Mockito) List(java.util.List) DetectorRule(com.synopsys.integration.detector.rule.DetectorRule) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) Detectable(com.synopsys.integration.detectable.Detectable) DetectableEnvironment(com.synopsys.integration.detectable.DetectableEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) Assertions.assertEquals(org.junit.jupiter.api.Assertions.assertEquals) DetectableException(com.synopsys.integration.detectable.detectable.exception.DetectableException) DetectorRuleSet(com.synopsys.integration.detector.rule.DetectorRuleSet) Collections(java.util.Collections) PassedDetectableResult(com.synopsys.integration.detectable.detectable.result.PassedDetectableResult) DetectorEvaluationTree(com.synopsys.integration.detector.base.DetectorEvaluationTree) ExtractionEnvironment(com.synopsys.integration.detectable.extraction.ExtractionEnvironment) DetectorResult(com.synopsys.integration.detector.result.DetectorResult) DetectorEvaluation(com.synopsys.integration.detector.base.DetectorEvaluation) File(java.io.File) Test(org.junit.jupiter.api.Test)

Aggregations

DetectorEvaluation (com.synopsys.integration.detector.base.DetectorEvaluation)30 DetectorEvaluationTree (com.synopsys.integration.detector.base.DetectorEvaluationTree)28 File (java.io.File)15 Test (org.junit.jupiter.api.Test)14 DetectableEnvironment (com.synopsys.integration.detectable.DetectableEnvironment)11 Detectable (com.synopsys.integration.detectable.Detectable)10 DetectorRule (com.synopsys.integration.detector.rule.DetectorRule)9 DetectorResult (com.synopsys.integration.detector.result.DetectorResult)8 DetectableResult (com.synopsys.integration.detectable.detectable.result.DetectableResult)7 ExtractionEnvironment (com.synopsys.integration.detectable.extraction.ExtractionEnvironment)7 List (java.util.List)7 Assertions.assertEquals (org.junit.jupiter.api.Assertions.assertEquals)7 Mockito (org.mockito.Mockito)7 Collections (java.util.Collections)6 DetectableException (com.synopsys.integration.detectable.detectable.exception.DetectableException)5 PassedDetectableResult (com.synopsys.integration.detectable.detectable.result.PassedDetectableResult)5 Extraction (com.synopsys.integration.detectable.extraction.Extraction)5 DetectorRuleSet (com.synopsys.integration.detector.rule.DetectorRuleSet)5 Function (java.util.function.Function)5 Predicate (java.util.function.Predicate)5