summaryrefslogtreecommitdiff
path: root/src/main/java
diff options
context:
space:
mode:
authorjbion <joffrey.bion@amadeus.com>2016-12-20 22:47:25 +0100
committerjbion <joffrey.bion@amadeus.com>2016-12-21 01:29:28 +0100
commitb21b0b854de124776d547c9cb2d42443396833f9 (patch)
tree1b3caaecf062d5a95d3d1e492faf965b942c30a9 /src/main/java
parentRemove experimental TestController (diff)
downloadseven-wonders-b21b0b854de124776d547c9cb2d42443396833f9.tar.gz
seven-wonders-b21b0b854de124776d547c9cb2d42443396833f9.tar.bz2
seven-wonders-b21b0b854de124776d547c9cb2d42443396833f9.zip
Add test for ScienceProgressSerializer
Diffstat (limited to 'src/main/java')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/boards/Science.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.java17
2 files changed, 14 insertions, 5 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/boards/Science.java b/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
index f3d6a681..71687657 100644
--- a/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
+++ b/src/main/java/org/luxons/sevenwonders/game/boards/Science.java
@@ -32,7 +32,7 @@ public class Science {
}
public int size() {
- return quantities.size() + jokers;
+ return quantities.values().stream().mapToInt(q -> q).sum() + jokers;
}
public int computePoints() {
diff --git a/src/main/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.java b/src/main/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.java
index 0535b90a..b6e38540 100644
--- a/src/main/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.java
+++ b/src/main/java/org/luxons/sevenwonders/game/data/serializers/ScienceProgressSerializer.java
@@ -2,6 +2,10 @@ package org.luxons.sevenwonders.game.data.serializers;
import java.lang.reflect.Type;
+import org.luxons.sevenwonders.game.boards.Science;
+import org.luxons.sevenwonders.game.boards.ScienceType;
+import org.luxons.sevenwonders.game.effects.ScienceProgress;
+
import com.google.gson.JsonDeserializationContext;
import com.google.gson.JsonDeserializer;
import com.google.gson.JsonElement;
@@ -10,9 +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.boards.Science;
-import org.luxons.sevenwonders.game.boards.ScienceType;
-import org.luxons.sevenwonders.game.effects.ScienceProgress;
public class ScienceProgressSerializer implements JsonSerializer<ScienceProgress>, JsonDeserializer<ScienceProgress> {
@@ -47,9 +48,17 @@ public class ScienceProgressSerializer implements JsonSerializer<ScienceProgress
if ("any".equals(s)) {
science.addJoker(1);
} else {
- science.add(context.deserialize(json, ScienceType.class), 1);
+ science.add(deserializeScienceType(json, context), 1);
}
scienceProgress.setScience(science);
return scienceProgress;
}
+
+ private ScienceType deserializeScienceType(JsonElement json, JsonDeserializationContext context) {
+ ScienceType type = context.deserialize(json, ScienceType.class);
+ if (type == null) {
+ throw new IllegalArgumentException("Invalid science type " + json.getAsString());
+ }
+ return type;
+ }
}
bgstack15