fix: fixed sonarqube-reported bugs in JSON and EventBuilderTest

This commit is contained in:
Yannik Bretschneider 2021-06-04 14:54:25 +02:00
parent 32cbb6d876
commit 672e5e7727
2 changed files with 18 additions and 16 deletions

View File

@ -32,7 +32,7 @@ public class JSON {
try { try {
return Optional.of(mapper.readValue(input, BasicMessage.class)); return Optional.of(mapper.readValue(input, BasicMessage.class));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); // e.printStackTrace();
return Optional.empty(); return Optional.empty();
} }
} }
@ -46,7 +46,7 @@ public class JSON {
try { try {
return Optional.of(mapper.writeValueAsString(input)); return Optional.of(mapper.writeValueAsString(input));
} catch (JsonProcessingException e) { } catch (JsonProcessingException e) {
e.printStackTrace(); // e.printStackTrace();
return Optional.empty(); return Optional.empty();
} }
} }

View File

@ -135,8 +135,8 @@ class EventBuilderTest {
roundSetupEventBaseline.characterOrder = turns; roundSetupEventBaseline.characterOrder = turns;
assertThat(roundSetupEvent) assertThat(roundSetupEvent)
.isEqualTo(roundSetupEventBaseline) .withFailMessage("RoundSetupEvent built improperly")
.withFailMessage("RoundSetupEvent built improperly"); .isEqualTo(roundSetupEventBaseline);
var turnEvent = new EventBuilder(EventType.TurnEvent) var turnEvent = new EventBuilder(EventType.TurnEvent)
.withNextCharacter(turn) .withNextCharacter(turn)
@ -153,8 +153,8 @@ class EventBuilderTest {
turnEventBaseline.turnCount = 5; turnEventBaseline.turnCount = 5;
assertThat(turnEvent) assertThat(turnEvent)
.isEqualTo(turnEventBaseline) .withFailMessage("TurnEvent was built improperly")
.withFailMessage("TurnEvent was built improperly"); .isEqualTo(turnEventBaseline);
} }
@Test @Test
@ -185,8 +185,9 @@ class EventBuilderTest {
baseline.timeLeft = -144; baseline.timeLeft = -144;
assertThat(gameEvent) assertThat(gameEvent)
.isEqualTo(baseline) .withFailMessage("GameEvent was built improperly")
.withFailMessage("GameEvent was built improperly"); .isEqualTo(baseline);
} }
@Test @Test
@ -211,8 +212,9 @@ class EventBuilderTest {
baseline.winCondition = true; baseline.winCondition = true;
assertThat(gameStateEvent) assertThat(gameStateEvent)
.isEqualTo(baseline) .withFailMessage("GameStateEvent was built improperly")
.withFailMessage("GameStateEvent was built improperly"); .isEqualTo(baseline);
} }
@Test @Test
@ -268,12 +270,12 @@ class EventBuilderTest {
assertEquals(des.targetField, des2.targetField); assertEquals(des.targetField, des2.targetField);
// EntityEvent des2 = new EntityEvent(eb.); // EntityEvent des2 = new EntityEvent(eb.);
assertTrue(des.equals(des2)); assertEquals(des, des2);
assertEquals(des.hashCode(), des2.hashCode()); assertEquals(des.hashCode(), des2.hashCode());
des.targetField = new IntVector2(3,3); des.targetField = new IntVector2(3,3);
assertFalse(des.equals(des2)); assertNotEquals(des, des2);
assertNotEquals(des.hashCode(), des2.hashCode()); assertNotEquals(des.hashCode(), des2.hashCode());
@ -311,12 +313,12 @@ class EventBuilderTest {
assertEquals(des.originEntity, des2.originEntity); assertEquals(des.originEntity, des2.originEntity);
assertEquals(des.originField, des2.originField); assertEquals(des.originField, des2.originField);
assertTrue(des.equals(des2)); assertEquals(des, des2);
assertEquals(des.hashCode(), des2.hashCode()); assertEquals(des.hashCode(), des2.hashCode());
des.targetField = new IntVector2(3,3); des.targetField = new IntVector2(3,3);
assertFalse(des.equals(des2)); assertNotEquals(des, des2);
assertNotEquals(des.hashCode(), des2.hashCode()); assertNotEquals(des.hashCode(), des2.hashCode());
@ -381,14 +383,14 @@ class EventBuilderTest {
assertEquals(des.type, des2.type); assertEquals(des.type, des2.type);
assertEquals(des.customContent, des2.customContent); assertEquals(des.customContent, des2.customContent);
assertTrue(des.equals(des2)); assertEquals(des, des2);
assertEquals(des.hashCode(), des2.hashCode()); assertEquals(des.hashCode(), des2.hashCode());
Object o = new Object(); Object o = new Object();
des.customContent = new HashMap<>(1, 1); des.customContent = new HashMap<>(1, 1);
des.customContent.put("a",o); des.customContent.put("a",o);
assertFalse(des.equals(des2)); assertNotEquals(des, des2);
assertNotEquals(des.hashCode(), des2.hashCode()); assertNotEquals(des.hashCode(), des2.hashCode());