From 9efaf7909ba72607254ee9248b98f6cd5856b693 Mon Sep 17 00:00:00 2001 From: jbion Date: Fri, 23 Dec 2016 00:52:08 +0100 Subject: Add brush test for game definition loading to ensure no exception occur --- .../java/org/luxons/sevenwonders/game/Settings.java | 2 +- .../sevenwonders/game/data/GameDefinitionLoader.java | 11 ++++++----- .../game/data/definitions/CardDefinition.java | 18 +----------------- .../game/data/definitions/WonderDefinition.java | 17 +++-------------- .../sevenwonders/game/data/definitions/WonderSide.java | 5 +++++ .../luxons/sevenwonders/game/wonders/WonderSide.java | 5 ----- 6 files changed, 16 insertions(+), 42 deletions(-) create mode 100644 src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSide.java delete mode 100644 src/main/java/org/luxons/sevenwonders/game/wonders/WonderSide.java (limited to 'src/main/java/org/luxons') diff --git a/src/main/java/org/luxons/sevenwonders/game/Settings.java b/src/main/java/org/luxons/sevenwonders/game/Settings.java index b3ee2232..ecd22d24 100644 --- a/src/main/java/org/luxons/sevenwonders/game/Settings.java +++ b/src/main/java/org/luxons/sevenwonders/game/Settings.java @@ -2,7 +2,7 @@ package org.luxons.sevenwonders.game; import java.util.Random; -import org.luxons.sevenwonders.game.wonders.WonderSide; +import org.luxons.sevenwonders.game.data.definitions.WonderSide; public class Settings { diff --git a/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java b/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java index 977bb100..30457d86 100644 --- a/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java +++ b/src/main/java/org/luxons/sevenwonders/game/data/GameDefinitionLoader.java @@ -7,9 +7,6 @@ import java.io.Reader; import java.lang.reflect.Type; import java.util.List; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; -import com.google.gson.reflect.TypeToken; import org.luxons.sevenwonders.game.data.definitions.DecksDefinition; import org.luxons.sevenwonders.game.data.definitions.WonderDefinition; import org.luxons.sevenwonders.game.data.serializers.NumericEffectSerializer; @@ -27,6 +24,10 @@ import org.luxons.sevenwonders.game.resources.ResourceType; import org.luxons.sevenwonders.game.resources.Resources; import org.springframework.stereotype.Component; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; +import com.google.gson.reflect.TypeToken; + @Component public class GameDefinitionLoader { @@ -41,14 +42,14 @@ public class GameDefinitionLoader { private final GameDefinition gameDefinition; public GameDefinitionLoader() { - gameDefinition = new GameDefinition(loadWonders(), loadDecks()); + gameDefinition = load(); } public GameDefinition getGameDefinition() { return gameDefinition; } - public static GameDefinition load() { + private static GameDefinition load() { return new GameDefinition(loadWonders(), loadDecks()); } diff --git a/src/main/java/org/luxons/sevenwonders/game/data/definitions/CardDefinition.java b/src/main/java/org/luxons/sevenwonders/game/data/definitions/CardDefinition.java index 48853899..f469ca4f 100644 --- a/src/main/java/org/luxons/sevenwonders/game/data/definitions/CardDefinition.java +++ b/src/main/java/org/luxons/sevenwonders/game/data/definitions/CardDefinition.java @@ -31,23 +31,7 @@ public class CardDefinition implements Definition { return new Card(name, color, requirements, effect.create(settings), chainParent, chainChildren, image); } - public String getName() { - return name; - } - - public Color getColor() { - return color; - } - - public Map getCountPerNbPlayer() { + Map getCountPerNbPlayer() { return countPerNbPlayer; } - - public String getImage() { - return image; - } - - public void setImage(String image) { - this.image = image; - } } diff --git a/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java index 4d0f411d..2dfe7bb7 100644 --- a/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java +++ b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderDefinition.java @@ -1,6 +1,7 @@ package org.luxons.sevenwonders.game.data.definitions; import java.util.List; +import java.util.Map; import java.util.stream.Collectors; import org.luxons.sevenwonders.game.Settings; @@ -12,32 +13,20 @@ public class WonderDefinition implements Definition { private String name; - private WonderSideDefinition a; - - private WonderSideDefinition b; + private Map sides; @Override public Wonder create(Settings settings) { Wonder wonder = new Wonder(); wonder.setName(name); - WonderSideDefinition wonderSideDef = pickSide(settings); + WonderSideDefinition wonderSideDef = sides.get(settings.getWonderSide()); wonder.setInitialResource(wonderSideDef.getInitialResource()); wonder.setStages(wonderSideDef.createStages(settings)); wonder.setImage(wonderSideDef.getImage()); return wonder; } - private WonderSideDefinition pickSide(Settings settings) { - switch (settings.getWonderSide()){ - case A: - return a; - case B: - return b; - } - throw new IllegalArgumentException("Unsupported wonder side " + settings.getWonderSide()); - } - public static class WonderSideDefinition { private ResourceType initialResource; diff --git a/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSide.java b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSide.java new file mode 100644 index 00000000..9cfeb767 --- /dev/null +++ b/src/main/java/org/luxons/sevenwonders/game/data/definitions/WonderSide.java @@ -0,0 +1,5 @@ +package org.luxons.sevenwonders.game.data.definitions; + +public enum WonderSide { + A, B; +} diff --git a/src/main/java/org/luxons/sevenwonders/game/wonders/WonderSide.java b/src/main/java/org/luxons/sevenwonders/game/wonders/WonderSide.java deleted file mode 100644 index 4a59e648..00000000 --- a/src/main/java/org/luxons/sevenwonders/game/wonders/WonderSide.java +++ /dev/null @@ -1,5 +0,0 @@ -package org.luxons.sevenwonders.game.wonders; - -public enum WonderSide { - A, B; -} -- cgit