From 987571937c8e7b1efeb3ce828fa027d62b0079c2 Mon Sep 17 00:00:00 2001 From: Craig Schardt Date: Sun, 17 Dec 2023 11:55:55 -0600 Subject: [PATCH] use proper tempfiles --- .../common/configuration/ConfigTest.java | 20 +++++++++++-------- 1 file changed, 12 insertions(+), 8 deletions(-) diff --git a/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java b/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java index ec32055385..919c1376b6 100644 --- a/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java +++ b/photon-core/src/test/java/org/photonvision/common/configuration/ConfigTest.java @@ -133,27 +133,31 @@ public static void cleanup() throws IOException { public void testJacksonHandlesOldVersions() throws IOException { var str = "{\"baseName\":\"aaaaaa\",\"uniqueName\":\"aaaaaa\",\"nickname\":\"aaaaaa\",\"FOV\":70.0,\"path\":\"dev/vid\",\"cameraType\":\"UsbCamera\",\"currentPipelineIndex\":0,\"camPitch\":{\"radians\":0.0},\"calibrations\":[], \"cameraLEDs\":[]}"; - var writer = new FileWriter("test.json"); + File tempFile = File.createTempFile("test", ".json"); + tempFile.deleteOnExit(); + var writer = new FileWriter(tempFile); writer.write(str); writer.flush(); writer.close(); Assertions.assertDoesNotThrow( - () -> JacksonUtils.deserialize(Path.of("test.json"), CameraConfiguration.class)); + () -> JacksonUtils.deserialize(tempFile.toPath(), CameraConfiguration.class)); - new File("test.json").delete(); + tempFile.delete(); } @Test public void testJacksonHandlesOldTargetEnum() throws IOException { - var str = - "[ \"AprilTagPipelineSettings\", {\n" + " \"targetModel\" : \"k6in_16h5\"\n" + "} ]\n"; - var writer = new FileWriter("test.json"); + var str = "[ \"AprilTagPipelineSettings\", {\n \"targetModel\" : \"k6in_16h5\"\n} ]\n"; + + File tempFile = File.createTempFile("test", ".json"); + tempFile.deleteOnExit(); + var writer = new FileWriter(tempFile); writer.write(str); writer.flush(); writer.close(); Assertions.assertDoesNotThrow( - () -> JacksonUtils.deserialize(Path.of("test.json"), CVPipelineSettings.class)); + () -> JacksonUtils.deserialize(tempFile.toPath(), CVPipelineSettings.class)); - new File("test.json").delete(); + tempFile.delete(); } }