♻️ Replace Guava’s Files.write() with NIO’s Files.write()
authorDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Mon, 6 Oct 2025 17:37:39 +0000 (19:37 +0200)
committerDavid ‘Bombe’ Roden <bombe@pterodactylus.net>
Wed, 8 Oct 2025 13:08:10 +0000 (15:08 +0200)
src/test/java/net/pterodactylus/rhynodge/states/StateManagerTest.java

index efdcb33..cd235eb 100644 (file)
@@ -2,13 +2,13 @@ package net.pterodactylus.rhynodge.states;
 
 import java.io.File;
 import java.io.IOException;
+import java.nio.file.Files;
 import java.util.Optional;
 
 import net.pterodactylus.rhynodge.State;
 import net.pterodactylus.rhynodge.states.StateManager.StateDirectory;
 
 import com.fasterxml.jackson.annotation.JsonProperty;
-import com.google.common.io.Files;
 import org.hamcrest.Matchers;
 import org.jspecify.annotations.NonNull;
 import org.junit.jupiter.api.BeforeAll;
@@ -16,7 +16,7 @@ import org.junit.jupiter.api.BeforeEach;
 import org.junit.jupiter.api.Test;
 import org.junit.jupiter.api.io.TempDir;
 
-import static com.google.common.base.Charsets.UTF_8;
+import static java.util.Arrays.asList;
 import static org.apache.log4j.Level.OFF;
 import static org.apache.log4j.Logger.getLogger;
 import static org.hamcrest.MatcherAssert.assertThat;
@@ -64,14 +64,14 @@ public class StateManagerTest {
 
        @Test
        public void invalidJsonFileCanNotBeLoaded() throws IOException {
-               Files.write("not json", new File(tempFolder, "test.last.json"), UTF_8);
+               Files.write(tempFolder.toPath().resolve("test.last.json"), asList("not json"));
                Optional<State> restoredState = stateManager.loadLastState("test");
                assertThat(restoredState.isPresent(), is(false));
        }
 
        @Test
        public void jsonWithInvalidFieldsCanNotBeLoaded() throws IOException {
-               Files.write("{\"not\":\"json\"}", new File(tempFolder, "test.last.json"), UTF_8);
+               Files.write(tempFolder.toPath().resolve("test.last.json"), asList("{\"not\":\"json\"}"));
                Optional<State> restoredState = stateManager.loadLastState("test");
                assertThat(restoredState.isPresent(), is(false));
        }