DependencyReader { public Node readDependencies(byte[] classAsBytes) { checkNotNull(classAsBytes, "Class could not be read"); DependencyClassVisitor visitor = new DependencyClassVisitor(dependencyGraph, collapseInnerClasses); ClassReader reader = new ClassReader(classAsBytes); reader.accept(visitor, 0); return dependencyGraph.getNode(visitor.getClassName()); } DependencyReader(DependencyGraph dependencyGraph, boolean collapseInnerClasses); Node readDependencies(byte[] classAsBytes);  }
@Test public void testFindDependencies() { String className = DependencyReaderTest.class.getCanonicalName(); String fileName = TEST_CLASSES_ROOT + "/" + className.replaceAll("\\.", "/") + ".class"; byte[] bytesFromFile = FileSystemUtil.readBytesFromFile(fileName); dependencyReader.readDependencies(bytesFromFile); assertThat(dependencyGraph.hasNode(className), is(true)); assertThat(dependencyGraph.hasNode(DependencyGraphFactory.class.getName()), is(true)); Node from = dependencyGraph.getNode(className); Node to = dependencyGraph.getNode(DependencyGraphFactory.class.getName()); assertThat(dependencyGraph.getIncomingEdges(to).size(), is(1)); assertThat(dependencyGraph.hasNode("java.lang.Object"), is(false)); Dependency dependency = dependencyGraph.getEdge(from, to); assertThat(dependency, notNullValue()); assertThat(dependency.getDependencyType(), is(DependencyType.READ_WRITE)); }
@Test public void testReadWrongFile() { try { dependencyReader.readDependencies(null); fail("reading not existing file should fail"); } catch(NullPointerException e) { assertThat(e.getMessage(), is("Class could not be read")); } }