added some tests for Events, Requests and their Builders

This commit is contained in:
C H 2021-06-01 09:40:03 +02:00
parent 6c06beb366
commit fe7687bc21
2 changed files with 52 additions and 6 deletions

View File

@ -216,20 +216,34 @@ class EventBuilderTest {
.withFailMessage("GameStateEvent was built improperly");
}
// TODO: implement tests for unchecked CharacterEvents and EntityEvents
@Test
void buildWrongEntityEvent1() {
void buildWrongEntityEvent() {
EventBuilder eb = new EventBuilder(EventType.DestroyedEntityEvent);
//the target entity is not set
EntityEvent des2 = eb
.withTargetField(new IntVector2(1,1))
.buildEntityEvent();
//the target entity is not set --> check() return false
boolean b = des2.check();
assertEquals(b, false);
}
@Test
void buildWrongCharacterEvent() {
EventBuilder eb = new EventBuilder(EventType.MeleeAttackEvent);
//the target entity is not set
CharacterEvent des2 = eb
.withTargetField(new IntVector2(1,1))
.buildCharacterEvent();
//the target entity, the origin and the target entity are not set --> check() return false
boolean b = des2.check();
assertEquals(b, false);
}
@Test
void buildEntityEvent() {
//testing EntityEvent class
@ -249,12 +263,20 @@ class EventBuilderTest {
.withTargetEntity(new EntityID(EntityType.P1,1))
.buildEntityEvent();
//testing EventBuilder
//testing EventBuilder and EntityEvent class
assertEquals(des.type, des2.type);
assertEquals(des.targetEntity, des2.targetEntity);
assertEquals(des.targetField, des2.targetField);
// EntityEvent des2 = new EntityEvent(eb.);
assertEquals(des.equals(des2), true);
assertEquals(des.hashCode(), des2.hashCode());
des.targetField = new IntVector2(3,3);
assertEquals(des.equals(des2), false);
assertNotEquals(des.hashCode(), des2.hashCode());
}
@ -282,13 +304,23 @@ class EventBuilderTest {
.withOriginEntity(new EntityID(EntityType.P2,2))
.withTargetEntity(new EntityID(EntityType.P1,1))
.buildCharacterEvent();
//testing EventBuilder
//testing EventBuilder and CharacterEvent class
assertEquals(des.type, des2.type);
assertEquals(des.targetEntity, des2.targetEntity);
assertEquals(des.targetField, des2.targetField);
assertEquals(des.originEntity, des2.originEntity);
assertEquals(des.originField, des2.originField);
assertEquals(des.equals(des2), true);
assertEquals(des.hashCode(), des2.hashCode());
des.targetField = new IntVector2(3,3);
assertEquals(des.equals(des2), false);
assertNotEquals(des.hashCode(), des2.hashCode());
}
@Test
@ -346,9 +378,20 @@ class EventBuilderTest {
.withCustomContent(new HashMap<String, Object>())
.buildCustomEvent();
//testing EventBuilder
//testing EventBuilder and CustomEvent class
assertEquals(des.type, des2.type);
assertEquals(des.customContent, des2.customContent);
assertEquals(des.equals(des2), true);
assertEquals(des.hashCode(), des2.hashCode());
Object o = new Object();
des.customContent = new HashMap<String, Object>(1,1);
des.customContent.put("a",o);
assertEquals(des.equals(des2), false);
assertNotEquals(des.hashCode(), des2.hashCode());
}
}

View File

@ -17,7 +17,7 @@ import java.util.HashMap;
class RequestBuilderTest {
@Test
void testEqualsCharacterRequest() {
void testEqualsAndHashCodeCharacterRequest() {
CharacterRequest cr = new CharacterRequest();
cr.type = RequestType.MoveRequest;
@ -55,6 +55,9 @@ class RequestBuilderTest {
assertEquals(cr.equals(cr2), true);
assertEquals(cr.equals(cr3), false);
assertEquals(cr.hashCode(), cr2.hashCode());
assertNotEquals(cr.hashCode(), cr3.hashCode());
}
@Test