AntiBot - make public field private

This commit is contained in:
ljacqu
2016-06-26 09:25:52 +02:00
parent df060ff29c
commit d72d6ddf5a
4 changed files with 71 additions and 4 deletions
@@ -36,6 +36,7 @@ import java.util.List;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
@@ -377,6 +378,51 @@ public class OnJoinVerifierTest {
verifyZeroInteractions(bukkitService);
}
@Test
public void shouldCheckAntiBot() throws FailedVerificationException {
// given
String name = "user123";
boolean hasAuth = false;
given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.LISTENING);
// when
onJoinVerifier.checkAntibot(name, hasAuth);
// then
verify(antiBot).getAntiBotStatus();
}
@Test
public void shouldAllowUserWithAuth() throws FailedVerificationException {
// given
String name = "Bobby";
boolean hasAuth = true;
given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE);
// when
onJoinVerifier.checkAntibot(name, hasAuth);
// then
verify(antiBot).getAntiBotStatus();
}
@Test
public void shouldThrowForActiveAntiBot() {
// given
String name = "Bobby";
boolean hasAuth = false;
given(antiBot.getAntiBotStatus()).willReturn(AntiBot.AntiBotStatus.ACTIVE);
// when / then
try {
onJoinVerifier.checkAntibot(name, hasAuth);
fail("Expected exception to be thrown");
} catch (FailedVerificationException e) {
assertThat(e, exceptionWithData(MessageKey.KICK_ANTIBOT));
verify(antiBot).addPlayerKick(name);
}
}
private static Player newPlayerWithName(String name) {
Player player = mock(Player.class);
given(player.getName()).willReturn(name);