use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class DistributedFilesPersistenceHandlerTest method shouldHandleReadErrorGracefully.
@Test
public void shouldHandleReadErrorGracefully() throws IOException {
// given
// assumption
File invalidFile = new File(playerDataFolder, "seg16-4-limbo.json");
assertThat(invalidFile.exists(), equalTo(false));
Files.write("not valid json".getBytes(), invalidFile);
// when
LimboPlayer result = persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UNKNOWN_UUID));
// then
assertThat(result, nullValue());
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class DistributedFilesPersistenceHandlerTest method shouldAddPlayer.
@Test
public void shouldAddPlayer() {
// given
Player uuidToAdd1 = mockPlayerWithUuid(UNKNOWN_UUID);
Location location1 = new Location(mockWorldWithName("1world"), 120, 60, -80, 0.42345f, 120.32f);
LimboPlayer limbo1 = new LimboPlayer(location1, false, "group-1", true, 0.1f, 0.2f);
Player uuidToAdd2 = mockPlayerWithUuid(UNKNOWN_UUID2);
Location location2 = new Location(mockWorldWithName("2world"), -40, 20, 33, 4.235f, 8.32299f);
LimboPlayer limbo2 = new LimboPlayer(location2, true, "", false, 0.0f, 0.25f);
// when
persistenceHandler.saveLimboPlayer(uuidToAdd1, limbo1);
persistenceHandler.saveLimboPlayer(uuidToAdd2, limbo2);
// then
LimboPlayer addedPlayer1 = persistenceHandler.getLimboPlayer(uuidToAdd1);
assertThat(addedPlayer1, isLimbo(limbo1));
assertThat(addedPlayer1, hasLocation(location1));
LimboPlayer addedPlayer2 = persistenceHandler.getLimboPlayer(uuidToAdd2);
assertThat(addedPlayer2, isLimbo(limbo2));
assertThat(addedPlayer2, hasLocation(location2));
assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(MIGRATED_UUID)), MIGRATED_LIMBO_MATCHER);
assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_FAB69)), FAB69_MATCHER);
assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_STAFF)), STAFF_MATCHER);
assertThat(persistenceHandler.getLimboPlayer(mockPlayerWithUuid(UUID_8C679)), SC679_MATCHER);
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class IndividualFilesPersistenceHandlerTest method shouldReadDataFromFile.
@Test
public void shouldReadDataFromFile() {
// given
Player player = mock(Player.class);
given(player.getUniqueId()).willReturn(SAMPLE_UUID);
World world = mock(World.class);
given(bukkitService.getWorld("nether")).willReturn(world);
// when
LimboPlayer data = handler.getLimboPlayer(player);
// then
assertThat(data, not(nullValue()));
assertThat(data.isOperator(), equalTo(true));
assertThat(data.isCanFly(), equalTo(true));
assertThat(data.getWalkSpeed(), equalTo(0.2f));
assertThat(data.getFlySpeed(), equalTo(0.1f));
assertThat(data.getGroup(), equalTo("players"));
Location location = data.getLocation();
assertThat(location.getX(), equalTo(-113.219));
assertThat(location.getY(), equalTo(72.0));
assertThat(location.getZ(), equalTo(130.637));
assertThat(location.getWorld(), equalTo(world));
assertThat(location.getPitch(), equalTo(24.15f));
assertThat(location.getYaw(), equalTo(-292.484f));
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class LimboPersistenceTest method shouldHandleExceptionWhenGettingLimbo.
@Test
public void shouldHandleExceptionWhenGettingLimbo() {
// given
Player player = mock(Player.class);
Logger logger = TestHelper.setupLogger();
LimboPersistenceHandler handler = getHandler();
doThrow(IllegalAccessException.class).when(handler).getLimboPlayer(player);
// when
LimboPlayer result = limboPersistence.getLimboPlayer(player);
// then
assertThat(result, nullValue());
verify(logger).warning(argThat(containsString("[IllegalAccessException]")));
}
use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.
the class LimboPersistenceTest method shouldHandleExceptionWhenSavingLimbo.
@Test
public void shouldHandleExceptionWhenSavingLimbo() {
// given
Player player = mock(Player.class);
LimboPlayer limbo = mock(LimboPlayer.class);
Logger logger = TestHelper.setupLogger();
LimboPersistenceHandler handler = getHandler();
doThrow(IllegalStateException.class).when(handler).saveLimboPlayer(player, limbo);
// when
limboPersistence.saveLimboPlayer(player, limbo);
// then
verify(logger).warning(argThat(containsString("[IllegalStateException]")));
}
Aggregations