summaryrefslogtreecommitdiff
path: root/src
diff options
context:
space:
mode:
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/Player.java8
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/data/serializers/NumericEffectSerializer.java4
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java2
-rw-r--r--src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java1
-rw-r--r--src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java2
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/LobbyTest.java26
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java4
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java23
-rw-r--r--src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java4
9 files changed, 34 insertions, 40 deletions
diff --git a/src/main/java/org/luxons/sevenwonders/game/Player.java b/src/main/java/org/luxons/sevenwonders/game/Player.java
index 3e25cb80..c8c1509c 100644
--- a/src/main/java/org/luxons/sevenwonders/game/Player.java
+++ b/src/main/java/org/luxons/sevenwonders/game/Player.java
@@ -14,13 +14,9 @@ public class Player {
private transient Game game;
- public Player(String userName) {
+ public Player(String userName, String displayName) {
this.userName = userName;
- }
-
- public Player(String displayName, String userName) {
- this(userName);
- setDisplayName(displayName);
+ this.displayName = displayName;
}
public String getUserName() {
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 8f50db29..c1a51f24 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
@@ -19,7 +19,7 @@ public class NumericEffectSerializer implements JsonSerializer<Effect>, JsonDese
@Override
public JsonElement serialize(Effect effect, Type typeOfSrc, JsonSerializationContext context) {
- int value = 0;
+ int value;
if (MilitaryReinforcements.class.equals(typeOfSrc)) {
value = ((MilitaryReinforcements)effect).getCount();
} else if (GoldIncrease.class.equals(typeOfSrc)) {
@@ -27,7 +27,7 @@ public class NumericEffectSerializer implements JsonSerializer<Effect>, JsonDese
} else if (RawPointsIncrease.class.equals(typeOfSrc)) {
value = ((RawPointsIncrease)effect).getPoints();
} else {
- throw new IllegalArgumentException("Unknown numeric effet " + typeOfSrc.getTypeName());
+ throw new IllegalArgumentException("Unknown numeric effect " + typeOfSrc.getTypeName());
}
return new JsonPrimitive(value);
}
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java b/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java
index 79216c93..8f4340cf 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/InstantOwnBoardEffect.java
@@ -10,7 +10,7 @@ public abstract class InstantOwnBoardEffect implements Effect {
apply(table.getBoard(playerIndex));
}
- public abstract void apply(Board board);
+ protected abstract void apply(Board board);
@Override
public int computePoints(Table table, int playerIndex) {
diff --git a/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
index ff2a59c7..9724dfcd 100644
--- a/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
+++ b/src/main/java/org/luxons/sevenwonders/game/effects/ProductionIncrease.java
@@ -17,6 +17,7 @@ public class ProductionIncrease extends InstantOwnBoardEffect {
this.production = production;
}
+ @Override
public void apply(Board board) {
board.getProduction().addAll(production);
}
diff --git a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
index e671088f..cd63c440 100644
--- a/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
+++ b/src/main/java/org/luxons/sevenwonders/repositories/PlayerRepository.java
@@ -21,7 +21,7 @@ public class PlayerRepository {
}
private Player createPlayer(String userName, String displayName) {
- Player player = new Player(displayName, userName);
+ Player player = new Player(userName, displayName);
add(player);
return player;
}
diff --git a/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java b/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java
index 1bed446b..a8c6ae6e 100644
--- a/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/LobbyTest.java
@@ -46,7 +46,7 @@ public class LobbyTest {
@Before
public void setUp() {
- gameOwner = new Player("Game owner", "gameowner");
+ gameOwner = new Player("gameowner", "Game owner");
lobby = new Lobby(0, "Test Game", gameOwner, gameDefinition);
}
@@ -72,22 +72,22 @@ public class LobbyTest {
@Test
public void isOwner_falseWhenOtherPlayerName() {
- Player player = new Player("Test User", "testuser");
+ Player player = new Player("testuser", "Test User");
lobby.addPlayer(player);
assertFalse(lobby.isOwner(player.getUserName()));
}
@Test
public void addPlayer_success() {
- Player player = new Player("Test User", "testuser");
+ Player player = new Player("testuser", "Test User");
lobby.addPlayer(player);
assertTrue(lobby.containsUser("testuser"));
}
@Test(expected = PlayerNameAlreadyUsedException.class)
public void addPlayer_failsOnSameName() {
- Player player = new Player("Test User", "testuser");
- Player player2 = new Player("Test User", "testuser2");
+ Player player = new Player("testuser", "Test User");
+ Player player2 = new Player("testuser2", "Test User");
lobby.addPlayer(player);
lobby.addPlayer(player2);
}
@@ -103,21 +103,21 @@ public class LobbyTest {
// total with owner is the minimum
addPlayers(gameDefinition.getMinPlayers() - 1);
lobby.startGame();
- lobby.addPlayer(new Player("The Late Guy", "soonerNextTime"));
+ lobby.addPlayer(new Player("soonerNextTime", "The Late Guy"));
}
private void addPlayers(int nbPlayers) {
for (int i = 0; i < nbPlayers; i++) {
- Player player = new Player("Test User " + i, "testuser" + i);
+ Player player = new Player("testuser" + i, "Test User " + i);
lobby.addPlayer(player);
}
}
@Test
public void reorderPlayers_failsOnSameName() {
- Player player1 = new Player("Test User 1", "testuser1");
- Player player2 = new Player("Test User 2", "testuser2");
- Player player3 = new Player("Test User 3", "testuser3");
+ Player player1 = new Player("testuser1", "Test User 1");
+ Player player2 = new Player("testuser2", "Test User 2");
+ Player player3 = new Player("testuser3", "Test User 3");
lobby.addPlayer(player1);
lobby.addPlayer(player2);
lobby.addPlayer(player3);
@@ -129,9 +129,9 @@ public class LobbyTest {
@Test(expected = UnknownPlayerException.class)
public void reorderPlayers_failsOnUnknownPlayer() {
- Player player1 = new Player("Test User 1", "testuser1");
- Player player2 = new Player("Test User 2", "testuser2");
- Player player3 = new Player("Test User 3", "testuser3");
+ Player player1 = new Player("testuser1", "Test User 1");
+ Player player2 = new Player("testuser2", "Test User 2");
+ Player player3 = new Player("testuser3", "Test User 3");
lobby.addPlayer(player1);
lobby.addPlayer(player2);
lobby.addPlayer(player3);
diff --git a/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java b/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
index 35b2df7d..675c77de 100644
--- a/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/boards/BoardTest.java
@@ -63,7 +63,7 @@ public class BoardTest {
}
@Theory
- public void removeOld_successfulWhenNotTooMuch(@FromDataPoints("gold") int initialGold,
+ public void removeGold_successfulWhenNotTooMuch(@FromDataPoints("gold") int initialGold,
@FromDataPoints("gold") int goldRemoved) {
assumeTrue(goldRemoved >= 0);
assumeTrue(initialGold >= goldRemoved);
@@ -74,7 +74,7 @@ public class BoardTest {
}
@Theory
- public void removeOld_failsWhenTooMuch(@FromDataPoints("gold") int initialGold,
+ public void removeGold_failsWhenTooMuch(@FromDataPoints("gold") int initialGold,
@FromDataPoints("gold") int goldRemoved) {
assumeTrue(goldRemoved >= 0);
assumeTrue(initialGold < goldRemoved);
diff --git a/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java b/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java
index 68c9a676..17940361 100644
--- a/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java
+++ b/src/test/java/org/luxons/sevenwonders/game/data/serializers/ProductionIncreaseSerializerTest.java
@@ -30,7 +30,7 @@ public class ProductionIncreaseSerializerTest {
.create();
}
- private static ProductionIncrease create(int wood, int stone, int clay, int glass) {
+ private static ProductionIncrease create(int wood, int stone, int clay) {
Production production = new Production();
if (wood > 0) {
production.addFixedResource(ResourceType.WOOD, wood);
@@ -41,9 +41,6 @@ public class ProductionIncreaseSerializerTest {
if (clay > 0) {
production.addFixedResource(ResourceType.CLAY, clay);
}
- if (glass > 0) {
- production.addFixedResource(ResourceType.GLASS, glass);
- }
ProductionIncrease prodIncrease = new ProductionIncrease();
prodIncrease.setProduction(production);
return prodIncrease;
@@ -70,25 +67,25 @@ public class ProductionIncreaseSerializerTest {
@Test
public void serialize_singleType() {
- ProductionIncrease prodIncrease = create(1, 0, 0, 0);
+ ProductionIncrease prodIncrease = create(1, 0, 0);
assertEquals("\"W\"", gson.toJson(prodIncrease, ProductionIncrease.class));
}
@Test
public void serialize_multipleTimesSameType() {
- ProductionIncrease prodIncrease = create(3, 0, 0, 0);
+ ProductionIncrease prodIncrease = create(3, 0, 0);
assertEquals("\"WWW\"", gson.toJson(prodIncrease, ProductionIncrease.class));
}
@Test
public void serialize_mixedTypes() {
- ProductionIncrease prodIncrease = create(1, 1, 1, 0);
+ ProductionIncrease prodIncrease = create(1, 1, 1);
assertEquals("\"WSC\"", gson.toJson(prodIncrease, ProductionIncrease.class));
}
@Test
public void serialize_mixedTypesMultiple() {
- ProductionIncrease prodIncrease = create(2, 1, 2, 0);
+ ProductionIncrease prodIncrease = create(2, 1, 2);
assertEquals("\"WWSCC\"", gson.toJson(prodIncrease, ProductionIncrease.class));
}
@@ -125,7 +122,7 @@ public class ProductionIncreaseSerializerTest {
@Test(expected = IllegalArgumentException.class)
public void serialize_failIfMixedFixedAndChoices() {
- ProductionIncrease prodIncrease = create(1, 0, 0, 0);
+ ProductionIncrease prodIncrease = create(1, 0, 0);
prodIncrease.getProduction().addChoice(ResourceType.WOOD, ResourceType.CLAY);
gson.toJson(prodIncrease, ProductionIncrease.class);
}
@@ -153,25 +150,25 @@ public class ProductionIncreaseSerializerTest {
@Test
public void deserialize_singleType() {
- ProductionIncrease prodIncrease = create(1, 0, 0, 0);
+ ProductionIncrease prodIncrease = create(1, 0, 0);
assertEquals(prodIncrease, gson.fromJson("\"W\"", ProductionIncrease.class));
}
@Test
public void deserialize_multipleTimesSameType() {
- ProductionIncrease prodIncrease = create(3, 0, 0, 0);
+ ProductionIncrease prodIncrease = create(3, 0, 0);
assertEquals(prodIncrease, gson.fromJson("\"WWW\"", ProductionIncrease.class));
}
@Test
public void deserialize_mixedTypes() {
- ProductionIncrease prodIncrease = create(1, 1, 1, 0);
+ ProductionIncrease prodIncrease = create(1, 1, 1);
assertEquals(prodIncrease, gson.fromJson("\"WCS\"", ProductionIncrease.class));
}
@Test
public void deserialize_mixedTypes_unordered() {
- ProductionIncrease prodIncrease = create(1, 3, 2, 0);
+ ProductionIncrease prodIncrease = create(1, 3, 2);
assertEquals(prodIncrease, gson.fromJson("\"SCWCSS\"", ProductionIncrease.class));
}
diff --git a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
index 1f2df0ab..f782118d 100644
--- a/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
+++ b/src/test/java/org/luxons/sevenwonders/game/test/TestUtils.java
@@ -41,7 +41,7 @@ public class TestUtils {
for (int i = 0; i < count; i++) {
String userName = "testUser" + i;
String displayName = "Test User " + i;
- Player player = new Player(displayName, userName);
+ Player player = new Player(userName, displayName);
players.add(player);
}
return players;
@@ -53,7 +53,7 @@ public class TestUtils {
String userName = "testUser" + initialResource.getSymbol();
String displayName = "Test User " + initialResource.getSymbol();
- Player player = new Player(displayName, userName);
+ Player player = new Player(userName, displayName);
return new Board(wonder, player, settings);
}
bgstack15