summaryrefslogtreecommitdiff
path: root/src/main/java/org
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-21 02:34:48 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-21 02:34:48 +0100
commitb892089b65aa6f2e23c420f764f50e7231ada659 (patch)
treea474258c82705fcd2373a1d4e822efe22d0665ab /src/main/java/org
parentRemove explicit types from toJson calls (diff)
downloadseven-wonders-b892089b65aa6f2e23c420f764f50e7231ada659.tar.gz
seven-wonders-b892089b65aa6f2e23c420f764f50e7231ada659.tar.bz2
seven-wonders-b892089b65aa6f2e23c420f764f50e7231ada659.zip
Add test for NumericEffectSerializer
Diffstat (limited to 'src/main/java/org')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java11
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java19
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java19
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java19
4 files changed, 64 insertions, 4 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java b/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java
index e8e5d163..8f50db29 100644
--- a/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java
+++ b/src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java
@@ -2,6 +2,11 @@ package org.luxons.sevenwonders.game.data.serializers;
import java.lang.reflect.Type;
+import org.luxons.sevenwonders.game.effects.Effect;
+import org.luxons.sevenwonders.game.effects.GoldIncrease;
+import org.luxons.sevenwonders.game.effects.MilitaryReinforcements;
+import org.luxons.sevenwonders.game.effects.RawPointsIncrease;
+
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
@@ -9,10 +14,6 @@ import com.google.gson.JsonParseException;
import com.google.gson.JsonPrimitive;
import com.google.gson.JsonSerializationContext;
import com.google.gson.JsonSerializer;
-import org.luxons.sevenwonders.game.effects.Effect;
-import org.luxons.sevenwonders.game.effects.GoldIncrease;
-import org.luxons.sevenwonders.game.effects.MilitaryReinforcements;
-import org.luxons.sevenwonders.game.effects.RawPointsIncrease;
public class NumericEffectSerializer implements JsonSerializer<Effect>, JsonDeserializer<Effect> {
@@ -25,6 +26,8 @@ public class NumericEffectSerializer implements JsonSerializer<Effect>, JsonDese
value = ((GoldIncrease)effect).getAmount();
} else if (RawPointsIncrease.class.equals(typeOfSrc)) {
value = ((RawPointsIncrease)effect).getPoints();
+ } else {
+ throw new IllegalArgumentException("Unknown numeric effet " + typeOfSrc.getTypeName());
}
return new JsonPrimitive(value);
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
index c2250d23..8a319ab6 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/GoldIncrease.java
@@ -1,5 +1,7 @@
package org.luxons.sevenwonders.game.effects;
+import java.util.Objects;
+
import org.luxons.sevenwonders.game.boards.Board;
public class GoldIncrease extends InstantEffect {
@@ -18,4 +20,21 @@ public class GoldIncrease extends InstantEffect {
public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
board.setGold(board.getGold() + amount);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ GoldIncrease that = (GoldIncrease)o;
+ return amount == that.amount;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(amount);
+ }
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
index 7cfa4905..ad1497dd 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/MilitaryReinforcements.java
@@ -1,5 +1,7 @@
package org.luxons.sevenwonders.game.effects;
+import java.util.Objects;
+
import org.luxons.sevenwonders.game.boards.Board;
public class MilitaryReinforcements extends InstantEffect {
@@ -18,4 +20,21 @@ public class MilitaryReinforcements extends InstantEffect {
public void apply(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
board.setNbWarSymbols(board.getNbWarSymbols() + count);
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ MilitaryReinforcements that = (MilitaryReinforcements)o;
+ return count == that.count;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(count);
+ }
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
index 53fcecd4..76ab30b0 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/RawPointsIncrease.java
@@ -1,5 +1,7 @@
package org.luxons.sevenwonders.game.effects;
+import java.util.Objects;
+
import org.luxons.sevenwonders.game.boards.Board;
public class RawPointsIncrease extends EndGameEffect {
@@ -18,4 +20,21 @@ public class RawPointsIncrease extends EndGameEffect {
public int computePoints(Board board, Board leftNeighbourBoard, Board rightNeighbourBoard) {
return points;
}
+
+ @Override
+ public boolean equals(Object o) {
+ if (this == o) {
+ return true;
+ }
+ if (o == null || getClass() != o.getClass()) {
+ return false;
+ }
+ RawPointsIncrease that = (RawPointsIncrease)o;
+ return points == that.points;
+ }
+
+ @Override
+ public int hashCode() {
+ return Objects.hash(points);
+ }
}
bgstack15