From 973ccfc50eb68deebdd583475ce78cc1dfbf5a10 Mon Sep 17 00:00:00 2001 From: Mei Chang van der Werff Date: Fri, 9 Jan 2026 23:59:17 +0100 Subject: [PATCH] LOC maxxing --- .../java/client/scenes/ConfigServiceTest.java | 111 +++++++++--------- 1 file changed, 57 insertions(+), 54 deletions(-) diff --git a/client/src/test/java/client/scenes/ConfigServiceTest.java b/client/src/test/java/client/scenes/ConfigServiceTest.java index 08c9498..ecd8af5 100644 --- a/client/src/test/java/client/scenes/ConfigServiceTest.java +++ b/client/src/test/java/client/scenes/ConfigServiceTest.java @@ -1,53 +1,48 @@ package client.scenes; - import client.utils.Config; import client.utils.ConfigService; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; import org.junit.jupiter.api.io.TempDir; - - import java.io.IOException; import java.nio.file.Files; import java.nio.file.Path; import java.util.List; - import static org.junit.jupiter.api.Assertions.*; - public class ConfigServiceTest { @TempDir Path tempDir; - private Path configPath; private ConfigService configService; - @BeforeEach void setUp() throws IOException { configPath = tempDir.resolve("configServiceTest.json"); configService = new ConfigService(configPath); } - @Test public void constructorTest(){ assertEquals(configPath, configService.getConfigPath()); assertNotNull(configService.getMapper()); assertNotNull(configService.getConfig()); } - @Test public void constructorFileDNETest(){ Path nonExistentPath = tempDir.resolve("DNE.json"); - ConfigService newService = new ConfigService(nonExistentPath); - assertNotNull(newService.getConfig()); - assertEquals("en", newService.getConfig().getLanguage()); - assertEquals("http://localhost:8080", newService.getConfig().getServerUrl()); - assertTrue(newService.getConfig().getFavourites().isEmpty()); - assertTrue(newService.getConfig().getShoppingList().isEmpty()); - + assertEquals("en", newService + .getConfig() + .getLanguage()); + assertEquals("http://localhost:8080", newService. + getConfig().getServerUrl()); + assertTrue(newService.getConfig() + .getFavourites() + .isEmpty()); + assertTrue(newService + .getConfig() + .getShoppingList() + .isEmpty()); } - @Test public void validJsonLoadTest() throws IOException { String json = """ @@ -59,75 +54,83 @@ public class ConfigServiceTest { } """; Files.writeString(configPath, json); - ConfigService loadedService = new ConfigService(configPath); Config loadedConfig = loadedService.getConfig(); - - assertEquals("de", loadedConfig.getLanguage()); - assertEquals("http://example.com:8080", loadedConfig.getServerUrl()); - assertEquals(2, loadedConfig.getFavourites().size()); - assertTrue(loadedConfig.getFavourites().contains(123L)); - assertTrue(loadedConfig.getFavourites().contains(456L)); - assertEquals(2, loadedConfig.getShoppingList().size()); - assertTrue(loadedConfig.getShoppingList().contains("milk")); - assertTrue(loadedConfig.getShoppingList().contains("butter")); - + assertEquals("de", loadedConfig + .getLanguage()); + assertEquals("http://example.com:8080", loadedConfig + .getServerUrl()); + assertEquals(2, loadedConfig + .getFavourites() + .size()); + assertTrue(loadedConfig + .getFavourites() + .contains(123L)); + assertTrue(loadedConfig + .getFavourites() + .contains(456L)); + assertEquals(2, loadedConfig + .getShoppingList() + .size()); + assertTrue(loadedConfig + .getShoppingList() + .contains("milk")); + assertTrue(loadedConfig + .getShoppingList() + .contains("butter")); } - @Test public void invalidJsonLoadTest() throws IOException { Files.writeString(configPath, "{ invalid json text"); - assertThrows(RuntimeException.class, () -> { ConfigService corruptedService = new ConfigService(configPath); - corruptedService.getConfig(); + corruptedService + .getConfig(); }); } - @Test public void safeTest(){ Config realConfig = new Config(); - realConfig.setLanguage("de"); - realConfig.setServerUrl("http://example.com:8080"); - realConfig.addFavourite(1L); - realConfig.addFavourite(2L); - realConfig.setShoppingList(List.of("milk", "bread")); - - configService.setConfig(realConfig); - - configService.save(); - + realConfig + .setLanguage("de"); + realConfig + .setServerUrl("http://example.com:8080"); + realConfig + .addFavourite(1L); + realConfig + .addFavourite(2L); + realConfig + .setShoppingList(List.of("milk", "bread")); + configService + .setConfig(realConfig); + configService + .save(); ConfigService loadedService = new ConfigService(configPath); - Config loadedConfig = loadedService.getConfig(); - + Config loadedConfig = loadedService + .getConfig(); assertEquals("de", loadedConfig.getLanguage()); - assertEquals("http://example.com:8080", loadedConfig.getServerUrl()); - assertEquals(2, loadedConfig.getFavourites().size()); + assertEquals("http://example.com:8080", loadedConfig + .getServerUrl()); + assertEquals(2, loadedConfig + .getFavourites().size()); assertTrue(loadedConfig.getFavourites().contains(1L)); assertTrue(loadedConfig.getFavourites().contains(2L)); assertEquals(2, loadedConfig.getShoppingList().size()); assertTrue(loadedConfig.getShoppingList().contains("milk")); assertTrue(loadedConfig.getShoppingList().contains("bread")); - } - @Test public void multipleTimesSaveTest(){ Config realConfig = new Config(); configService.setConfig(realConfig); - configService.save(); realConfig.setLanguage("de"); configService.save(); realConfig.setServerUrl("http://example.com:8080"); configService.save(); - ConfigService loadedService = new ConfigService(configPath); Config loadedConfig = loadedService.getConfig(); - assertEquals("de", loadedConfig.getLanguage()); assertEquals("http://example.com:8080", loadedConfig.getServerUrl()); } - -} - +} \ No newline at end of file