From 0926df1945b4259666f6bfe3028596dc350fb888 Mon Sep 17 00:00:00 2001 From: lieght <49651652+BAFGdeJong@users.noreply.github.com> Date: Sat, 20 Sep 2025 23:04:40 +0200 Subject: [PATCH] Reformatted tests --- src/test/java/org/toop/LoggingTest.java | 20 +++++++----- .../java/org/toop/backend/TcpServerTest.java | 31 +++++++++---------- .../org/toop/eventbus/GlobalEventBusTest.java | 29 +++++++++-------- .../org/toop/frontend/math/BoundsTest.java | 24 +++++++------- .../org/toop/game/tictactoe/GameBaseTest.java | 2 +- 5 files changed, 55 insertions(+), 51 deletions(-) diff --git a/src/test/java/org/toop/LoggingTest.java b/src/test/java/org/toop/LoggingTest.java index dda0202..b979802 100644 --- a/src/test/java/org/toop/LoggingTest.java +++ b/src/test/java/org/toop/LoggingTest.java @@ -53,7 +53,8 @@ public class LoggingTest { void testDisableLogsForClass_addsLoggerWithOff() { Logging.disableLogsForClass(LoggingTest.class); - LoggerConfig loggerConfig = ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); + LoggerConfig loggerConfig = + ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); assertNotNull(loggerConfig); assertEquals(Level.OFF, loggerConfig.getLevel()); } @@ -62,7 +63,8 @@ public class LoggingTest { void testEnableLogsForClass_addsLoggerWithLevel() { Logging.enableLogsForClass(LoggingTest.class, Level.ERROR); - LoggerConfig loggerConfig = ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); + LoggerConfig loggerConfig = + ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); assertNotNull(loggerConfig); assertEquals(Level.ERROR, loggerConfig.getLevel()); } @@ -71,7 +73,8 @@ public class LoggingTest { void testEnableLogsForClass_withStringLevel() { Logging.enableLogsForClass(LoggingTest.class.getName(), "INFO"); - LoggerConfig loggerConfig = ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); + LoggerConfig loggerConfig = + ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); assertNotNull(loggerConfig); assertEquals(Level.INFO, loggerConfig.getLevel()); } @@ -80,7 +83,8 @@ public class LoggingTest { void testEnableDebugLogsForClass_setsDebug() { Logging.enableDebugLogsForClass(LoggingTest.class); - LoggerConfig loggerConfig = ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); + LoggerConfig loggerConfig = + ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); assertNotNull(loggerConfig); assertEquals(Level.DEBUG, loggerConfig.getLevel()); } @@ -89,7 +93,8 @@ public class LoggingTest { void testEnableInfoLogsForClass_setsInfo() { Logging.enableInfoLogsForClass(LoggingTest.class); - LoggerConfig loggerConfig = ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); + LoggerConfig loggerConfig = + ctx.getConfiguration().getLoggers().get(LoggingTest.class.getName()); assertNotNull(loggerConfig); assertEquals(Level.INFO, loggerConfig.getLevel()); } @@ -98,7 +103,8 @@ public class LoggingTest { void testDisableLogsForNonexistentClass_doesNothing() { Logging.disableLogsForClass("org.toop.DoesNotExist"); - LoggerConfig loggerConfig = ctx.getConfiguration().getLoggers().get("org.toop.DoesNotExist"); + LoggerConfig loggerConfig = + ctx.getConfiguration().getLoggers().get("org.toop.DoesNotExist"); assertNull(loggerConfig); // class doesn't exist, so no logger added } -} \ No newline at end of file +} diff --git a/src/test/java/org/toop/backend/TcpServerTest.java b/src/test/java/org/toop/backend/TcpServerTest.java index b016879..65696a6 100644 --- a/src/test/java/org/toop/backend/TcpServerTest.java +++ b/src/test/java/org/toop/backend/TcpServerTest.java @@ -1,13 +1,11 @@ package org.toop.backend; -import org.junit.jupiter.api.*; -import org.toop.backend.tictactoe.ParsedCommand; +import static org.junit.jupiter.api.Assertions.*; import java.io.*; import java.net.Socket; import java.util.concurrent.TimeUnit; - -import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.*; class TcpServerTest { @@ -39,7 +37,8 @@ class TcpServerTest { server.stop(); try { serverThread.join(1000); - } catch (InterruptedException ignored) {} + } catch (InterruptedException ignored) { + } } @Test @@ -78,16 +77,16 @@ class TcpServerTest { client.close(); } -// @Test -// void testGetNewestCommand() throws InterruptedException { -// String command = "move 1 2"; -// server.receivedQueue.put(command); -// -// ParsedCommand parsed = server.getNewestCommand(); -// System.out.println(parsed); -// assertNotNull(parsed); -// assertEquals(command, parsed.returnMessage); TODO: Test later -// } + // @Test + // void testGetNewestCommand() throws InterruptedException { + // String command = "move 1 2"; + // server.receivedQueue.put(command); + // + // ParsedCommand parsed = server.getNewestCommand(); + // System.out.println(parsed); + // assertNotNull(parsed); + // assertEquals(command, parsed.returnMessage); TODO: Test later + // } @Test void testMultipleClients() throws IOException, InterruptedException { @@ -106,4 +105,4 @@ class TcpServerTest { client1.close(); client2.close(); } -} \ No newline at end of file +} diff --git a/src/test/java/org/toop/eventbus/GlobalEventBusTest.java b/src/test/java/org/toop/eventbus/GlobalEventBusTest.java index 2db3ded..9208453 100644 --- a/src/test/java/org/toop/eventbus/GlobalEventBusTest.java +++ b/src/test/java/org/toop/eventbus/GlobalEventBusTest.java @@ -3,9 +3,8 @@ package org.toop.eventbus; import static org.junit.jupiter.api.Assertions.*; import com.google.common.eventbus.EventBus; -import org.junit.jupiter.api.*; - import java.util.concurrent.atomic.AtomicBoolean; +import org.junit.jupiter.api.*; class GlobalEventBusTest { @@ -70,16 +69,16 @@ class GlobalEventBusTest { assertFalse(called.get(), "Consumer should not be called after unregister"); } -// @Test -// void testPost_storesEventInRegistry() { -// // Simple EventMeta check -// class MyEvent {} -// -// MyEvent event = new MyEvent(); -// GlobalEventBus.post(event); -// -// EventMeta stored = EventRegistry.getStoredEvent(MyEvent.class); -// assertNotNull(stored, "EventMeta should be stored"); -// assertEquals(event, stored.event(), "Stored event should match the posted one"); -// } -} \ No newline at end of file + // @Test + // void testPost_storesEventInRegistry() { + // // Simple EventMeta check + // class MyEvent {} + // + // MyEvent event = new MyEvent(); + // GlobalEventBus.post(event); + // + // EventMeta stored = EventRegistry.getStoredEvent(MyEvent.class); + // assertNotNull(stored, "EventMeta should be stored"); + // assertEquals(event, stored.event(), "Stored event should match the posted one"); + // } +} diff --git a/src/test/java/org/toop/frontend/math/BoundsTest.java b/src/test/java/org/toop/frontend/math/BoundsTest.java index c58fa5f..d8bfd98 100644 --- a/src/test/java/org/toop/frontend/math/BoundsTest.java +++ b/src/test/java/org/toop/frontend/math/BoundsTest.java @@ -35,26 +35,26 @@ class BoundsTest { @Test void testCheckInsideBounds() { // Points inside the bounds - assertTrue(bounds.check(10, 20)); // top-left corner - assertTrue(bounds.check(110, 70)); // bottom-right corner - assertTrue(bounds.check(60, 45)); // inside + assertTrue(bounds.check(10, 20)); // top-left corner + assertTrue(bounds.check(110, 70)); // bottom-right corner + assertTrue(bounds.check(60, 45)); // inside } @Test void testCheckOutsideBounds() { // Points outside the bounds - assertFalse(bounds.check(9, 20)); // left - assertFalse(bounds.check(10, 19)); // above - assertFalse(bounds.check(111, 70)); // right - assertFalse(bounds.check(110, 71)); // below + assertFalse(bounds.check(9, 20)); // left + assertFalse(bounds.check(10, 19)); // above + assertFalse(bounds.check(111, 70)); // right + assertFalse(bounds.check(110, 71)); // below } @Test void testCheckOnEdgeBounds() { // Points on the edges should be considered inside - assertTrue(bounds.check(10, 20)); // top-left - assertTrue(bounds.check(110, 20)); // top-right - assertTrue(bounds.check(10, 70)); // bottom-left - assertTrue(bounds.check(110, 70)); // bottom-right + assertTrue(bounds.check(10, 20)); // top-left + assertTrue(bounds.check(110, 20)); // top-right + assertTrue(bounds.check(10, 70)); // bottom-left + assertTrue(bounds.check(110, 70)); // bottom-right } -} \ No newline at end of file +} diff --git a/src/test/java/org/toop/game/tictactoe/GameBaseTest.java b/src/test/java/org/toop/game/tictactoe/GameBaseTest.java index 4b70e8d..dd56230 100644 --- a/src/test/java/org/toop/game/tictactoe/GameBaseTest.java +++ b/src/test/java/org/toop/game/tictactoe/GameBaseTest.java @@ -79,4 +79,4 @@ class GameBaseTest { assertEquals(GameBase.State.INVALID, game.play(-1)); assertEquals(GameBase.State.INVALID, game.play(9)); } -} \ No newline at end of file +}