#1169 Create UnregisterEvent

This commit is contained in:
ljacqu
2017-04-29 15:22:27 +02:00
parent d65556d893
commit b652d89088
5 changed files with 162 additions and 2 deletions
@@ -5,6 +5,7 @@ import fr.xephi.authme.data.auth.PlayerAuth;
import fr.xephi.authme.data.auth.PlayerCache;
import fr.xephi.authme.data.limbo.LimboService;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.events.AbstractUnregisterEvent;
import fr.xephi.authme.message.MessageKey;
import fr.xephi.authme.permission.AuthGroupHandler;
import fr.xephi.authme.permission.AuthGroupType;
@@ -19,10 +20,15 @@ import org.bukkit.entity.Player;
import org.junit.BeforeClass;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.mockito.ArgumentCaptor;
import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import java.util.function.Function;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -81,7 +87,7 @@ public class AsynchronousUnregisterTest {
// then
verify(service).send(player, MessageKey.WRONG_PASSWORD);
verify(passwordSecurity).comparePassword(userPassword, password, name);
verifyZeroInteractions(dataSource, limboService, authGroupHandler, teleportationService);
verifyZeroInteractions(dataSource, limboService, authGroupHandler, teleportationService, bukkitService);
verify(player, only()).getName();
}
@@ -112,6 +118,7 @@ public class AsynchronousUnregisterTest {
verify(teleportationService).teleportOnJoin(player);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
}
@Test
@@ -141,6 +148,7 @@ public class AsynchronousUnregisterTest {
verify(teleportationService).teleportOnJoin(player);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
}
@Test
@@ -169,6 +177,7 @@ public class AsynchronousUnregisterTest {
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verifyZeroInteractions(teleportationService, limboService);
verify(bukkitService, never()).runTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
}
@Test
@@ -218,6 +227,7 @@ public class AsynchronousUnregisterTest {
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verifyZeroInteractions(teleportationService, authGroupHandler);
verifyCalledUnregisterEventFor(player);
}
// Initiator known and Player object available
@@ -242,6 +252,7 @@ public class AsynchronousUnregisterTest {
verify(teleportationService).teleportOnJoin(player);
verify(authGroupHandler).setGroup(player, AuthGroupType.UNREGISTERED);
verify(bukkitService).scheduleSyncTaskFromOptionallyAsyncTask(any(Runnable.class));
verifyCalledUnregisterEventFor(player);
}
@Test
@@ -257,6 +268,7 @@ public class AsynchronousUnregisterTest {
verify(dataSource).removeAuth(name);
verify(playerCache).removePlayer(name);
verifyZeroInteractions(authGroupHandler, teleportationService);
verifyCalledUnregisterEventFor(null);
}
@Test
@@ -272,6 +284,15 @@ public class AsynchronousUnregisterTest {
// then
verify(dataSource).removeAuth(name);
verify(service).send(initiator, MessageKey.ERROR);
verifyZeroInteractions(playerCache, teleportationService, authGroupHandler);
verifyZeroInteractions(playerCache, teleportationService, authGroupHandler, bukkitService);
}
@SuppressWarnings("unchecked")
private void verifyCalledUnregisterEventFor(Player player) {
ArgumentCaptor<Function<Boolean, AbstractUnregisterEvent>> eventFunctionCaptor =
ArgumentCaptor.forClass(Function.class);
verify(bukkitService).createAndCallEvent(eventFunctionCaptor.capture());
AbstractUnregisterEvent event = eventFunctionCaptor.getValue().apply(true);
assertThat(event.getPlayer(), equalTo(player));
}
}