package temp; import static org.junit.jupiter.api.Assertions.*; import org.junit.jupiter.api.Test; import io.github.classgraph.ClassGraph; import io.github.classgraph.ClassInfo; import io.github.classgraph.ClassInfoList; import io.github.classgraph.ScanResult; class ReferencedClassTestCase { @Test void test() { String typeName = RegressionTarget.class.getName(); ScanResult sr = new ClassGraph() .verbose() .blacklistPackages("org") .enableInterClassDependencies() .whitelistClasses(typeName) .scan(); ClassInfo child = sr.getClassInfo(typeName); ClassInfoList dependentTypes = child.getClassDependencies(); System.out.println(dependentTypes); assertTrue(dependentTypes.toString().contains("Source")); } } class RegressionTarget { public static void doSomething() { Source.num = 123; Source.obj = new Source(); Source local = new Source(); local.num = 321; System.out.println(Source.num); System.out.println(local.num); } } class Source { public static int num; public static Source obj; }