diff --git a/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java b/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java index b67dce3fe36a42291258349cd1130437505ab0d4..b5b3584782ca9e1754ffa8f1109a7cca32942a22 100644 --- a/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java +++ b/src/test/java/eu/simstadt/regionchooser/RegionChooserCommandLineInterfaceTest.java @@ -16,6 +16,7 @@ import org.junit.jupiter.api.AfterEach; // JUnit 5 import org.junit.jupiter.api.BeforeEach; // JUnit 5 import org.junit.jupiter.api.Test; +import org.junit.jupiter.api.io.TempDir; import picocli.CommandLine; @@ -28,18 +29,25 @@ private static final Path TEST_REPOSITORY = Paths.get("src/test/resources/testdata/"); + + @TempDir + Path tempDirectory; + Path outGML; + @BeforeEach - public void setUpStreams() { + public void setUp() { out.reset(); err.reset(); System.setOut(new PrintStream(out)); System.setErr(new PrintStream(err)); + outGML = tempDirectory.resolve("output.gml"); } @AfterEach - public void restoreStreams() { + public void restore() throws IOException { System.setOut(originalOut); System.setErr(originalErr); + Files.deleteIfExists(outGML); } @Test @@ -54,8 +62,7 @@ void testExtractRegionFromTwoCitygmls() throws IOException { String wktPolygon = "POLYGON((3512984.7003764412 5405148.310572891,3513038.6360455155 5405010.072163861,3513142.7277745553 5405004.02571992,3514204.1661769524 5405563.192081669,3514399.2818417274 5405720.905457244,3514291.6158155007 5405896.706492759,3512984.7003764412 5405148.310572891))"; Path citygml1 = TEST_REPOSITORY.resolve("Stuttgart.proj/Stuttgart_LOD0_LOD1_small.gml"); Path citygml2 = TEST_REPOSITORY.resolve("Stuttgart.proj/Stöckach_überarbeitete GML-NoBuildingPart.gml"); - Path outGML = Files.createTempFile("output", ".gml"); - Path inWKT = Files.createTempFile("polygon", ".wkt"); + Path inWKT = tempDirectory.resolve("polygon.wkt"); try (BufferedWriter wkt = Files.newBufferedWriter(inWKT)) { wkt.write(wktPolygon); } @@ -73,8 +80,7 @@ void testExtractRegionFromTwoCitygmlsInWGS84() throws IOException { String wktPolygon = "POLYGON((9.18991539528286 48.79067456353269, 9.195580220722313 48.7873947720947, 9.172062612079735 48.78241812742368, 9.170946813129538 48.78569824412753, 9.18991539528286 48.79067456353269))"; Path citygml1 = TEST_REPOSITORY.resolve("Stuttgart.proj/Stuttgart_LOD0_LOD1_small.gml"); Path citygml2 = TEST_REPOSITORY.resolve("Stuttgart.proj/Stöckach_überarbeitete GML-NoBuildingPart.gml"); - Path outGML = Files.createTempFile("output", ".gml"); - Path inWKT = Files.createTempFile("polygon", ".wkt"); + Path inWKT = tempDirectory.resolve("polygon.wkt"); try (BufferedWriter wkt = Files.newBufferedWriter(inWKT)) { wkt.write(wktPolygon); } @@ -96,7 +102,6 @@ private long countBuildings(Path outGML) throws IOException { void testExtractRegionWithStandardInput() throws IOException { String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))"; Path citygml = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); - Path outGML = Files.createTempFile("output", ".gml"); InputStream stdin = new ByteArrayInputStream(wktPolygon.getBytes(StandardCharsets.UTF_8)); System.setIn(stdin); assertFalse(Files.exists(outGML)); @@ -112,8 +117,7 @@ void testExtractRegionWithStandardInput() throws IOException { void testExtractRegionWithMissingInput() throws IOException { String wktPolygon = "POLYGON((-73.9959209576448 40.73286384885367, -73.996317924579 40.732359794090684, -73.9947515145143 40.7315061442504, -73.99422580154739 40.73214841515045, -73.9959209576448 40.73286384885367))"; Path citygml = TEST_REPOSITORY.resolve("NewYork.proj/ManhattanSmall.gml"); - Path outGML = Files.createTempFile("output", ".gml"); - Path inWKT = Files.createTempFile("polygon", ".wkt"); + Path inWKT = tempDirectory.resolve("polygon.wkt"); try (BufferedWriter wkt = Files.newBufferedWriter(inWKT)) { wkt.write(wktPolygon); }