### Question:
FromFiles implements Codebase { @Override public Stream<Type> types() { return this.sources.stream() .map(this::parse) .flatMap(Optional::stream) .map(file -> file.findAll(TypeDeclaration.class)) .flatMap(types -> types.stream().map(Type.TypeFromJavaparser::new)); } FromFiles(final @NonNull Collection<File> sources);  FromFiles(final Directory directory); @Override Stream<Type> types();  }### Answer:
@Test public void codebaseOfNoSourcesHasNoTypes() { Assertions.assertThat( new FromFiles( new ListOf<>() ).types() ).isEmpty(); }
@Test public void codebaseCanBeConstructedFromDirectory() { Assertions.assertThat( new FromFiles( ListOf<File>::new ).types() ).isEmpty(); }
@Test public void codebaseOfTextFileHasNoTypes() throws IOException { Assertions.assertThat( new FromFiles( new ListOf<>( new FakeFile(this.tmp.newFile("TextFile.txt")) .withContent("Just a simple text file.") ) ).types() ).isEmpty(); }
@Test public void codebaseOfJavaFileHasAType() throws IOException { Assertions.assertThat( new FromFiles( new ListOf<>( new FakeFile(this.tmp.newFile("Simple.java")) .withContent("class Simple { }") ) ).types() ) .hasSize(1) .allMatch( new HasDefinition( new Definition( "Simple", "Description not found" ) ) ); }
@Test public void codebaseOfAnnotatedJavaFileHasTypeWithAnnotation() throws IOException { Assertions.assertThat( new FromFiles( new ListOf<>( new FakeFile(this.tmp.newFile("Annotated.java")) .withContent("@Term class Annotated { }") ) ).types() ) .hasSize(1) .allMatch( new HasDefinition( new Definition( "Annotated", "Description not found" ) ) ); }
@Test @SuppressWarnings("PMD.AvoidDuplicateLiterals") public void codebaseOfJavaFileWithJavadocHasTypeWithJavadoc() throws IOException { Assertions.assertThat( new FromFiles( new ListOf<>( new FakeFile(this.tmp.newFile("Javadoc.java")) .withContent("" + "class Javadoc { }" ) ) ).types() ) .hasSize(1) .allMatch( new HasDefinition( new Definition( "Javadoc", "Documentation" ) ) ); }
@Test public void codebaseCanContainManyTypes() throws IOException { Assertions.assertThat( new FromFiles( new ListOf<>( new FakeFile(this.tmp.newFile("Simple.java")) .withContent("class Simple { }"), new FakeFile(this.tmp.newFile("Annotated.java")) .withContent("@Term class Annotated { }"), new FakeFile(this.tmp.newFile("Javadoc.java")) .withContent("" + "class Javadoc { }" ) ) ).types() ).hasSize(3); }
@Test public void codebaseAlsoSeesOtherTypeDeclarationsAsClassfiers() throws IOException { Assertions.assertThat( new FromFiles( new ListOf<>( new FakeFile(this.tmp.newFile("SomeClass.java")) .withContent("class SomeClass { }"), new FakeFile(this.tmp.newFile("SomeInterface.java")) .withContent("interface SomeInterface { }"), new FakeFile(this.tmp.newFile("SomeEnum")) .withContent("enum SomeEnum { }"), new FakeFile(this.tmp.newFile("SomeAnnotation.java")) .withContent("@interface SomeAnnotation { }") ) ).types() ).hasSize(4); }