From 75ccecce02a2bfc85f7fb5234fc834ea4a75fbe2 Mon Sep 17 00:00:00 2001 From: Rsl1122 Date: Mon, 21 Aug 2017 18:55:07 +0300 Subject: [PATCH] Fixed WorldTimes, now works as intended. --- .../djrapitops/plan/data/time/WorldTimes.java | 14 +++-- .../plan/data/time/WorldTimesTest.java | 55 ++++++++++--------- 2 files changed, 36 insertions(+), 33 deletions(-) diff --git a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java index bdeb603eb..ff9dc61a8 100644 --- a/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java +++ b/Plan/src/main/java/com/djrapitops/plan/data/time/WorldTimes.java @@ -43,16 +43,18 @@ public class WorldTimes { public void updateState(String worldName, String gameMode, long changeTime) { GMTimes currentGMTimes = worldTimes.get(currentWorld); - - GMTimes newGMTimes = worldTimes.get(worldName); - if (newGMTimes == null) { - addWorld(worldName, gameMode, currentGMTimes.getLastStateChange()); + if (worldName.equals(currentWorld)) { + currentGMTimes.changeState(gameMode, changeTime); + } else { + GMTimes newGMTimes = worldTimes.get(worldName); + if (newGMTimes == null) { + addWorld(worldName, gameMode, currentGMTimes.getLastStateChange()); + } + currentGMTimes.changeState(currentGamemode, changeTime); } - currentGMTimes.changeState(gameMode, changeTime); for (GMTimes gmTimes : worldTimes.values()) { gmTimes.setLastStateChange(changeTime); } - worldTimes.put(currentWorld, currentGMTimes); currentWorld = worldName; currentGamemode = gameMode; } diff --git a/Plan/test/test/java/main/java/com/djrapitops/plan/data/time/WorldTimesTest.java b/Plan/test/test/java/main/java/com/djrapitops/plan/data/time/WorldTimesTest.java index 2332b7677..d3a7667bd 100644 --- a/Plan/test/test/java/main/java/com/djrapitops/plan/data/time/WorldTimesTest.java +++ b/Plan/test/test/java/main/java/com/djrapitops/plan/data/time/WorldTimesTest.java @@ -9,7 +9,6 @@ import test.java.utils.RandomData; import java.util.*; import static org.junit.Assert.assertEquals; -import static org.junit.Assert.assertTrue; /** * @author Rsl1122 @@ -121,12 +120,12 @@ public class WorldTimesTest { long changeTime2 = changeTime + 1000L; GMTimes gmTimes = test.getGMTimes(worldOne).get(); test.updateState(worldOne, "CREATIVE", changeTime); - assertTrue(1000L == gmTimes.getTime("SURVIVAL")); - assertTrue(0L == gmTimes.getTime("CREATIVE")); + assertEquals(1000L, gmTimes.getTime("SURVIVAL")); + assertEquals(0L, gmTimes.getTime("CREATIVE")); test.updateState(worldOne, "ADVENTURE", changeTime2); - assertTrue(1000L == gmTimes.getTime("SURVIVAL")); - assertTrue(1000L == gmTimes.getTime("CREATIVE")); - assertTrue(0L == gmTimes.getTime("ADVENTURE")); + assertEquals(1000L, gmTimes.getTime("SURVIVAL")); + assertEquals(1000L, gmTimes.getTime("CREATIVE")); + assertEquals(0L, gmTimes.getTime("ADVENTURE")); } @Test @@ -136,46 +135,48 @@ public class WorldTimesTest { GMTimes worldOneGMTimes = test.getGMTimes(worldOne).get(); test.updateState(worldOne, "CREATIVE", changeTime); test.updateState(worldOne, "ADVENTURE", changeTime2); - // Same state as above. + assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL")); + assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE")); + assertEquals(0L, worldOneGMTimes.getTime("ADVENTURE")); test.updateState(worldTwo, "SURVIVAL", time + 3000L); - assertTrue(1000L == worldOneGMTimes.getTime("SURVIVAL")); - assertTrue(1000L == worldOneGMTimes.getTime("CREATIVE")); - assertTrue(1000L == worldOneGMTimes.getTime("ADVENTURE")); - GMTimes worldTwoGMTimes = test.getGMTimes(worldTwo).get(); + assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL")); + assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE")); + assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE")); - assertTrue(0L == worldTwoGMTimes.getTime("SURVIVAL")); - assertTrue(0L == worldTwoGMTimes.getTime("CREATIVE")); - assertTrue(0L == worldTwoGMTimes.getTime("ADVENTURE")); + assertEquals(0L, worldTwoGMTimes.getTime("SURVIVAL")); + assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE")); + assertEquals(0L, worldTwoGMTimes.getTime("ADVENTURE")); test.updateState(worldTwo, "CREATIVE", time + 4000L); - assertTrue(1000L == worldOneGMTimes.getTime("SURVIVAL")); - assertTrue(1000L == worldOneGMTimes.getTime("CREATIVE")); - assertTrue(1000L == worldOneGMTimes.getTime("ADVENTURE")); + assertEquals(1000L, worldOneGMTimes.getTime("SURVIVAL")); + assertEquals(1000L, worldOneGMTimes.getTime("CREATIVE")); + assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE")); - assertTrue(1000L == worldTwoGMTimes.getTime("SURVIVAL")); - assertTrue(0L == worldTwoGMTimes.getTime("CREATIVE")); + assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL")); + assertEquals(0L, worldTwoGMTimes.getTime("CREATIVE")); test.updateState(worldTwo, "CREATIVE", time + 5000L); - assertTrue(1000L == worldTwoGMTimes.getTime("SURVIVAL")); - assertTrue(1000L == worldTwoGMTimes.getTime("CREATIVE")); + assertEquals(1000L, worldTwoGMTimes.getTime("SURVIVAL")); + assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE")); // No change should occur. test.updateState(worldOne, "ADVENTURE", time + 5000L); - assertTrue(1000L == worldOneGMTimes.getTime("ADVENTURE")); - assertTrue(1000L == worldTwoGMTimes.getTime("CREATIVE")); + System.out.println(test); + assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE")); + assertEquals(1000L, worldTwoGMTimes.getTime("CREATIVE")); test.updateState(worldTwo, "CREATIVE", time + 5000L); System.out.println(test); test.updateState(worldOne, "ADVENTURE", time + 6000L); System.out.println(test); - assertTrue(1000L == worldOneGMTimes.getTime("ADVENTURE")); - assertTrue(2000L == worldTwoGMTimes.getTime("CREATIVE")); + assertEquals(1000L, worldOneGMTimes.getTime("ADVENTURE")); + assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE")); test.updateState(worldTwo, "ADVENTURE", time + 7000L); - assertTrue(2000L == worldTwoGMTimes.getTime("CREATIVE")); - assertTrue(2000L == worldOneGMTimes.getTime("ADVENTURE")); + assertEquals(2000L, worldTwoGMTimes.getTime("CREATIVE")); + assertEquals(2000L, worldOneGMTimes.getTime("ADVENTURE")); } // TODO Test where SessionData is ended, check if worldTimes & session length add up.