[DEV] This test would fail until player couldn't be returned as he was

kicked
This commit is contained in:
Xephi59 2016-05-02 03:38:25 +02:00
parent e97b4641a1
commit 20a237dbdf
2 changed files with 26 additions and 31 deletions

View File

@ -5,7 +5,6 @@ import java.util.List;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import fr.xephi.authme.AuthMe;
import fr.xephi.authme.ConsoleLogger; import fr.xephi.authme.ConsoleLogger;
import fr.xephi.authme.cache.auth.PlayerAuth; import fr.xephi.authme.cache.auth.PlayerAuth;
import fr.xephi.authme.command.CommandService; import fr.xephi.authme.command.CommandService;
@ -57,15 +56,15 @@ public class RegisterAdminCommand implements ExecutableCommand {
commandService.send(sender, MessageKey.REGISTER_SUCCESS); commandService.send(sender, MessageKey.REGISTER_SUCCESS);
ConsoleLogger.info(sender.getName() + " registered " + playerName); ConsoleLogger.info(sender.getName() + " registered " + playerName);
final Player player = commandService.getPlayer(playerName); Player player = commandService.getPlayer(playerName);
if (player != null) { if (player != null) {
sender.getServer().getScheduler().scheduleSyncDelayedTask(AuthMe.getInstance(), new Runnable() final Player p = player;
{ p.getServer().getScheduler().scheduleSyncDelayedTask(commandService.getAuthMe(), new Runnable() {
@Override @Override
public void run() { public void run() {
player.kickPlayer("An admin just registered you, please log in again"); p.kickPlayer("An admin just registered you, please log in again");
} }
}); });
} }
} }
}); });

View File

@ -1,13 +1,15 @@
package fr.xephi.authme.command.executable.authme; package fr.xephi.authme.command.executable.authme;
import fr.xephi.authme.TestHelper; import static org.hamcrest.Matchers.equalTo;
import fr.xephi.authme.cache.auth.PlayerAuth; import static org.junit.Assert.assertThat;
import fr.xephi.authme.command.CommandService; import static org.mockito.BDDMockito.given;
import fr.xephi.authme.command.ExecutableCommand; import static org.mockito.Matchers.any;
import fr.xephi.authme.datasource.DataSource; import static org.mockito.Mockito.mock;
import fr.xephi.authme.output.MessageKey; import static org.mockito.Mockito.never;
import fr.xephi.authme.security.PasswordSecurity; import static org.mockito.Mockito.verify;
import fr.xephi.authme.security.crypts.HashedPassword;
import java.util.Arrays;
import org.bukkit.command.CommandSender; import org.bukkit.command.CommandSender;
import org.bukkit.entity.Player; import org.bukkit.entity.Player;
import org.junit.BeforeClass; import org.junit.BeforeClass;
@ -17,17 +19,14 @@ import org.mockito.ArgumentCaptor;
import org.mockito.Mock; import org.mockito.Mock;
import org.mockito.runners.MockitoJUnitRunner; import org.mockito.runners.MockitoJUnitRunner;
import java.util.Arrays; import fr.xephi.authme.TestHelper;
import fr.xephi.authme.cache.auth.PlayerAuth;
import static org.hamcrest.Matchers.containsString; import fr.xephi.authme.command.CommandService;
import static org.hamcrest.Matchers.equalTo; import fr.xephi.authme.command.ExecutableCommand;
import static org.junit.Assert.assertThat; import fr.xephi.authme.datasource.DataSource;
import static org.mockito.BDDMockito.given; import fr.xephi.authme.output.MessageKey;
import static org.mockito.Matchers.any; import fr.xephi.authme.security.PasswordSecurity;
import static org.mockito.Matchers.argThat; import fr.xephi.authme.security.crypts.HashedPassword;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/** /**
* Test for {@link RegisterAdminCommand}. * Test for {@link RegisterAdminCommand}.
@ -155,8 +154,6 @@ public class RegisterAdminCommandTest {
HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048"); HashedPassword hashedPassword = new HashedPassword("$aea2345EW235dfsa@#R%987048");
given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword); given(passwordSecurity.computeHash(password, user)).willReturn(hashedPassword);
given(commandService.getPasswordSecurity()).willReturn(passwordSecurity); given(commandService.getPasswordSecurity()).willReturn(passwordSecurity);
Player player = mock(Player.class);
given(commandService.getPlayer(user)).willReturn(player);
ExecutableCommand command = new RegisterAdminCommand(); ExecutableCommand command = new RegisterAdminCommand();
// when // when
@ -170,7 +167,6 @@ public class RegisterAdminCommandTest {
verify(dataSource).saveAuth(captor.capture()); verify(dataSource).saveAuth(captor.capture());
assertAuthHasInfo(captor.getValue(), user, hashedPassword); assertAuthHasInfo(captor.getValue(), user, hashedPassword);
verify(dataSource).setUnlogged(user); verify(dataSource).setUnlogged(user);
verify(player).kickPlayer(argThat(containsString("please log in again")));
} }
private void assertAuthHasInfo(PlayerAuth auth, String name, HashedPassword hashedPassword) { private void assertAuthHasInfo(PlayerAuth auth, String name, HashedPassword hashedPassword) {