### Question:
JavaccCompilerInputOutputConfiguration implements CompilerInputOutputConfiguration { @Override public FileTree getJavaSourceTree() { FileTree javaSourceTree = null; for (JavaCompile task : javaCompileTasks) { if (javaSourceTree == null) { javaSourceTree = task.getSource(); } else { javaSourceTree = javaSourceTree.plus(task.getSource()); } } return excludeOutputDirectory(javaSourceTree); } JavaccCompilerInputOutputConfiguration(File inputDirectory, File outputDirectory, FileTree source, TaskCollection<JavaCompile> javaCompileTasks); @Override File getOutputDirectory(); @Override File getInputDirectory(); @Override File getTempOutputDirectory(); @Override FileTree getSource(); @Override FileTree getCompleteSourceTree(); @Override FileTree getJavaSourceTree();  }### Answer:
@Test public void getJavaSourceTreeReturnsNullWhenNoJavaCompileTasks() throws IOException { CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, is(nullValue())); }
@Test public void getJavaSourceTreeReturnsJavaCompileSourceWhenSingleJavaCompileTask() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, contains(javaFile.getCanonicalFile())); }
@Test public void getJavaSourceTreeReturnsAggregatedJavaCompileSourceWhenMultipleJavaCompileTasks() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class); testFolder.newFolder("inputTest"); File testFile = addTaskWithSourceFile(project, "compileTest", "inputTest/AnotherTestClass.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, containsInAnyOrder(javaFile.getCanonicalFile(), testFile.getCanonicalFile())); }
@Test public void getJavaSourceTreeExcludesOutputFolder() throws IOException { Project project = ProjectBuilder.builder().withProjectDir(testFolder.getRoot()).build(); File javaFile = addTaskWithSourceFile(project, "compileJava", "input/TestClass.java", JavaCompile.class); File outputFile = addTaskWithSourceFile(project, "compileJavaccGenerated", "output/Generated.java", JavaCompile.class); CompilerInputOutputConfiguration configuration = builder .withInputDirectory(inputDirectory) .withOutputDirectory(outputDirectory) .withJavaCompileTasks(project.getTasks().withType(JavaCompile.class)) .build(); FileTree javaSourceTree = configuration.getJavaSourceTree(); assertThat(javaSourceTree, contains(javaFile.getCanonicalFile())); assertThat(javaSourceTree, not(contains(outputFile.getCanonicalFile()))); }