Skip to content

Commit

Permalink
added more tests and comments
Browse files Browse the repository at this point in the history
  • Loading branch information
nahsra committed Aug 30, 2023
1 parent 98f41d1 commit b639cbc
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 8 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,9 @@
public interface JavaParserFactory {

/**
* Create a JavaParser instance for the given project source directories
* Create a JavaParser instance for the given project source directories. Note that we should
* still operate on the files that are not in the source directories, but we may have less symbol
* resolution for them.
*
* @param sourceDirectories the path to the project
* @return a JavaParser instance based on the given source directories
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,7 @@ final class CLITest {
void setup(final @TempDir Path tmpDir) throws IOException {
workingRepoDir = tmpDir;
Path module1JavaDir =
Files.createDirectories(tmpDir.resolve("module1/src/main/java/com/acme/"));
Files.createDirectories(tmpDir.resolve("module1/src/alternateMain/java/com/acme/"));
Path module2JavaDir =
Files.createDirectories(tmpDir.resolve("module2/src/main/java/com/acme/util/"));
fooJavaFile = module1JavaDir.resolve("Foo.java");
Expand All @@ -46,11 +46,12 @@ void setup(final @TempDir Path tmpDir) throws IOException {
fooJavaFile,
"import com.acme.util.Bar; class Foo {private var bar = new Bar();}".getBytes());
Files.write(barJavaFile, "public class Bar {}".getBytes());

/*
* Only add module2 to the discovered source directories. This will help prove that the module2 files can still be seen and changed, even if we couldn't locate it as a "source directory".
*/
sourceDirectories =
List.of(
SourceDirectory.createDefault(
tmpDir.resolve("module1/src/main/java").toAbsolutePath(),
List.of(fooJavaFile.toAbsolutePath().toString())),
SourceDirectory.createDefault(
tmpDir.resolve("module2/src/main/java").toAbsolutePath(),
List.of(barJavaFile.toAbsolutePath().toString())));
Expand Down Expand Up @@ -112,7 +113,7 @@ void dry_run_works() throws IOException {
List<CodeTFResult> dryRunCodeTFResults = dryRunCodeTFReport.getResults();

// we just compare the results because the "run" section is non-deterministic (has elapsed time
// etc)
// etc.)
String normalJson = mapper.writeValueAsString(normalCodeTFResults);
String dryRunJson = mapper.writeValueAsString(dryRunCodeTFResults);
assertThat(normalJson).isEqualTo(dryRunJson);
Expand Down Expand Up @@ -152,12 +153,12 @@ void file_finder_works() throws IOException {
FileFinder finder = new CLI.DefaultFileFinder();

IncludesExcludes all = IncludesExcludes.any();
List<Path> files = finder.findFiles(sourceDirectories, all);
List<Path> files = finder.findFiles(workingRepoDir, all);
assertThat(files).containsExactly(fooJavaFile, barJavaFile);

IncludesExcludes onlyFoo =
IncludesExcludes.withSettings(workingRepoDir.toFile(), List.of("**/Foo.java"), List.of());
files = finder.findFiles(sourceDirectories, onlyFoo);
files = finder.findFiles(workingRepoDir, onlyFoo);
assertThat(files).containsExactly(fooJavaFile);
}

Expand Down

0 comments on commit b639cbc

Please sign in to comment.