diff --git a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java index d57581ff5..5ddd0b951 100644 --- a/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java +++ b/src/main/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommand.java @@ -63,13 +63,12 @@ public class RegisterAdminCommand implements ExecutableCommand { commandService.send(sender, MessageKey.REGISTER_SUCCESS); ConsoleLogger.info(sender.getName() + " registered " + playerName); - Player player = commandService.getPlayer(playerName); + final Player player = commandService.getPlayer(playerName); if (player != null) { - final Player p = player; - p.getServer().getScheduler().scheduleSyncDelayedTask(commandService.getAuthMe(), new Runnable() { + commandService.getBukkitService().scheduleSyncDelayedTask(new Runnable() { @Override public void run() { - p.kickPlayer("An admin just registered you, please log in again"); + player.kickPlayer("An admin just registered you, please log in again"); } }); } diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java index 89fc3da61..47f4de1bf 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/RegisterAdminCommandTest.java @@ -7,7 +7,9 @@ import fr.xephi.authme.datasource.DataSource; import fr.xephi.authme.output.MessageKey; import fr.xephi.authme.security.PasswordSecurity; import fr.xephi.authme.security.crypts.HashedPassword; +import fr.xephi.authme.util.BukkitService; import org.bukkit.command.CommandSender; +import org.bukkit.entity.Player; import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; @@ -18,10 +20,13 @@ import org.mockito.runners.MockitoJUnitRunner; import java.util.Arrays; +import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; import static org.mockito.Matchers.any; +import static org.mockito.Matchers.argThat; +import static org.mockito.Mockito.mock; import static org.mockito.Mockito.never; import static org.mockito.Mockito.verify; @@ -143,10 +148,15 @@ public class RegisterAdminCommandTest { given(dataSource.saveAuth(any(PlayerAuth.class))).willReturn(true); HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048"); given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword); + Player player = mock(Player.class); + given(commandService.getPlayer(user)).willReturn(player); + BukkitService bukkitService = mock(BukkitService.class); + given(commandService.getBukkitService()).willReturn(bukkitService); // when command.executeCommand(sender, Arrays.asList(user, password), commandService); TestHelper.runInnerRunnable(commandService); + runSyncDelayedTask(bukkitService); // then verify(commandService).validatePassword(password, user); @@ -155,6 +165,7 @@ public class RegisterAdminCommandTest { verify(dataSource).saveAuth(captor.capture()); assertAuthHasInfo(captor.getValue(), user, hashedPassword); verify(dataSource).setUnlogged(user); + verify(player).kickPlayer(argThat(containsString("please log in again"))); } private void assertAuthHasInfo(PlayerAuth auth, String name, HashedPassword hashedPassword) { @@ -162,4 +173,11 @@ public class RegisterAdminCommandTest { assertThat(auth.getNickname(), equalTo(name.toLowerCase())); assertThat(auth.getPassword(), equalTo(hashedPassword)); } + + private static void runSyncDelayedTask(BukkitService bukkitService) { + ArgumentCaptor captor = ArgumentCaptor.forClass(Runnable.class); + verify(bukkitService).scheduleSyncDelayedTask(captor.capture()); + Runnable runnable = captor.getValue(); + runnable.run(); + } }