@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)); }
@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()); }