### Question:
TeleportationService implements Reloadable { public void teleportOnJoin(final Player player) { if (!settings.getProperty(RestrictionSettings.NO_TELEPORT) && settings.getProperty(TELEPORT_UNAUTHED_TO_SPAWN)) { teleportToSpawn(player, playerCache.isAuthenticated(player.getName())); } } TeleportationService(); @PostConstruct @Override void reload(); void teleportOnJoin(final Player player); Location prepareOnJoinSpawnLocation(final Player player); void teleportNewPlayerToFirstSpawn(final Player player); void teleportOnLogin(final Player player, PlayerAuth auth, LimboPlayer limbo);  }### Answer:
@Test public void shouldNotTeleportPlayerOnJoin() { given(settings.getProperty(RestrictionSettings.NO_TELEPORT)).willReturn(true); Player player = mock(Player.class); teleportationService.teleportOnJoin(player); verifyZeroInteractions(player); verifyZeroInteractions(bukkitService); }
@Test public void shouldTeleportPlayerToSpawn() { given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true); Player player = mock(Player.class); given(player.isOnline()).willReturn(true); Location spawn = mockLocation(); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); teleportationService.teleportOnJoin(player); verify(player).teleport(spawn); verify(bukkitService).callEvent(any(SpawnTeleportEvent.class)); verify(spawnLoader).getSpawnLocation(player); }
@Test public void shouldNotTeleportPlayerForRemovedLocationInEvent() { final Player player = mock(Player.class); Location spawn = mockLocation(); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true); doAnswer(invocation -> { SpawnTeleportEvent event = (SpawnTeleportEvent) invocation.getArguments()[0]; assertThat(event.getPlayer(), equalTo(player)); event.setTo(null); return null; }).when(bukkitService).callEvent(any(SpawnTeleportEvent.class)); setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); teleportationService.teleportOnJoin(player); verify(bukkitService).callEvent(any(SpawnTeleportEvent.class)); verify(player, never()).teleport(any(Location.class)); }
@Test public void shouldNotTeleportPlayerForCanceledEvent() { final Player player = mock(Player.class); Location spawn = mockLocation(); given(spawnLoader.getSpawnLocation(player)).willReturn(spawn); given(settings.getProperty(RestrictionSettings.TELEPORT_UNAUTHED_TO_SPAWN)).willReturn(true); doAnswer(invocation -> { SpawnTeleportEvent event = (SpawnTeleportEvent) invocation.getArguments()[0]; assertThat(event.getPlayer(), equalTo(player)); event.setCancelled(true); return null; }).when(bukkitService).callEvent(any(SpawnTeleportEvent.class)); setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService); teleportationService.teleportOnJoin(player); verify(bukkitService).callEvent(any(SpawnTeleportEvent.class)); verify(player, never()).teleport(any(Location.class)); }