1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-22 18:46:33 +01:00

Fixes bug where database table existed but had no valid data in it.

Fixes https://github.com/BentoBoxWorld/Warps/issues/71
This commit is contained in:
tastybento 2020-04-02 12:54:55 -07:00
parent f3fe87c757
commit 40c0b8d791
2 changed files with 39 additions and 5 deletions

View File

@ -47,6 +47,7 @@ import world.bentobox.warps.objects.WarpsData;
*/ */
public class WarpSignsManager { public class WarpSignsManager {
private static final int MAX_WARPS = 600; private static final int MAX_WARPS = 600;
private static final String WARPS = "warps";
private BentoBox plugin; private BentoBox plugin;
// Map of all warps stored as player, warp sign Location // Map of all warps stored as player, warp sign Location
private Map<World, Map<UUID, Location>> worldsWarpList; private Map<World, Map<UUID, Location>> worldsWarpList;
@ -176,11 +177,11 @@ public class WarpSignsManager {
/** /**
* Load the warps and check if they still exist * Load the warps and check if they still exist
*/ */
private void loadWarpList() { void loadWarpList() {
addon.getLogger().info("Loading warps..."); addon.log("Loading warps...");
worldsWarpList = new HashMap<>(); worldsWarpList = new HashMap<>();
if (handler.objectExists("warps")) { if (handler.objectExists(WARPS)) {
warpsData = handler.loadObject("warps"); warpsData = handler.loadObject(WARPS);
// Load into map // Load into map
if (warpsData != null) { if (warpsData != null) {
warpsData.getWarpSigns().forEach((k,v) -> { warpsData.getWarpSigns().forEach((k,v) -> {
@ -189,6 +190,8 @@ public class WarpSignsManager {
getWarpMap(k.getWorld()).put(v, k); getWarpMap(k.getWorld()).put(v, k);
} }
}); });
} else {
warpsData = new WarpsData();
} }
} }
} }

View File

@ -9,6 +9,7 @@ import static org.mockito.ArgumentMatchers.anyInt;
import static org.mockito.ArgumentMatchers.anyString; import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.ArgumentMatchers.eq; import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.Mockito.mock; import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.times;
import static org.mockito.Mockito.verify; import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when; import static org.mockito.Mockito.when;
@ -289,7 +290,7 @@ public class WarpSignsManagerTest {
*/ */
@Test @Test
public void testWarpSignsManager() throws Exception { public void testWarpSignsManager() throws Exception {
verify(logger).info("Loading warps..."); verify(addon).log("Loading warps...");
verify(load).getWarpSigns(); verify(load).getWarpSigns();
verify(block).getType(); verify(block).getType();
} }
@ -444,4 +445,34 @@ public class WarpSignsManagerTest {
assertFalse(wsm.hasWarp(world, UUID.randomUUID())); assertFalse(wsm.hasWarp(world, UUID.randomUUID()));
} }
/**
* Test method for {@link world.bentobox.warps.WarpSignsManager#loadWarpList()}.
*/
@Test
public void testLoadWarpListNoWarpTable() {
// Run again but with no database table
when(handler.objectExists(anyString())).thenReturn(false);
wsm = new WarpSignsManager(addon, plugin);
// Save
wsm.saveWarpList();
// Default load in constructor check
verify(addon, times(2)).log(eq("Loading warps..."));
assertTrue(wsm.getWarpMap(world).isEmpty());
}
/**
* Test method for {@link world.bentobox.warps.WarpSignsManager#loadWarpList()}.
* @throws Exception
*/
@Test
public void testLoadWarpListEmptyWarpTable() throws Exception {
// Run again but with no data in table
when(handler.loadObject(anyString())).thenReturn(null);
wsm = new WarpSignsManager(addon, plugin);
// Save
wsm.saveWarpList();
// Default load in constructor check
verify(addon, times(2)).log(eq("Loading warps..."));
assertTrue(wsm.getWarpMap(world).isEmpty());
}
} }