private static Map<String, Set<String>> createStaticFields( String targetClassName) { GetStaticGraph getStaticGraph = GetStaticGraphGenerator .generate(targetClassName); return getStaticGraph.getStaticFields(); }
@Test public void testFoo() { String targetClassName = Foo.class.getCanonicalName(); GetStaticGraph graph = GetStaticGraphGenerator .generate(targetClassName); Set<String> expectedClasses = new HashSet<String>(Arrays.asList( Foo.class.getCanonicalName(), Bar1.class.getCanonicalName(), Bar2.class.getCanonicalName(), Bar3.class.getCanonicalName(), Bar4.class.getCanonicalName(), Bar5.class.getCanonicalName(), Bar6.class.getCanonicalName(), Bar7.class.getCanonicalName(), BarBar1.class.getCanonicalName())); Set<String> allClasses = new HashSet<String>(); allClasses.addAll(graph.getSourceClasses()); allClasses.addAll(graph.getTargetClasses()); assertEquals(expectedClasses, allClasses); Map<String, Set<String>> expectedStaticFields = new HashMap<String, Set<String>>(); expectedStaticFields.put(Bar2.class.getCanonicalName(), new HashSet<String>(Arrays.asList("fieldBar2"))); expectedStaticFields.put(Bar6.class.getCanonicalName(), new HashSet<String>(Arrays.asList("fieldBar6"))); expectedStaticFields.put(Bar7.class.getCanonicalName(), new HashSet<String>(Arrays.asList("fieldBar7"))); Map<String, Set<String>> staticFields = graph.getStaticFields(); assertEquals(expectedStaticFields, staticFields); }
@Test public void testCycle() { String targetClassName = Cycle1.class.getCanonicalName(); GetStaticGraph graph = GetStaticGraphGenerator .generate(targetClassName); Set<String> expectedSourceClasses = new HashSet<String>(Arrays.asList( Cycle1.class.getCanonicalName(), Cycle2.class.getCanonicalName())); assertEquals(expectedSourceClasses, graph.getSourceClasses()); Set<String> expectedTargetClasses = expectedSourceClasses; assertEquals(expectedTargetClasses, graph.getTargetClasses()); Map<String, Set<String>> staticFields = graph.getStaticFields(); assertTrue(staticFields.isEmpty()); } }
Map<String, Set<String>> staticFields = getStaticGraph.getStaticFields(); for (String className : staticFields.keySet()) { logger.info("Adding static fields to cluster for class " + className);