From 75e9ee07a5e04d6848a33541ef1bafd102b22cee Mon Sep 17 00:00:00 2001 From: C H Date: Sun, 30 May 2021 18:50:21 +0200 Subject: [PATCH] testing: RequestBuilder testing --- .../requests/RequestBuilderTest.java | 109 ++++++++++++++++++ 1 file changed, 109 insertions(+) create mode 100644 src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java diff --git a/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java b/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java new file mode 100644 index 0000000..3357c9d --- /dev/null +++ b/src/test/java/uulm/teamname/marvelous/gamelibrary/requests/RequestBuilderTest.java @@ -0,0 +1,109 @@ +package uulm.teamname.marvelous.gamelibrary.requests; + +import static org.junit.jupiter.api.Assertions.*; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +import static org.assertj.core.api.Assertions.*; +import static org.junit.jupiter.api.Assertions.*; + +import uulm.teamname.marvelous.gamelibrary.IntVector2; +import uulm.teamname.marvelous.gamelibrary.entities.*; +import uulm.teamname.marvelous.gamelibrary.entities.Character; + +import java.util.ArrayList; +import java.util.HashMap; + +class RequestBuilderTest { + + @Test + void testEqualsCharacterRequest() { + + CharacterRequest cr = new CharacterRequest(); + cr.type = RequestType.MoveRequest; + cr.originEntity = new EntityID(EntityType.P1, 1); + cr.targetEntity = new EntityID(EntityType.P2, 2); + cr.originField = new IntVector2(1, 1); + cr.targetField = new IntVector2(2, 2); + cr.value = 100; + HashMap map = new HashMap<>(); + map.put(1,StoneType.SoulStone); + cr.stoneType = StoneType.valueOf(1); + + CharacterRequest cr2 = new CharacterRequest(); + cr2.type = RequestType.MoveRequest; + cr2.originEntity = new EntityID(EntityType.P1, 1); + cr2.targetEntity = new EntityID(EntityType.P2, 2); + cr2.originField = new IntVector2(1, 1); + cr2.targetField = new IntVector2(2, 2); + cr2.value = 100; + HashMap map2 = new HashMap<>(); + map.put(1,StoneType.SoulStone); + cr2.stoneType = StoneType.valueOf(1); + + CharacterRequest cr3 = new CharacterRequest(); + cr3.type = RequestType.MoveRequest; + cr3.originEntity = new EntityID(EntityType.P1, 1); + cr3.targetEntity = new EntityID(EntityType.P2, 2); + cr3.originField = new IntVector2(1, 1); + cr3.targetField = new IntVector2(2, 2); + cr3.value = 200; + HashMap map3 = new HashMap<>(); + map.put(1,StoneType.SoulStone); + cr3.stoneType = StoneType.valueOf(1); + + assertEquals(cr.equals(cr2), true); + assertEquals(cr.equals(cr3), false); + + } + + @Test + void testBuildCharacterRequest() { + + CharacterRequest cr = new CharacterRequest(); + cr.type = RequestType.MoveRequest; + cr.originEntity = new EntityID(EntityType.P1, 1); + cr.targetEntity = new EntityID(EntityType.P2, 2); + cr.originField = new IntVector2(1, 1); + cr.targetField = new IntVector2(2, 2); + cr.value = 100; + HashMap map = new HashMap<>(); + map.put(1,StoneType.SoulStone); + cr.stoneType = StoneType.valueOf(1); + + RequestBuilder rb = new RequestBuilder(RequestType.MoveRequest); + CharacterRequest cr2 = rb + .withOriginField(new IntVector2(1, 1)) + .withTargetField(new IntVector2(2, 2)) + .withOriginEntity(new EntityID(EntityType.P1, 1)) + .withTargetEntity(new EntityID(EntityType.P2, 2)) + .withValue(100) + .withStoneType(StoneType.valueOf(1)) + .buildCharacterRequest(); + + //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)"; + + assertEquals(cr.equals(cr2), true); + + } + + @Test + void testBuildGameRequest() { + + //implementation of the GameRequest is mostly missing yet. + + GameRequest gr = new GameRequest(); + gr.type = RequestType.PauseStopRequest; + + RequestBuilder rb = new RequestBuilder(RequestType.PauseStopRequest); + + GameRequest gr2 = rb.buildGameRequest(); + + assertEquals(gr.type, gr2.type); + + + + + } +} \ No newline at end of file