test(sbt): Added multiple project node test.
@@ -3,6 +3,7 @@ package com.synopsys.integration.detectable.detectables.sbt.unit;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.nio.charset.StandardCharsets;
+import java.util.Set;
import org.junit.Test;
import org.junit.jupiter.api.Assertions;
@@ -13,6 +14,7 @@ import com.synopsys.integration.detectable.detectable.exception.DetectableExcept
import com.synopsys.integration.detectable.detectables.sbt.dot.SbtDotGraphNodeParser;
import com.synopsys.integration.detectable.detectables.sbt.dot.SbtRootNodeFinder;
+@SuppressWarnings("OptionalGetWithoutIsPresent")
public class SbtRootNodeFinderTest {
private GraphParser createGraphParser(String actualGraph) {
@@ -40,8 +42,9 @@ public class SbtRootNodeFinderTest {
public void projectFoundFromSingleNode() throws DetectableException {
GraphParser graphParser = createGraphParser(node("one-org", "one-name", "one-version"));
SbtRootNodeFinder projectMatcher = new SbtRootNodeFinder(new SbtDotGraphNodeParser(new ExternalIdFactory()));
- String projectId = projectMatcher.determineRootIDs(graphParser);
- Assertions.assertEquals("\"one-org:one-name:one-version\"", projectId);
+ Set<String> projectId = projectMatcher.determineRootIDs(graphParser);
+ Assertions.assertEquals(1, projectId.size());
+ Assertions.assertEquals("\"one-org:one-name:one-version\"", projectId.stream().findFirst().get());
}
@Test
@@ -50,8 +53,33 @@ public class SbtRootNodeFinderTest {
node("one-org", "one-name", "one-version") +
edge("one-org", "one-name", "one-version", "two-org", "two-name", "two-version"));
SbtRootNodeFinder projectMatcher = new SbtRootNodeFinder(new SbtDotGraphNodeParser(new ExternalIdFactory()));
- String projectId = projectMatcher.determineRootIDs(graphParser);
- Assertions.assertEquals("\"one-org:one-name:one-version\"", projectId);
+ Set<String> projectId = projectMatcher.determineRootIDs(graphParser);
+ Assertions.assertEquals(1, projectId.size());
+ Assertions.assertEquals("\"one-org:one-name:one-version\"", projectId.stream().findFirst().get());
+ }
+
+ @Test
+ public void multipleFoundWithNoEdges() throws DetectableException {
+ GraphParser graphParser = createGraphParser(node("one-org", "one-name", "one-version") +
+ node("one-org", "one-name", "two-version"));
+ SbtRootNodeFinder projectMatcher = new SbtRootNodeFinder(new SbtDotGraphNodeParser(new ExternalIdFactory()));
+ Set<String> projectId = projectMatcher.determineRootIDs(graphParser);
+ Assertions.assertEquals(2, projectId.size());
+ Assertions.assertTrue(projectId.contains("\"one-org:one-name:one-version\""));
+ Assertions.assertTrue(projectId.contains("\"one-org:one-name:two-version\""));
+ }
+
+ @Test
+ public void multipleFoundWithEdge() throws DetectableException {
+ GraphParser graphParser = createGraphParser(node("one-org", "one-name", "one-version") +
+ node("one-org", "one-name", "two-version") +
+ node("one-org", "one-name", "three-version") + //should not be reported
+ edge("one-org", "one-name", "one-version", "one-org", "one-name", "three-version"));
+ SbtRootNodeFinder projectMatcher = new SbtRootNodeFinder(new SbtDotGraphNodeParser(new ExternalIdFactory()));
+ Set<String> projectId = projectMatcher.determineRootIDs(graphParser);
+ Assertions.assertEquals(2, projectId.size());
+ Assertions.assertTrue(projectId.contains("\"one-org:one-name:one-version\""));
+ Assertions.assertTrue(projectId.contains("\"one-org:one-name:two-version\""));
}
}
