From: David Roden Date: Sat, 25 Jan 2025 17:19:15 +0000 (+0100) Subject: ♻️ Use actual JSON matchers for Server test X-Git-Url: https://git.pterodactylus.net/?a=commitdiff_plain;h=cdb4f923f43bf2ed70f0532efe34a63d960b90f5;p=msta.git ♻️ Use actual JSON matchers for Server test --- diff --git a/pom.xml b/pom.xml index 2d20018..4508734 100644 --- a/pom.xml +++ b/pom.xml @@ -46,6 +46,12 @@ jackson-databind 2.18.1 + + com.spotify + hamcrest-jackson + 1.3.2 + test + diff --git a/server/pom.xml b/server/pom.xml index 00b8bb4..eb13148 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -19,6 +19,10 @@ com.fasterxml.jackson.core jackson-databind + + com.spotify + hamcrest-jackson + diff --git a/server/src/test/java/de/qsheltier/msta/ServerTest.java b/server/src/test/java/de/qsheltier/msta/ServerTest.java index c724a8d..aa7606b 100644 --- a/server/src/test/java/de/qsheltier/msta/ServerTest.java +++ b/server/src/test/java/de/qsheltier/msta/ServerTest.java @@ -14,6 +14,9 @@ import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Timeout; import org.junit.jupiter.api.function.ThrowingConsumer; +import static com.spotify.hamcrest.jackson.JsonMatchers.isJsonStringMatching; +import static com.spotify.hamcrest.jackson.JsonMatchers.jsonObject; +import static com.spotify.hamcrest.jackson.JsonMatchers.jsonText; import static java.nio.charset.StandardCharsets.UTF_8; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.equalTo; @@ -37,7 +40,7 @@ public class ServerTest { try (var connection = new Socket("localhost", server.getPort()); var reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { var line = reader.readLine(); - assertThat(line, equalTo("{\"event\":\"connected\"}")); + assertThat(line, isJsonStringMatching(jsonObject().where("event", jsonText("connected")))); } } } @@ -81,7 +84,7 @@ public class ServerTest { try { connectToServerAndWaitForEvent(reader -> { var line = reader.readLine(); - assertThat(line, equalTo("{\"event\":\"new-window\"}")); + assertThat(line, isJsonStringMatching(jsonObject().where("event", jsonText("new-window")))); }); } finally { window.setVisible(false); @@ -96,7 +99,7 @@ public class ServerTest { try { connectToServerAndWaitForEvent(reader -> { var line = reader.readLine(); - assertThat(line, equalTo("{\"event\":\"new-frame\"}")); + assertThat(line, isJsonStringMatching(jsonObject().where("event", jsonText("new-frame")))); }); } finally { frame.setVisible(false); @@ -127,12 +130,12 @@ public class ServerTest { try (var connection = new Socket("localhost", server.getPort()); var reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { var line = reader.readLine(); - assertThat(line, equalTo("{\"event\":\"connected\"}")); + assertThat(line, isJsonStringMatching(jsonObject().where("event", jsonText("connected")))); } try (var connection = new Socket("localhost", server.getPort()); var reader = new BufferedReader(new InputStreamReader(connection.getInputStream()))) { var line = reader.readLine(); - assertThat(line, equalTo("{\"event\":\"connected\"}")); + assertThat(line, isJsonStringMatching(jsonObject().where("event", jsonText("connected")))); } } }