|
28 | 28 | import java.io.IOException; |
29 | 29 | import java.nio.file.Files; |
30 | 30 | import java.nio.file.Path; |
| 31 | +import java.nio.file.attribute.FileTime; |
31 | 32 | import java.util.List; |
32 | 33 |
|
33 | 34 | import static org.junit.jupiter.api.Assertions.*; |
@@ -117,6 +118,30 @@ public void subclassNotOverwrittenWhenMakePairsIsTrue() throws IOException { |
117 | 118 | assertTrue(skipped >= 1, "At least one file (the existing subclass) should have been skipped"); |
118 | 119 | } |
119 | 120 |
|
| 121 | + @Test |
| 122 | + public void regeneratesAfterDataMapChange() throws IOException { |
| 123 | + // First run — generates files |
| 124 | + CgenRunResult first = tool.run(projectFile.toString(), "PersonMap"); |
| 125 | + assertEquals("generated", first.status()); |
| 126 | + |
| 127 | + // Bump the DataMap's mtime to be clearly newer than the generated files. |
| 128 | + // Use setLastModifiedTime rather than a wall-clock sleep to avoid |
| 129 | + // filesystem mtime granularity issues (Windows has 1-second resolution). |
| 130 | + long maxGeneratedMtime = first.files().stream() |
| 131 | + .mapToLong(e -> Path.of(e.path()).toFile().lastModified()) |
| 132 | + .max() |
| 133 | + .orElseThrow(); |
| 134 | + Path dataMapFile = tempDir.resolve("PersonMap.map.xml"); |
| 135 | + Files.setLastModifiedTime(dataMapFile, FileTime.fromMillis(maxGeneratedMtime + 5_000L)); |
| 136 | + |
| 137 | + // Second run — must detect that the DataMap is newer than the generated files |
| 138 | + // and regenerate the superclass(es). |
| 139 | + CgenRunResult second = tool.run(projectFile.toString(), "PersonMap"); |
| 140 | + assertEquals("generated", second.status(), |
| 141 | + "Expected regeneration after DataMap mtime was bumped past generated files"); |
| 142 | + assertTrue(second.summary().filesWritten() > 0); |
| 143 | + } |
| 144 | + |
120 | 145 | private Path writeFixture(String mapName, String pkg, Path destDir, boolean makePairs) throws IOException { |
121 | 146 |
|
122 | 147 | // Project descriptor |
|
0 commit comments