Fix SongodaYamlConfigTest leaving created backup files in tmp dir

This commit is contained in:
Christian Koop 2022-06-26 13:24:16 +02:00
parent fce5c5c6a1
commit c9a48387de
No known key found for this signature in database
GPG Key ID: 89A8181384E010A3

View File

@ -10,22 +10,32 @@ import java.io.IOException;
import java.io.StringReader; import java.io.StringReader;
import java.nio.file.Files; import java.nio.file.Files;
import java.nio.file.Path; import java.nio.file.Path;
import java.util.Comparator;
import java.util.stream.Stream;
import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse; import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertNull;
class SongodaYamlConfigTest { class SongodaYamlConfigTest {
Path tmpDir;
Path cfg; Path cfg;
@BeforeEach @BeforeEach
void setUp() throws IOException { void setUp() throws IOException {
this.cfg = createTmpFile(); this.tmpDir = Files.createTempDirectory("SongodaYamlConfigTest");
this.cfg = Files.createTempFile(this.tmpDir, "config", ".yml");
this.tmpDir.toFile().deleteOnExit();
} }
@AfterEach @AfterEach
void tearDown() throws IOException { void tearDown() throws IOException {
Files.deleteIfExists(this.cfg); try (Stream<Path> stream = Files.walk(this.tmpDir)) {
stream
.sorted(Comparator.reverseOrder())
.map(Path::toFile).forEach(File::delete);
}
} }
@Test @Test
@ -115,7 +125,7 @@ class SongodaYamlConfigTest {
} }
@Test @Test
void testDefaultValueAppliedAfterLoadNullValue() throws IOException { void testDefaultValueAppliedAfterLoadNullValue() {
SongodaYamlConfig cfg = new SongodaYamlConfig(this.cfg.toFile()); SongodaYamlConfig cfg = new SongodaYamlConfig(this.cfg.toFile());
ConfigEntry entry = new ConfigEntry(cfg, "key", "value"); ConfigEntry entry = new ConfigEntry(cfg, "key", "value");
@ -123,12 +133,4 @@ class SongodaYamlConfigTest {
assertEquals("value", entry.get()); assertEquals("value", entry.get());
} }
private Path createTmpFile() throws IOException {
Path path = Files.createTempFile("SongodaYamlConfigTest", "yml");
File file = path.toFile();
file.deleteOnExit();
return path;
}
} }