some improvements for tests

This commit is contained in:
C H 2021-06-06 12:46:10 +02:00
parent 38865aea70
commit 8dd5b864f3
4 changed files with 32 additions and 36 deletions

View File

@ -220,7 +220,7 @@ class EventBuilderTest {
@Test @Test
void buildWrongEntityEvent() { void buildWrongEntityEvent() {
EventBuilder eb = new EventBuilder(EventType.DestroyedEntityEvent); EventBuilder eb = new EventBuilder(EventType.DestroyedEntityEvent);
//the target entity is not set //the target entity is not set. This is an error.
EntityEvent des2 = eb EntityEvent des2 = eb
.withTargetField(new IntVector2(1,1)) .withTargetField(new IntVector2(1,1))
.buildEntityEvent(); .buildEntityEvent();
@ -234,7 +234,7 @@ class EventBuilderTest {
@Test @Test
void buildWrongCharacterEvent() { void buildWrongCharacterEvent() {
EventBuilder eb = new EventBuilder(EventType.MeleeAttackEvent); EventBuilder eb = new EventBuilder(EventType.MeleeAttackEvent);
//the target entity is not set //the target entity is not set. This is an error.
CharacterEvent des2 = eb CharacterEvent des2 = eb
.withTargetField(new IntVector2(1,1)) .withTargetField(new IntVector2(1,1))
.buildCharacterEvent(); .buildCharacterEvent();
@ -247,7 +247,7 @@ class EventBuilderTest {
@Test @Test
void buildEntityEvent() { void buildEntityEvent() {
//testing EntityEvent class //testing EntityEvent and EventBuilder classes
assertThat(new EventBuilder(EventType.DestroyedEntityEvent) assertThat(new EventBuilder(EventType.DestroyedEntityEvent)
.withTargetField(new IntVector2(1,1)) .withTargetField(new IntVector2(1,1))
.withTargetEntity(new EntityID(EntityType.P1,1)) .withTargetEntity(new EntityID(EntityType.P1,1))
@ -264,11 +264,10 @@ class EventBuilderTest {
.withTargetEntity(new EntityID(EntityType.P1,1)) .withTargetEntity(new EntityID(EntityType.P1,1))
.buildEntityEvent(); .buildEntityEvent();
//testing EventBuilder and EntityEvent class //testing EventBuilder and EntityEvent classes
assertEquals(des.type, des2.type); assertEquals(des.type, des2.type);
assertEquals(des.targetEntity, des2.targetEntity); assertEquals(des.targetEntity, des2.targetEntity);
assertEquals(des.targetField, des2.targetField); assertEquals(des.targetField, des2.targetField);
// EntityEvent des2 = new EntityEvent(eb.);
assertEquals(des, des2); assertEquals(des, des2);
assertEquals(des.hashCode(), des2.hashCode()); assertEquals(des.hashCode(), des2.hashCode());
@ -283,7 +282,7 @@ class EventBuilderTest {
@Test @Test
void buildCharacterEvent() { void buildCharacterEvent() {
//testing CharacterEvent class //testing CharacterEvent and EventBuilder classes
assertThat(new EventBuilder(EventType.MeleeAttackEvent) assertThat(new EventBuilder(EventType.MeleeAttackEvent)
.withOriginField(new IntVector2(2,2)) .withOriginField(new IntVector2(2,2))
.withTargetField(new IntVector2(1,1)) .withTargetField(new IntVector2(1,1))
@ -364,7 +363,7 @@ class EventBuilderTest {
@Test @Test
void buildCustomEvent() { void buildCustomEvent() {
//testing CustomEvent class //testing CustomEvent and EventBuilder classes
assertThat(new EventBuilder(EventType.CustomEvent) assertThat(new EventBuilder(EventType.CustomEvent)
.withCustomContent(new HashMap<>()) .withCustomContent(new HashMap<>())
.buildCustomEvent().check()).isTrue(); .buildCustomEvent().check()).isTrue();

View File

@ -17,7 +17,7 @@ class EntitySerializerTest {
@Test @Test
void serializeCharacter() throws JsonProcessingException { void serializeCharacter() throws JsonProcessingException {
//test if all required values are set in json //testing, if all required values are set in json
// and that this is done in the right order as defined in the methods serialize() and serializeCharacter(). // and that this is done in the right order as defined in the methods serialize() and serializeCharacter().
var mapper = new ObjectMapper(); var mapper = new ObjectMapper();
@ -90,8 +90,6 @@ class EntitySerializerTest {
//________________________________________________ //________________________________________________
// al.removeStone(StoneType.MindStone);
//Inventory inv = new Inventory(al);
var npc0= new NPC( var npc0= new NPC(
new EntityID(EntityType.NPC, 3), new EntityID(EntityType.NPC, 3),
new IntVector2(12, 24)); new IntVector2(12, 24));

View File

@ -4,6 +4,8 @@ import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper; import com.fasterxml.jackson.databind.ObjectMapper;
//import net.jqwik.api.*; //import net.jqwik.api.*;
//import net.jqwik.api.lifecycle.BeforeProperty; //import net.jqwik.api.lifecycle.BeforeProperty;
import net.jqwik.api.*;
import net.jqwik.api.lifecycle.BeforeProperty;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import uulm.teamname.marvelous.gamelibrary.IntVector2; import uulm.teamname.marvelous.gamelibrary.IntVector2;
import uulm.teamname.marvelous.gamelibrary.entities.*; import uulm.teamname.marvelous.gamelibrary.entities.*;
@ -14,7 +16,6 @@ import java.util.HashMap;
import static org.assertj.core.api.Assertions.*; import static org.assertj.core.api.Assertions.*;
public class EventSerializerTest { public class EventSerializerTest {
//System.out.println(mapper.writeValueAsString(gse));
EntityID[] turns; EntityID[] turns;
EntityID turn; EntityID turn;
@ -72,10 +73,18 @@ public class EventSerializerTest {
gse2.activeCharacter = ac; gse2.activeCharacter = ac;
System.out.println(mapper.writeValueAsString(gse2)); System.out.println(mapper.writeValueAsString(gse2));
// ERROR!!! "Can not write a field name, expecting a value" bei active Character jsonRepresentingGSE = """
{"eventType":"GamestateEvent",
"entities":[{"entityType":"NPC","ID":1,"MP":0,"stones":[],
"position":[1,1]}],"mapSize":[42,24],
"turnOrder":[{"entityID":"NPC","ID":1}],
"activeCharacter":{"entityID":"P1","ID":2},
"stoneCooldowns":[6,5,4,3,2,1],
"winCondition":false
}""".replace("\n", "");
// assertThat(mapper.writeValueAsString(gse2)) assertThat(mapper.writeValueAsString(gse2))
// .isEqualTo(jsonRepresentingGSE); .isEqualTo(jsonRepresentingGSE);
} }
@ -181,13 +190,8 @@ public class EventSerializerTest {
System.out.println(mapper.writeValueAsString(ce2)); System.out.println(mapper.writeValueAsString(ce2));
// ERROR !!! "Can not start an object, expecting field name (context: Object)" bei stoneType assertThat(mapper.writeValueAsString(ce2))
//assertThat(mapper.writeValueAsString(ce2)) .isEqualTo(jsonRepresentingEE);
// .isEqualTo(jsonRepresentingEE);
//gen.writeObject(new EntityID(EntityType.InfinityStones, value.stoneType.getID()));
} }
@ -204,18 +208,15 @@ public class EventSerializerTest {
var jsonRepresentingEE = """ var jsonRepresentingEE = """
{ {
"eventType":"MeleeAttackEvent", "eventType":"RoundSetupEvent",
"originEntity":{"entityID":"P2","ID":7}, "roundCount":5,
"targetEntity":{"entityID":"P1","ID":5}, "characterOrder":[{"entityID":"NPC","ID":1}]
"originField":null,"targetField":[2,2]
}""".replace("\n", ""); }""".replace("\n", "");
// System.out.println(mapper.writeValueAsString(ge)); // System.out.println(mapper.writeValueAsString(ge));
// ERROR !!! "Current context not Array but Object" bei characterorder assertThat(mapper.writeValueAsString(ge))
.isEqualTo(jsonRepresentingEE);
// assertThat(mapper.writeValueAsString(ge))
// .isEqualTo(jsonRepresentingEE);
GameEvent ge2 = new GameEvent(); GameEvent ge2 = new GameEvent();
ge2.type = EventType.TurnEvent; ge2.type = EventType.TurnEvent;
@ -301,7 +302,7 @@ public class EventSerializerTest {
.isEqualTo(jsonRepresentingEE); .isEqualTo(jsonRepresentingEE);
} }
/*
ObjectMapper mapper; ObjectMapper mapper;
@BeforeProperty @BeforeProperty
@ -376,6 +377,6 @@ public class EventSerializerTest {
}); });
} }
*/
} }

View File

@ -80,7 +80,7 @@ class RequestBuilderTest {
.buildCharacterRequest(); .buildCharacterRequest();
//since we tested in the test before that the equals() method from the CharacterRequest class works fine //since we tested in the test before that the equals() method from the CharacterRequest class works fine
// we can use this method here. and do not have to test all properties for itself, e.g.: "assertEquals(cr.targetEntity, cr2.targetEntity)"; // we can use this method here and do not have to test all properties for itself, e.g.: "assertEquals(cr.targetEntity, cr2.targetEntity)";
assertTrue(cr.equals(cr2)); assertTrue(cr.equals(cr2));
@ -89,8 +89,6 @@ class RequestBuilderTest {
@Test @Test
void testBuildGameRequest() { void testBuildGameRequest() {
//implementation of the GameRequest class is mostly missing yet.
GameRequest gr = new GameRequest(); GameRequest gr = new GameRequest();
gr.type = RequestType.PauseStopRequest; gr.type = RequestType.PauseStopRequest;