1
0
mirror of https://github.com/BentoBoxWorld/Warps.git synced 2024-11-13 06:14:21 +01:00

Fixes tests

This commit is contained in:
tastybento 2020-06-02 14:34:21 -07:00
parent 6d4b7c2a19
commit 8f38353b73
4 changed files with 14 additions and 17 deletions

View File

@ -59,7 +59,7 @@
<powermock.version>2.0.2</powermock.version>
<!-- More visible way how to change dependency versions -->
<spigot.version>1.14.4-R0.1-SNAPSHOT</spigot.version>
<bentobox.version>1.13.1</bentobox.version>
<bentobox.version>1.14.0-SNAPSHOT</bentobox.version>
<level.version>1.5.0</level.version>
<!-- Revision variable removes warning about dynamic version -->
<revision>${build.version}-SNAPSHOT</revision>

View File

@ -257,7 +257,7 @@ public class WarpSignsManager {
* Saves the warp lists to the database
*/
public void saveWarpList() {
handler.saveObject(warpsData.save(worldsWarpList));
handler.saveObjectAsync(warpsData.save(worldsWarpList));
addon.getWarpPanelManager().saveCache();
}

View File

@ -21,6 +21,7 @@ import java.util.UUID;
import java.util.logging.Logger;
import org.bukkit.Bukkit;
import org.bukkit.ChatColor;
import org.bukkit.Location;
import org.bukkit.Material;
import org.bukkit.OfflinePlayer;
@ -67,7 +68,7 @@ import world.bentobox.warps.objects.WarpsData;
*
*/
@RunWith(PowerMockRunner.class)
@PrepareForTest({Bukkit.class, Util.class, DatabaseSetup.class})
@PrepareForTest({Bukkit.class, Util.class, DatabaseSetup.class, ChatColor.class})
public class WarpSignsManagerTest {
@Mock
@ -135,11 +136,12 @@ public class WarpSignsManagerTest {
// Player
when(player.getUniqueId()).thenReturn(uuid);
User.setPlugin(plugin);
User.getInstance(player);
// Locales
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(Mockito.any(), Mockito.any())).thenAnswer((Answer<String>) invocation -> invocation.getArgument(1, String.class));
when(lm.get(Mockito.any(), Mockito.any())).thenReturn(null);
when(plugin.getLocalesManager()).thenReturn(lm);
// Return the same string
PlaceholdersManager phm = mock(PlaceholdersManager.class);

View File

@ -5,12 +5,12 @@ import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyString;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
import static org.mockito.Mockito.any;
import static org.mockito.Mockito.anyString;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
import java.util.HashMap;
import java.util.Map;
@ -37,7 +37,6 @@ import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.Mockito;
import org.mockito.invocation.InvocationOnMock;
import org.mockito.stubbing.Answer;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
@ -53,7 +52,6 @@ import world.bentobox.bentobox.util.Util;
import world.bentobox.warps.Warp;
import world.bentobox.warps.WarpSignsManager;
import world.bentobox.warps.config.Settings;
import world.bentobox.warps.listeners.WarpSignsListener;
/**
* @author tastybento
@ -140,12 +138,7 @@ public class WarpSignsListenerTest {
when(addon.getPlugin()).thenReturn(plugin);
User.setPlugin(plugin);
LocalesManager lm = mock(LocalesManager.class);
when(lm.get(any(), any())).thenAnswer(new Answer<String>(){
@Override
public String answer(InvocationOnMock invocation) throws Throwable {
return invocation.getArgument(1, String.class);
}});
when(lm.get(any(), any())).thenReturn(null);
when(plugin.getLocalesManager()).thenReturn(lm);
// Lines
@ -167,12 +160,14 @@ public class WarpSignsListenerTest {
when(iwm.getAddon(any())).thenReturn(Optional.empty());
when(iwm.inWorld(any(World.class))).thenReturn(true);
Answer<String> answer = invocation -> invocation.getArgument(1, String.class);
// Util
PowerMockito.mockStatic(Util.class);
when(Util.getWorld(any())).thenReturn(world);
when(Util.stripSpaceAfterColorCodes(anyString())).thenAnswer(invocation -> invocation.getArgument(0, String.class));
// Locales
Answer<String> answer = invocation -> invocation.getArgument(1, String.class);
when(lm.get(any(User.class), anyString())).thenAnswer(answer);
when(plugin.getLocalesManager()).thenReturn(lm);