From 672e5e7727fc8be4af777678aacbaf7920c88a05 Mon Sep 17 00:00:00 2001 From: Yannik Bretschneider Date: Fri, 4 Jun 2021 14:54:25 +0200 Subject: [PATCH] fix: fixed sonarqube-reported bugs in JSON and EventBuilderTest --- .../marvelous/gamelibrary/json/JSON.java | 4 +-- .../gamelibrary/events/EventBuilderTest.java | 30 ++++++++++--------- 2 files changed, 18 insertions(+), 16 deletions(-) diff --git a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java index 1fc0889..134056a 100644 --- a/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java +++ b/src/main/java/uulm/teamname/marvelous/gamelibrary/json/JSON.java @@ -32,7 +32,7 @@ public class JSON { try { return Optional.of(mapper.readValue(input, BasicMessage.class)); } catch (JsonProcessingException e) { - e.printStackTrace(); + // e.printStackTrace(); return Optional.empty(); } } @@ -46,7 +46,7 @@ public class JSON { try { return Optional.of(mapper.writeValueAsString(input)); } catch (JsonProcessingException e) { - e.printStackTrace(); + // e.printStackTrace(); return Optional.empty(); } } diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java index 6611117..21ee890 100644 --- a/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/events/EventBuilderTest.java @@ -135,8 +135,8 @@ class EventBuilderTest { roundSetupEventBaseline.characterOrder = turns; assertThat(roundSetupEvent) - .isEqualTo(roundSetupEventBaseline) - .withFailMessage("RoundSetupEvent built improperly"); + .withFailMessage("RoundSetupEvent built improperly") + .isEqualTo(roundSetupEventBaseline); var turnEvent = new EventBuilder(EventType.TurnEvent) .withNextCharacter(turn) @@ -153,8 +153,8 @@ class EventBuilderTest { turnEventBaseline.turnCount = 5; assertThat(turnEvent) - .isEqualTo(turnEventBaseline) - .withFailMessage("TurnEvent was built improperly"); + .withFailMessage("TurnEvent was built improperly") + .isEqualTo(turnEventBaseline); } @Test @@ -185,8 +185,9 @@ class EventBuilderTest { baseline.timeLeft = -144; assertThat(gameEvent) - .isEqualTo(baseline) - .withFailMessage("GameEvent was built improperly"); + .withFailMessage("GameEvent was built improperly") + .isEqualTo(baseline); + } @Test @@ -211,8 +212,9 @@ class EventBuilderTest { baseline.winCondition = true; assertThat(gameStateEvent) - .isEqualTo(baseline) - .withFailMessage("GameStateEvent was built improperly"); + .withFailMessage("GameStateEvent was built improperly") + .isEqualTo(baseline); + } @Test @@ -268,12 +270,12 @@ class EventBuilderTest { assertEquals(des.targetField, des2.targetField); // EntityEvent des2 = new EntityEvent(eb.); - assertTrue(des.equals(des2)); + assertEquals(des, des2); assertEquals(des.hashCode(), des2.hashCode()); des.targetField = new IntVector2(3,3); - assertFalse(des.equals(des2)); + assertNotEquals(des, des2); assertNotEquals(des.hashCode(), des2.hashCode()); @@ -311,12 +313,12 @@ class EventBuilderTest { assertEquals(des.originEntity, des2.originEntity); assertEquals(des.originField, des2.originField); - assertTrue(des.equals(des2)); + assertEquals(des, des2); assertEquals(des.hashCode(), des2.hashCode()); des.targetField = new IntVector2(3,3); - assertFalse(des.equals(des2)); + assertNotEquals(des, des2); assertNotEquals(des.hashCode(), des2.hashCode()); @@ -381,14 +383,14 @@ class EventBuilderTest { assertEquals(des.type, des2.type); assertEquals(des.customContent, des2.customContent); - assertTrue(des.equals(des2)); + assertEquals(des, des2); assertEquals(des.hashCode(), des2.hashCode()); Object o = new Object(); des.customContent = new HashMap<>(1, 1); des.customContent.put("a",o); - assertFalse(des.equals(des2)); + assertNotEquals(des, des2); assertNotEquals(des.hashCode(), des2.hashCode());