Fix unit tests

This commit is contained in:
ljacqu 2016-08-04 18:25:43 +02:00
parent f0dfd85903
commit 3534f680f7
3 changed files with 5 additions and 42 deletions

View File

@ -65,14 +65,12 @@ public class TeleportationService implements Reloadable {
* as fast as possible (cf. <a href="https://github.com/Xephi/AuthMeReloaded/issues/682">AuthMe #682</a>).
*
* @param player the player to process
* @see <a href="https://bukkit.atlassian.net/browse/BUKKIT-3521">BUKKIT-3521: Player.hasPlayedBefore() always false</a>
* @see <a href="https://bukkit.atlassian.net/browse/BUKKIT-3521">BUKKIT-3521: Player.hasPlayedBefore()
* always false</a>
*/
public void teleportOnJoin(final Player player) {
if (settings.getProperty(RestrictionSettings.NO_TELEPORT)) {
return;
}
if (settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
if (!settings.getProperty(RestrictionSettings.NO_TELEPORT)
&& settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) {
teleportToSpawn(player, playerCache.isAuthenticated(player.getName()));
}
}

View File

@ -23,7 +23,6 @@ import org.mockito.stubbing.Answer;
import java.util.Arrays;
import static fr.xephi.authme.TestHelper.runSyncDelayedTask;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.BDDMockito.given;
@ -94,7 +93,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportNewPlayerToFirstSpawn(player);
runSyncDelayedTask(bukkitService);
// then
verify(player).teleport(firstSpawn);
@ -114,7 +112,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then
verify(player).teleport(spawn);
@ -174,31 +171,6 @@ public class TeleportationServiceTest {
verifyZeroInteractions(bukkitService);
}
@Test
public void shouldTeleportPlayerDueToForcedWorld() {
// given
Player player = mock(Player.class);
given(player.isOnline()).willReturn(true);
World playerWorld = mock(World.class);
given(playerWorld.getName()).willReturn("OtherForced");
given(player.getWorld()).willReturn(playerWorld);
given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(false);
given(settings.getProperty(RestrictionSettings.FORCE_SPAWN_LOCATION_AFTER_LOGIN)).willReturn(true);
Location spawn = mockLocation();
given(spawnLoader.getSpawnLocation(player)).willReturn(spawn);
// when
teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then
verify(player).teleport(spawn);
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
verify(spawnLoader).getSpawnLocation(player);
}
@Test
public void shouldNotTeleportPlayerForRemovedLocationInEvent() {
// given
@ -218,7 +190,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
@ -244,7 +215,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnJoin(player);
runSyncDelayedTask(bukkitService);
// then
verify(bukkitService).callEvent(any(SpawnTeleportEvent.class));
@ -285,7 +255,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then
verify(player).teleport(spawn);
@ -335,7 +304,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
@ -364,7 +332,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then
ArgumentCaptor<Location> locationCaptor = ArgumentCaptor.forClass(Location.class);
@ -392,7 +359,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then
verify(player).teleport(location);
@ -417,7 +383,6 @@ public class TeleportationServiceTest {
// when
teleportationService.teleportOnLogin(player, auth, limbo);
runSyncDelayedTask(bukkitService);
// then
verify(player).teleport(location);

View File

@ -80,7 +80,7 @@ public class UtilsTest {
public void shouldFallbackToName() {
// given
Player player = mock(Player.class);
doThrow(RuntimeException.class).when(player).getUniqueId();
doThrow(NoSuchMethodError.class).when(player).getUniqueId();
String name = "Bobby12";
given(player.getName()).willReturn(name);