diff --git a/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java b/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java index c5060cfa..5a3c3767 100644 --- a/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java +++ b/data/src/test/java/io/github/adamw7/tools/data/source/file/AbstractFileSourceTest.java @@ -59,15 +59,19 @@ public void csvSourceFailsWhenTheReadBreaksMidFile() { @Test public void csvSourceNamesTheFileItFailedToRead(@TempDir Path directory) throws IOException { Path file = truncatedGzip(directory); - CSVDataSource source = new CSVDataSource(file.toString(), ",", 1, AllowedPaths.under(directory)); - source.open(); - - UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> readAll(source)); - - // A GZip member cut short ends with an unexpected EOF rather than a clean end of - // data; the message must name the file so the failure can be traced to it. - assertInstanceOf(EOFException.class, thrown.getCause()); - assertTrue(thrown.getMessage().contains(file.toString()), thrown.getMessage()); + // Closed even though the read failed: the failure leaves the descriptor open, and + // Windows refuses to delete a file some handle still holds, so an unclosed source + // fails @TempDir's cleanup rather than the assertions below. + try (CSVDataSource source = new CSVDataSource(file.toString(), ",", 1, AllowedPaths.under(directory))) { + source.open(); + + UncheckedIOException thrown = assertThrows(UncheckedIOException.class, () -> readAll(source)); + + // A GZip member cut short ends with an unexpected EOF rather than a clean end of + // data; the message must name the file so the failure can be traced to it. + assertInstanceOf(EOFException.class, thrown.getCause()); + assertTrue(thrown.getMessage().contains(file.toString()), thrown.getMessage()); + } } @Test diff --git a/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java b/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java index 4299b68c..5d469d32 100644 --- a/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java +++ b/data/src/test/java/io/github/adamw7/tools/data/source/file/AllowedPathsTest.java @@ -71,7 +71,11 @@ public void acceptsFileNameStartingWithTwoDots(@TempDir Path baseDir) throws IOE String validated = AllowedPaths.under(baseDir).validate(dotted.toString()); - assertEquals(dotted.toRealPath().toString(), validated); + // Compared against the canonicalisation validate() documents -- absolute and + // normalised -- rather than the real path: on Windows the temporary directory is + // handed over in its short 8.3 form (RUNNER~1), which toRealPath() spells out and + // validate() leaves exactly as it was given. + assertEquals(dotted.toAbsolutePath().normalize().toString(), validated); } @Test