@Test
  public void shouldReturnUnparsableClassIfClassCannotBeFound() {
    JavaClass javaClass = builder.createClass("foo.bar.com");

    assertThat(javaClass).isInstanceOf(UnparsableClass.class);
    assertThat(javaClass.getName()).isEqualTo("foo.bar.com");
    assertThat(javaClass.getImports()).isEmpty();
  }
  @Test
  public void shouldReturnUnparsableClassIfErrorOccursWhileParsing() {
    ClassParser parser = mock(ClassParser.class);
    when(parser.getClass("MyClassName")).thenThrow(new RuntimeException(new NotFoundException("")));

    builder = new JavaClassBuilder(parser);

    Assert.assertThat(builder.createClass("MyClassName"), instanceOf(UnparsableClass.class));
  }
 public JavaClass findJavaClass(String classname) {
   JavaClass clazz = findClass(classname);
   if (clazz == null) {
     clazz = builder.getClass(classname);
     if (clazz.locatedInClassFile()) {
       addToIndex(clazz);
     }
   }
   return clazz;
 }
  public Set<JavaClass> findClasses(Collection<File> changedFiles) {
    // First update class index
    List<String> changedClassesNames = new ArrayList<String>();
    for (File changedFile : changedFiles) {
      String changedClassname = builder.classFileChanged(changedFile);
      if (changedClassname != null) {
        changedClassesNames.add(changedClassname);
      }
    }

    // Then find dependencies
    Set<JavaClass> changedClasses = newHashSet();
    for (String changedClassesName : changedClassesNames) {
      JavaClass javaClass = builder.getClass(changedClassesName);
      if (javaClass != null) {
        addToIndex(javaClass);
        changedClasses.add(javaClass);
      }
    }
    builder.clear();
    return changedClasses;
  }
  @Test
  public void shouldLookForClassesInTargetDirectories() throws Exception {
    newDir = new File("tempClassDir");
    List<File> buildPaths = asList(newDir);
    ClasspathProvider classpath =
        new StandaloneClasspath(
            buildPaths,
            FakeEnvironments.systemClasspath() + pathSeparator + newDir.getAbsolutePath());

    String classname = "org.fakeco.Foobar";
    createClass(classname);

    builder = new JavaClassBuilder(classpath);
    JavaClass javaClass = builder.createClass(classname);
    assertEquals(classname, javaClass.getName());
    assertFalse(javaClass.isATest());
  }
  @Test
  public void shouldFindDependenciesInSamePackage() {
    JavaClass javaClass = builder.createClass(FakeTree.class.getName());

    assertThat(javaClass.getImports()).contains(FakeDependency.class.getName());
  }