109 lines
3.7 KiB
Java
109 lines
3.7 KiB
Java
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<Integer, StoneType> 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<Integer, StoneType> 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<Integer, StoneType> 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<Integer, StoneType> 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);
|
|
|
|
|
|
|
|
|
|
}
|
|
} |