|
9 | 9 | import org.junit.jupiter.api.DisplayName; |
10 | 10 | import org.junit.jupiter.api.Test; |
11 | 11 | import org.junit.jupiter.api.io.TempDir; |
| 12 | +import org.junit.jupiter.params.ParameterizedTest; |
| 13 | +import org.junit.jupiter.params.provider.CsvSource; |
| 14 | +import org.junit.jupiter.params.provider.NullAndEmptySource; |
12 | 15 |
|
13 | 16 | /** |
14 | 17 | * Verifies {@link CycleRanker#generateClassReferencesGraph(boolean, String)} |
@@ -41,4 +44,46 @@ public void hello() {} |
41 | 44 | assertNotNull(dto); |
42 | 45 | assertTrue(dto.getClassReferencesGraph().containsVertex("com.example.Plain")); |
43 | 46 | } |
| 47 | + |
| 48 | + @ParameterizedTest |
| 49 | + @NullAndEmptySource |
| 50 | + @DisplayName("generateClassReferencesGraph rejects a missing source directory") |
| 51 | + void rejectsMissingSourceDirectory(String repositoryPath) { |
| 52 | + CycleRanker ranker = new CycleRanker(repositoryPath, tempDir.toString()); |
| 53 | + |
| 54 | + IllegalArgumentException exception = assertThrows( |
| 55 | + IllegalArgumentException.class, () -> ranker.generateClassReferencesGraph(false, "src/test")); |
| 56 | + |
| 57 | + assertEquals("Source directory cannot be null or empty", exception.getMessage()); |
| 58 | + assertNull(ranker.getCodebaseGraphDTO(), "A rejected request must not populate the graph DTO"); |
| 59 | + } |
| 60 | + |
| 61 | + @ParameterizedTest(name = "excludeTests={0} should include custom test source={1}") |
| 62 | + @CsvSource({"true, false", "false, true"}) |
| 63 | + @DisplayName("generateClassReferencesGraph forwards test exclusion configuration") |
| 64 | + void forwardsTestExclusionConfiguration(boolean excludeTests, boolean expectTestSource) throws IOException { |
| 65 | + writeJava(tempDir.resolve("src/main/java/com/example/ProductionClass.java"), "com.example", "ProductionClass"); |
| 66 | + writeJava(tempDir.resolve("custom-tests/com/example/FixtureClass.java"), "com.example", "FixtureClass"); |
| 67 | + |
| 68 | + CycleRanker ranker = new CycleRanker(tempDir.toString(), tempDir.toString()); |
| 69 | + CodebaseGraphDTO dto = ranker.generateClassReferencesGraph(excludeTests, "custom-tests"); |
| 70 | + |
| 71 | + assertTrue(dto.getClassReferencesGraph().containsVertex("com.example.ProductionClass")); |
| 72 | + assertEquals( |
| 73 | + expectTestSource, |
| 74 | + dto.getClassReferencesGraph().containsVertex("com.example.FixtureClass"), |
| 75 | + "The custom test source directory must follow the caller's exclusion setting"); |
| 76 | + assertSame(dto, ranker.getCodebaseGraphDTO(), "The generated DTO must remain available to cycle ranking"); |
| 77 | + } |
| 78 | + |
| 79 | + private static void writeJava(Path path, String packageName, String className) throws IOException { |
| 80 | + Files.createDirectories(path.getParent()); |
| 81 | + Files.writeString( |
| 82 | + path, |
| 83 | + """ |
| 84 | + package %s; |
| 85 | + public class %s {} |
| 86 | + """ |
| 87 | + .formatted(packageName, className)); |
| 88 | + } |
44 | 89 | } |
0 commit comments