#761 Fix removal and restoration of primary permission group

- Improve how a player is being switched between permission groups (add new group before removing old one)
- Remove group handling logic from LimboCache: AuthGroupHandler is now solely responsible for changing the player's permission group
This commit is contained in:
ljacqu
2017-02-05 13:12:04 +01:00
parent 49f7e47645
commit 2b1a97e959
6 changed files with 78 additions and 84 deletions
@@ -2,9 +2,7 @@ package fr.xephi.authme.data.limbo;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.SpawnLoader;
import fr.xephi.authme.settings.properties.PluginSettings;
import org.bukkit.Location;
import org.bukkit.entity.Player;
import org.junit.Test;
@@ -33,9 +31,6 @@ public class LimboCacheTest {
@InjectMocks
private LimboCache limboCache;
@Mock
private Settings settings;
@Mock
private PermissionsManager permissionsManager;
@@ -118,11 +113,7 @@ public class LimboCacheTest {
given(limboPlayer.isCanFly()).willReturn(true);
float flySpeed = 1.0f;
given(limboPlayer.getFlySpeed()).willReturn(flySpeed);
String group = "primary-group";
given(limboPlayer.getGroup()).willReturn(group);
getCache().put(name.toLowerCase(), limboPlayer);
given(settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)).willReturn(true);
given(permissionsManager.hasGroupSupport()).willReturn(true);
// when
limboCache.restoreData(player);
@@ -132,7 +123,6 @@ public class LimboCacheTest {
verify(player).setWalkSpeed(walkSpeed);
verify(player).setAllowFlight(true);
verify(player).setFlySpeed(flySpeed);
verify(permissionsManager).setGroup(player, group);
verify(limboPlayer).clearTasks();
}
@@ -147,11 +137,7 @@ public class LimboCacheTest {
given(limboPlayer.getWalkSpeed()).willReturn(0f);
given(limboPlayer.isCanFly()).willReturn(true);
given(limboPlayer.getFlySpeed()).willReturn(0f);
String group = "primary-group";
given(limboPlayer.getGroup()).willReturn(group);
getCache().put(name.toLowerCase(), limboPlayer);
given(settings.getProperty(PluginSettings.ENABLE_PERMISSION_CHECK)).willReturn(true);
given(permissionsManager.hasGroupSupport()).willReturn(true);
// when
limboCache.restoreData(player);
@@ -134,13 +134,11 @@ public class CommonServiceTest {
// given
Player player = mock(Player.class);
AuthGroupType type = AuthGroupType.LOGGED_IN;
given(authGroupHandler.setGroup(player, type)).willReturn(true);
// when
boolean result = commonService.setGroup(player, type);
commonService.setGroup(player, type);
// then
verify(authGroupHandler).setGroup(player, type);
assertThat(result, equalTo(true));
}
}