Fixed tests.

This commit is contained in:
tastybento 2018-05-25 17:58:07 -07:00
parent 74c86901d0
commit 35b715ff80
7 changed files with 49 additions and 11 deletions

View File

@ -133,12 +133,7 @@ public class User {
}
public String getName() {
player = Bukkit.getPlayer(playerUUID);
if (player != null) {
return player.getName();
}
// Try and get name from database
return plugin.getPlayers().getName(playerUUID);
return player != null ? player.getName() : plugin.getPlayers().getName(playerUUID);
}
/**

View File

@ -63,7 +63,7 @@ public class AdminTeamAddCommand extends CompositeCommand {
// Success
User target = User.getInstance(targetUUID);
User leader = User.getInstance(leaderUUID);
leader.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", target.getName());
leader.sendMessage("commands.island.team.invite.accept.name-joined-your-island", "[name]", getPlugin().getPlayers().getName(targetUUID));
target.sendMessage("commands.island.team.invite.accept.you-joined-island", "[label]", Constants.ISLANDCOMMAND);
getIslands().getIsland(world, leaderUUID).addMember(targetUUID);
user.sendMessage("general.success");

View File

@ -56,7 +56,10 @@ public class Players implements DataObject {
locale = "";
kickedList = new HashMap<>();
// Try to get player's name
this.playerName = Bukkit.getOfflinePlayer(uniqueId).getName();
this.playerName = Bukkit.getServer().getOfflinePlayer(uniqueId).getName();
if (this.playerName == null) {
this.playerName = uniqueId.toString();
}
}
/**

View File

@ -292,6 +292,10 @@ public class AdminTeamAddCommandTest {
Island island = mock(Island.class);
when(im.getIsland(Mockito.any(), Mockito.eq(uuid))).thenReturn(island);
// Player name
when(pm.getName(Mockito.eq(uuid))).thenReturn("tastybento");
when(pm.getName(Mockito.eq(notUUID))).thenReturn("poslovich");
when(plugin.getPlayers()).thenReturn(pm);
// Success
assertTrue(itl.execute(user, Arrays.asList(name)));

View File

@ -11,10 +11,14 @@ import java.util.UUID;
import org.bukkit.Bukkit;
import org.bukkit.Location;
import org.bukkit.OfflinePlayer;
import org.bukkit.Server;
import org.bukkit.World;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.Mockito;
import org.powermock.api.mockito.PowerMockito;
import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
import org.powermock.reflect.Whitebox;
@ -40,6 +44,14 @@ public class PlayersTest {
when(s.getResetLimit()).thenReturn(3);
when(s.getDeathsMax()).thenReturn(3);
when(plugin.getSettings()).thenReturn(s);
Server server = mock(Server.class);
PowerMockito.mockStatic(Bukkit.class);
when(Bukkit.getServer()).thenReturn(server);
OfflinePlayer olp = mock(OfflinePlayer.class);
when(olp.getName()).thenReturn("tasty");
when(server.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
}
private BSkyBlock plugin;

View File

@ -49,6 +49,7 @@ import us.tastybento.bskyblock.managers.FlagsManager;
import us.tastybento.bskyblock.managers.IslandWorldManager;
import us.tastybento.bskyblock.managers.IslandsManager;
import us.tastybento.bskyblock.managers.LocalesManager;
import us.tastybento.bskyblock.managers.PlayersManager;
import us.tastybento.bskyblock.util.Util;
@RunWith(PowerMockRunner.class)
@ -128,12 +129,17 @@ public class FireListenerTest {
///user.setPlugin(plugin);
User.setPlugin(plugin);
// Locales - final
LocalesManager lm = mock(LocalesManager.class);
when(plugin.getLocalesManager()).thenReturn(lm);
when(lm.get(any(), any())).thenReturn("mock translation");
// Player name
PlayersManager pm = mock(PlayersManager.class);
when(pm.getName(Mockito.any())).thenReturn("tastybento");
when(plugin.getPlayers()).thenReturn(pm);
}
@Test

View File

@ -185,7 +185,7 @@ public class PlayersManagerTest {
when(olp.getName()).thenReturn("tasty");
when(server.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
Players player = pm.getPlayer(uuid);
assertEquals(uuid.toString(), player.getPlayerName());
assertEquals("tasty", player.getPlayerName());
assertEquals(uuid.toString(), player.getUniqueId());
}
@ -358,9 +358,15 @@ public class PlayersManagerTest {
@Test
public void testSetandGetPlayerName() {
PlayersManager pm = new PlayersManager(plugin);
Server server = mock(Server.class);
when(Bukkit.getServer()).thenReturn(server);
OfflinePlayer olp = mock(OfflinePlayer.class);
when(olp.getName()).thenReturn("tasty");
when(server.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
// Add a player
pm.addPlayer(uuid);
assertEquals(uuid.toString(), pm.getName(user.getUniqueId()));
assertEquals("tasty", pm.getName(user.getUniqueId()));
pm.setPlayerName(user);
assertEquals(user.getName(), pm.getName(user.getUniqueId()));
}
@ -371,6 +377,12 @@ public class PlayersManagerTest {
@Test
public void testGetSetResetsLeft() {
PlayersManager pm = new PlayersManager(plugin);
Server server = mock(Server.class);
when(Bukkit.getServer()).thenReturn(server);
OfflinePlayer olp = mock(OfflinePlayer.class);
when(olp.getName()).thenReturn("tasty");
when(server.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
// Add a player
pm.addPlayer(uuid);
assertEquals(0, pm.getResetsLeft(uuid));
@ -384,6 +396,12 @@ public class PlayersManagerTest {
@Test
public void testSaveUUID() {
PlayersManager pm = new PlayersManager(plugin);
Server server = mock(Server.class);
when(Bukkit.getServer()).thenReturn(server);
OfflinePlayer olp = mock(OfflinePlayer.class);
when(olp.getName()).thenReturn("tasty");
when(server.getOfflinePlayer(Mockito.any(UUID.class))).thenReturn(olp);
// Add a player
pm.addPlayer(uuid);
pm.save(uuid);