Skip to content

Commit

Permalink
Test DefaultCallGraph
Browse files Browse the repository at this point in the history
  • Loading branch information
cesarsotovalero committed Apr 5, 2022
1 parent 38d59a6 commit 139c48a
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,8 +90,7 @@ static Set<String> getConstantPoolClassReferences(byte[] b) {
}

static Set<String> parseConstantPoolClassReferences(ByteBuffer buf) {
if (buf.order(ByteOrder.BIG_ENDIAN)
.getInt() != HEAD) {
if (buf.order(ByteOrder.BIG_ENDIAN).getInt() != HEAD) {
return Collections.emptySet();
}
buf.getChar();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -110,7 +110,7 @@ public static void cleanDirectedGraph() {
directedGraph.edgeSet().clear();
}

public Map<String, Set<String>> getUsagesPerClass() {
public static Map<String, Set<String>> getUsagesPerClass() {
return usagesPerClass;
}

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
package se.kth.depclean.core.analysis.graph;

import java.util.Arrays;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;

class DefaultCallGraphTest {

@BeforeEach
void setUp() {
DefaultCallGraph.addEdge("A", new HashSet<>(Arrays.asList("B", "C", "D")));
DefaultCallGraph.addEdge("D", new HashSet<>(Arrays.asList("E", "F")));
DefaultCallGraph.addEdge("F", new HashSet<>(Arrays.asList("G", "H")));
DefaultCallGraph.addEdge("I", new HashSet<>(Arrays.asList("J")));
}

@Test
void referencedClassMembers() {
HashSet<String> projectClasses = new HashSet<>(Arrays.asList("A"));
Set<String> referenced = DefaultCallGraph.referencedClassMembers(projectClasses);
// note that there is no path from A to J
Assertions.assertEquals(new HashSet<>(Arrays.asList("A", "B", "C", "D", "E", "F", "G", "H")), referenced);
}

@Test
void getProjectVertices() {
Set<String> projectVertices = DefaultCallGraph.getProjectVertices();
Assertions.assertEquals(new HashSet<>(Arrays.asList("A", "D", "F", "I")), projectVertices);
}

@Test
void getUsagesPerClass() {
Map<String, Set<String>> usagesPerClass = DefaultCallGraph.getUsagesPerClass();
Map<String, Set<String>> usagesExpected = new HashMap<>();
usagesExpected.put("A", new HashSet<>(Arrays.asList("B", "C", "D")));
usagesExpected.put("D", new HashSet<>(Arrays.asList("E", "F")));
usagesExpected.put("F", new HashSet<>(Arrays.asList("G", "H")));
usagesExpected.put("I", new HashSet<>(Arrays.asList("J")));
Assertions.assertEquals(usagesExpected, usagesPerClass);
}
}

0 comments on commit 139c48a

Please sign in to comment.