Search in sources :

Example 26 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class DebugSectionUtilsTest method shouldFetchMapInLimboService.

@Test
public void shouldFetchMapInLimboService() {
    // given
    LimboService limboService = mock(LimboService.class);
    Map<String, LimboPlayer> limboMap = new HashMap<>();
    ReflectionTestUtils.setField(LimboService.class, limboService, "entries", limboMap);
    // when
    Map map = DebugSectionUtils.applyToLimboPlayersMap(limboService, Function.identity());
    // then
    assertThat(map, sameInstance(limboMap));
}
Also used : HashMap(java.util.HashMap) LimboService(fr.xephi.authme.data.limbo.LimboService) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) HashMap(java.util.HashMap) Map(java.util.Map) Test(org.junit.Test)

Example 27 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class IndividualFilesPersistenceHandlerTest method shouldReturnNullForUnavailablePlayer.

@Test
public void shouldReturnNullForUnavailablePlayer() {
    // given
    Player player = mock(Player.class);
    given(player.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("other-player".getBytes()));
    // when
    LimboPlayer data = handler.getLimboPlayer(player);
    // then
    assertThat(data, nullValue());
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Test(org.junit.Test)

Example 28 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class IndividualFilesPersistenceHandlerTest method shouldSavePlayerData.

@Test
public void shouldSavePlayerData() {
    // given
    Player player = mock(Player.class);
    UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes());
    given(player.getUniqueId()).willReturn(uuid);
    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);
    LimboPlayer limbo = new LimboPlayer(location, true, Collections.singletonList(new UserGroup("primary-grp")), true, 1.2f, 0.8f);
    // when
    handler.saveLimboPlayer(player, limbo);
    // 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
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) UUID(java.util.UUID) World(org.bukkit.World) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) File(java.io.File) Location(org.bukkit.Location) UserGroup(fr.xephi.authme.data.limbo.UserGroup) Test(org.junit.Test)

Example 29 with LimboPlayer

use of fr.xephi.authme.data.limbo.LimboPlayer in project AuthMeReloaded by AuthMe.

the class LimboPersistenceTest method shouldDelegateToHandler.

@Test
public void shouldDelegateToHandler() {
    // given
    Player player = mock(Player.class);
    LimboPersistenceHandler handler = getHandler();
    LimboPlayer limbo = mock(LimboPlayer.class);
    given(handler.getLimboPlayer(player)).willReturn(limbo);
    // when
    LimboPlayer result = limboPersistence.getLimboPlayer(player);
    limboPersistence.saveLimboPlayer(player, mock(LimboPlayer.class));
    limboPersistence.removeLimboPlayer(mock(Player.class));
    // then
    assertThat(result, equalTo(limbo));
    verify(handler).getLimboPlayer(player);
    verify(handler).saveLimboPlayer(eq(player), argThat(notNullAndDifferentFrom(limbo)));
    verify(handler).removeLimboPlayer(argThat(notNullAndDifferentFrom(player)));
}
Also used : Player(org.bukkit.entity.Player) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) LimboPlayer(fr.xephi.authme.data.limbo.LimboPlayer) Test(org.junit.Test)

Aggregations

LimboPlayer (fr.xephi.authme.data.limbo.LimboPlayer)29 Test (org.junit.Test)18 Player (org.bukkit.entity.Player)16 PlayerAuth (fr.xephi.authme.data.auth.PlayerAuth)11 Location (org.bukkit.Location)11 File (java.io.File)7 UserGroup (fr.xephi.authme.data.limbo.UserGroup)4 HashMap (java.util.HashMap)4 World (org.bukkit.World)4 LimboService (fr.xephi.authme.data.limbo.LimboService)3 Map (java.util.Map)3 JsonObject (com.google.gson.JsonObject)2 LoginEvent (fr.xephi.authme.events.LoginEvent)2 List (java.util.List)2 Logger (java.util.logging.Logger)2 Gson (com.google.gson.Gson)1 JsonArray (com.google.gson.JsonArray)1 JsonElement (com.google.gson.JsonElement)1 JsonSerializationContext (com.google.gson.JsonSerializationContext)1 JsonSerializer (com.google.gson.JsonSerializer)1