@Test public void shouldSavePlayerData() { // given Player player = mock(Player.class); UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes()); given(player.getUniqueId()).willReturn(uuid); given(permissionsManager.getPrimaryGroup(player)).willReturn("primary-grp"); given(player.isOp()).willReturn(true); given(player.getWalkSpeed()).willReturn(1.2f); given(player.getFlySpeed()).willReturn(0.8f); given(player.getAllowFlight()).willReturn(true); World world = mock(World.class); given(world.getName()).willReturn("player-world"); Location location = new Location(world, 0.2, 102.25, -89.28, 3.02f, 90.13f); given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(location); // when limboPlayerStorage.saveData(player); // then File playerFile = new File(dataFolder, FileUtils.makePath("playerdata", uuid.toString(), "data.json")); assertThat(playerFile.exists(), equalTo(true)); // TODO ljacqu 20160711: Check contents of file }
@Override public void runCommand(Player player, List<String> arguments) { if (spawnLoader.setFirstSpawn(player.getLocation())) { player.sendMessage("[AuthMe] Correctly defined new first spawn point"); } else { player.sendMessage("[AuthMe] SetFirstSpawn has failed, please retry"); } }
@Test public void shouldHandleMissingFirstSpawn() { // given given(spawnLoader.getFirstSpawn()).willReturn(null); Player player = mock(Player.class); // when command.executeCommand(player, Collections.<String>emptyList()); // then verify(player).sendMessage(argThat(containsString("spawn has failed"))); verify(player, never()).teleport(any(Location.class)); }
@Test public void shouldTeleportToFirstSpawn() { // given Location firstSpawn = mock(Location.class); given(spawnLoader.getFirstSpawn()).willReturn(firstSpawn); Player player = mock(Player.class); // when command.executeCommand(player, Collections.<String>emptyList()); // then verify(player).teleport(firstSpawn); verify(spawnLoader, atLeastOnce()).getFirstSpawn(); }