Merge branch 'master' into pre-release-cleanup
# Conflicts: # pom.xml # src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java # src/test/java/fr/xephi/authme/service/ValidationServiceTest.java
This commit is contained in:
@@ -11,13 +11,13 @@ import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
import java.net.URISyntaxException;
|
||||
import java.net.URL;
|
||||
import java.net.UnknownHostException;
|
||||
import java.nio.file.Path;
|
||||
import java.nio.file.Paths;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* AuthMe test utilities.
|
||||
@@ -98,11 +98,14 @@ public final class TestHelper {
|
||||
* @param player the player mock
|
||||
* @param ip the ip address it should return
|
||||
*/
|
||||
public static void mockPlayerIp(Player player, String ip) {
|
||||
InetAddress inetAddress = mock(InetAddress.class);
|
||||
given(inetAddress.getHostAddress()).willReturn(ip);
|
||||
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 8093);
|
||||
given(player.getAddress()).willReturn(inetSocketAddress);
|
||||
public static void mockIpAddressToPlayer(Player player, String ip) {
|
||||
try {
|
||||
InetAddress inetAddress = InetAddress.getByName(ip);
|
||||
InetSocketAddress inetSocketAddress = new InetSocketAddress(inetAddress, 8093);
|
||||
given(player.getAddress()).willReturn(inetSocketAddress);
|
||||
} catch (UnknownHostException e) {
|
||||
throw new IllegalStateException("Invalid IP address: " + ip, e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
|
||||
@@ -138,11 +138,11 @@ public class CommandInitializerTest {
|
||||
String forCommandText = " for command with labels '" + command.getLabels() + "'";
|
||||
|
||||
assertThat("has description" + forCommandText,
|
||||
StringUtils.isEmpty(command.getDescription()), equalTo(false));
|
||||
StringUtils.isBlank(command.getDescription()), equalTo(false));
|
||||
assertThat("short description doesn't end in '.'" + forCommandText,
|
||||
command.getDescription().endsWith("."), equalTo(false));
|
||||
assertThat("has detailed description" + forCommandText,
|
||||
StringUtils.isEmpty(command.getDetailedDescription()), equalTo(false));
|
||||
StringUtils.isBlank(command.getDetailedDescription()), equalTo(false));
|
||||
assertThat("detailed description ends in '.'" + forCommandText,
|
||||
command.getDetailedDescription().endsWith("."), equalTo(true));
|
||||
}
|
||||
|
||||
@@ -93,7 +93,7 @@ public class ConverterCommandTest {
|
||||
// when / then
|
||||
for (Map.Entry<String, Class<? extends Converter>> entry : ConverterCommand.CONVERTERS.entrySet()) {
|
||||
assertThat("Name is not null or empty",
|
||||
StringUtils.isEmpty(entry.getKey()), equalTo(false));
|
||||
StringUtils.isBlank(entry.getKey()), equalTo(false));
|
||||
|
||||
assertThat("Converter class is unique for each entry",
|
||||
classes.add(entry.getValue()), equalTo(true));
|
||||
|
||||
@@ -100,7 +100,7 @@ public class GetIpCommandTest {
|
||||
private static Player mockPlayer(String name, String ip) {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
+2
-2
@@ -23,14 +23,14 @@ public class HelpMessageAndHelpSectionConsistencyTest {
|
||||
// when / then
|
||||
for (HelpMessage message : HelpMessage.values()) {
|
||||
assertThat("Key for message '" + message + "' is empty",
|
||||
StringUtils.isEmpty(message.getKey()), equalTo(false));
|
||||
StringUtils.isBlank(message.getKey()), equalTo(false));
|
||||
if (!keys.add(message.getKey())) {
|
||||
fail("Key for message '" + message + "' is already used elsewhere");
|
||||
}
|
||||
}
|
||||
for (HelpSection section : HelpSection.values()) {
|
||||
assertThat("Key for section '" + section + "' is empty",
|
||||
StringUtils.isEmpty(section.getKey()), equalTo(false));
|
||||
StringUtils.isBlank(section.getKey()), equalTo(false));
|
||||
if (!keys.add(section.getKey())) {
|
||||
fail("Key for section '" + section + "' is already used elsewhere");
|
||||
}
|
||||
|
||||
@@ -147,7 +147,7 @@ public class TempbanManagerTest {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String ip = "123.45.67.89";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
String banReason = "IP ban too many logins";
|
||||
given(messages.retrieveSingle(player, MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason);
|
||||
Settings settings = mockSettings(2, 100, "");
|
||||
@@ -175,7 +175,7 @@ public class TempbanManagerTest {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn("Bob");
|
||||
String ip = "143.45.77.89";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
String banCommand = "banip %ip% 15d IP ban too many logins";
|
||||
Settings settings = mockSettings(2, 100, banCommand);
|
||||
TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
|
||||
@@ -193,7 +193,7 @@ public class TempbanManagerTest {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String ip = "22.44.66.88";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
String banReason = "kick msg";
|
||||
given(messages.retrieveSingle(player, MessageKey.TEMPBAN_MAX_LOGINS)).willReturn(banReason);
|
||||
Settings settings = mockSettings(10, 60, "");
|
||||
|
||||
@@ -27,7 +27,7 @@ public class MessageKeyTest {
|
||||
String key = messageKey.getKey();
|
||||
if (!keys.add(key)) {
|
||||
fail("Found key '" + messageKey.getKey() + "' twice!");
|
||||
} else if (StringUtils.isEmpty(key)) {
|
||||
} else if (StringUtils.isBlank(key)) {
|
||||
fail("Key for message key '" + messageKey + "' is empty");
|
||||
}
|
||||
}
|
||||
|
||||
@@ -40,7 +40,7 @@ public class MessagesFileConsistencyTest {
|
||||
final String key = messageKey.getKey();
|
||||
final String message = reader.getString(key);
|
||||
|
||||
if (StringUtils.isEmpty(message)) {
|
||||
if (StringUtils.isBlank(message)) {
|
||||
errors.add("Messages file should have message for key '" + key + "'");
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -81,7 +81,7 @@ public class YamlTextFileCheckerTest {
|
||||
private void checkFile(File file, String mandatoryKey, List<String> errors) {
|
||||
try {
|
||||
PropertyReader reader = new YamlFileReader(file);
|
||||
if (StringUtils.isEmpty(reader.getString(mandatoryKey))) {
|
||||
if (StringUtils.isBlank(reader.getString(mandatoryKey))) {
|
||||
errors.add("Message for '" + mandatoryKey + "' is empty");
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
||||
@@ -125,7 +125,7 @@ public class AsynchronousLoginTest {
|
||||
String name = "oscar";
|
||||
String ip = "1.1.1.245";
|
||||
Player player = mockPlayer(name);
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
@@ -148,7 +148,7 @@ public class AsynchronousLoginTest {
|
||||
String name = "oscar";
|
||||
String ip = "1.1.1.245";
|
||||
Player player = mockPlayer(name);
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
given(dataSource.getAuth(name)).willReturn(auth);
|
||||
@@ -243,26 +243,26 @@ public class AsynchronousLoginTest {
|
||||
private void mockOnlinePlayersInBukkitService() {
|
||||
// 1.1.1.1: albania (online), brazil (offline)
|
||||
Player playerA = mockPlayer("albania");
|
||||
TestHelper.mockPlayerIp(playerA, "1.1.1.1");
|
||||
TestHelper.mockIpAddressToPlayer(playerA, "1.1.1.1");
|
||||
given(dataSource.isLogged(playerA.getName())).willReturn(true);
|
||||
Player playerB = mockPlayer("brazil");
|
||||
TestHelper.mockPlayerIp(playerB, "1.1.1.1");
|
||||
TestHelper.mockIpAddressToPlayer(playerB, "1.1.1.1");
|
||||
given(dataSource.isLogged(playerB.getName())).willReturn(false);
|
||||
|
||||
// 2.2.2.2: congo (online), denmark (offline), ecuador (online)
|
||||
Player playerC = mockPlayer("congo");
|
||||
TestHelper.mockPlayerIp(playerC, "2.2.2.2");
|
||||
TestHelper.mockIpAddressToPlayer(playerC, "2.2.2.2");
|
||||
given(dataSource.isLogged(playerC.getName())).willReturn(true);
|
||||
Player playerD = mockPlayer("denmark");
|
||||
TestHelper.mockPlayerIp(playerD, "2.2.2.2");
|
||||
TestHelper.mockIpAddressToPlayer(playerD, "2.2.2.2");
|
||||
given(dataSource.isLogged(playerD.getName())).willReturn(false);
|
||||
Player playerE = mockPlayer("ecuador");
|
||||
TestHelper.mockPlayerIp(playerE, "2.2.2.2");
|
||||
TestHelper.mockIpAddressToPlayer(playerE, "2.2.2.2");
|
||||
given(dataSource.isLogged(playerE.getName())).willReturn(true);
|
||||
|
||||
// 3.3.3.3: france (offline)
|
||||
Player playerF = mockPlayer("france");
|
||||
TestHelper.mockPlayerIp(playerF, "3.3.3.3");
|
||||
TestHelper.mockIpAddressToPlayer(playerF, "3.3.3.3");
|
||||
|
||||
List<Player> onlinePlayers = Arrays.asList(playerA, playerB, playerC, playerD, playerE, playerF);
|
||||
given(bukkitService.getOnlinePlayers()).willReturn(onlinePlayers);
|
||||
|
||||
@@ -111,7 +111,7 @@ public class AsyncRegisterTest {
|
||||
// given
|
||||
String name = "edbert";
|
||||
Player player = mockPlayerWithName(name);
|
||||
TestHelper.mockPlayerIp(player, "33.44.55.66");
|
||||
TestHelper.mockIpAddressToPlayer(player, "33.44.55.66");
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(true);
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(false);
|
||||
@@ -136,7 +136,7 @@ public class AsyncRegisterTest {
|
||||
// given
|
||||
String name = "edbert";
|
||||
Player player = mockPlayerWithName(name);
|
||||
TestHelper.mockPlayerIp(player, "33.44.55.66");
|
||||
TestHelper.mockIpAddressToPlayer(player, "33.44.55.66");
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
given(commonService.getProperty(RegistrationSettings.IS_ENABLED)).willReturn(true);
|
||||
given(commonService.getProperty(RestrictionSettings.MAX_REGISTRATION_PER_IP)).willReturn(0);
|
||||
|
||||
+1
-1
@@ -110,7 +110,7 @@ public class EmailRegisterExecutorTest {
|
||||
given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(
|
||||
invocation -> new HashedPassword(invocation.getArgument(0)));
|
||||
Player player = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(player, "123.45.67.89");
|
||||
TestHelper.mockIpAddressToPlayer(player, "123.45.67.89");
|
||||
given(player.getName()).willReturn("Veronica");
|
||||
EmailRegisterParams params = EmailRegisterParams.of(player, "test@example.com");
|
||||
|
||||
|
||||
+1
-1
@@ -97,7 +97,7 @@ public class PasswordRegisterExecutorTest {
|
||||
given(passwordSecurity.computeHash(anyString(), anyString())).willAnswer(
|
||||
invocation -> new HashedPassword(invocation.getArgument(0)));
|
||||
Player player = mockPlayerWithName("S1m0N");
|
||||
TestHelper.mockPlayerIp(player, "123.45.67.89");
|
||||
TestHelper.mockIpAddressToPlayer(player, "123.45.67.89");
|
||||
PasswordRegisterParams params = PasswordRegisterParams.of(player, "pass", "mail@example.org");
|
||||
|
||||
// when
|
||||
|
||||
+1
-1
@@ -25,7 +25,7 @@ public class PlayerAuthBuilderHelperTest {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn("Noah");
|
||||
String ip = "192.168.34.47";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
HashedPassword hashedPassword = new HashedPassword("myHash0001");
|
||||
String email = "test@example.org";
|
||||
|
||||
|
||||
@@ -74,9 +74,9 @@ public class HashAlgorithmIntegrationTest {
|
||||
}
|
||||
HashedPassword hashedPassword = method.computeHash("pwd", "name");
|
||||
assertThat("Salt should not be null if method.hasSeparateSalt(), and vice versa. Method: '"
|
||||
+ method + "'", StringUtils.isEmpty(hashedPassword.getSalt()), equalTo(!method.hasSeparateSalt()));
|
||||
+ method + "'", StringUtils.isBlank(hashedPassword.getSalt()), equalTo(!method.hasSeparateSalt()));
|
||||
assertThat("Hash should not be empty for method '" + method + "'",
|
||||
StringUtils.isEmpty(hashedPassword.getHash()), equalTo(false));
|
||||
StringUtils.isBlank(hashedPassword.getHash()), equalTo(false));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,7 @@ import com.maxmind.geoip2.DatabaseReader;
|
||||
import com.maxmind.geoip2.model.CountryResponse;
|
||||
import com.maxmind.geoip2.record.Country;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
@@ -24,6 +25,7 @@ import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
/**
|
||||
* Test for {@link GeoIpService}.
|
||||
@@ -63,6 +65,7 @@ public class GeoIpServiceTest {
|
||||
CountryResponse response = mock(CountryResponse.class);
|
||||
given(response.getCountry()).willReturn(country);
|
||||
given(lookupService.country(ip)).willReturn(response);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_GEOIP)).willReturn(true);
|
||||
|
||||
// when
|
||||
String result = geoIpService.getCountryCode(ip.getHostAddress());
|
||||
@@ -97,6 +100,7 @@ public class GeoIpServiceTest {
|
||||
CountryResponse response = mock(CountryResponse.class);
|
||||
given(response.getCountry()).willReturn(country);
|
||||
given(lookupService.country(ip)).willReturn(response);
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_GEOIP)).willReturn(true);
|
||||
|
||||
// when
|
||||
String result = geoIpService.getCountryName(ip.getHostAddress());
|
||||
@@ -118,4 +122,18 @@ public class GeoIpServiceTest {
|
||||
assertThat(result, equalTo("LocalHost"));
|
||||
verify(lookupService, never()).country(ip);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotLookUpCountryNameIfDisabled() throws Exception {
|
||||
// given
|
||||
InetAddress ip = InetAddress.getByName("24.45.167.89");
|
||||
given(settings.getProperty(ProtectionSettings.ENABLE_GEOIP)).willReturn(false);
|
||||
|
||||
// when
|
||||
String result = geoIpService.getCountryName(ip.getHostAddress());
|
||||
|
||||
// then
|
||||
assertThat(result, equalTo("N/A"));
|
||||
verifyNoInteractions(lookupService);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -78,15 +78,15 @@ public class PasswordRecoveryServiceTest {
|
||||
public void shouldKeepTrackOfSuccessfulRecoversByIp() {
|
||||
// given
|
||||
Player bobby = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(bobby, "192.168.8.8");
|
||||
TestHelper.mockIpAddressToPlayer(bobby, "192.168.8.8");
|
||||
given(bobby.getName()).willReturn("bobby");
|
||||
|
||||
Player bobby2 = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(bobby2, "127.0.0.1");
|
||||
TestHelper.mockIpAddressToPlayer(bobby2, "127.0.0.1");
|
||||
given(bobby2.getName()).willReturn("bobby");
|
||||
|
||||
Player other = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(other, "192.168.8.8");
|
||||
TestHelper.mockIpAddressToPlayer(other, "192.168.8.8");
|
||||
given(other.getName()).willReturn("other");
|
||||
|
||||
// when
|
||||
@@ -102,12 +102,12 @@ public class PasswordRecoveryServiceTest {
|
||||
public void shouldRemovePlayerFromSuccessfulRecovers() {
|
||||
// given
|
||||
Player bobby = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(bobby, "192.168.8.8");
|
||||
TestHelper.mockIpAddressToPlayer(bobby, "192.168.8.8");
|
||||
given(bobby.getName()).willReturn("bobby");
|
||||
recoveryService.addSuccessfulRecovery(bobby);
|
||||
|
||||
Player other = mock(Player.class);
|
||||
TestHelper.mockPlayerIp(other, "8.8.8.8");
|
||||
TestHelper.mockIpAddressToPlayer(other, "8.8.8.8");
|
||||
given(other.getName()).willReturn("other");
|
||||
recoveryService.addSuccessfulRecovery(other);
|
||||
|
||||
|
||||
@@ -240,7 +240,7 @@ public class SessionServiceTest {
|
||||
private static Player mockPlayerWithNameAndIp(String name, String ip) {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
return player;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -21,7 +21,9 @@ import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Mockito;
|
||||
|
||||
import java.net.InetSocketAddress;
|
||||
import java.util.Collections;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
@@ -30,7 +32,9 @@ import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.BDDMockito.willReturn;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
@@ -358,18 +362,23 @@ public class ValidationServiceTest {
|
||||
Player gabriel2 = mockPlayer("Gabriel", "93.23.33.34");
|
||||
Player emanuel = mockPlayer("emanuel", "94.65.24.10");
|
||||
Player emanuel2 = mockPlayer("emanuel", "94.65.60.10");
|
||||
Player imyourisp = mockPlayer("imyourisp", "bazinga.yourisp.net");
|
||||
Player imYourIsp = mockPlayer("imyourisp", "65.65.65.65");
|
||||
Player notRestricted = mockPlayer("notRestricted", "0.0.0.0");
|
||||
|
||||
ValidationService validationServiceSpy = Mockito.spy(validationService);
|
||||
willReturn("bogus.tld").given(validationServiceSpy).getHostName(any(InetSocketAddress.class));
|
||||
InetSocketAddress imYourIspSocketAddr = imYourIsp.getAddress();
|
||||
willReturn("bazinga.yourisp.net").given(validationServiceSpy).getHostName(imYourIspSocketAddr);
|
||||
|
||||
// when
|
||||
boolean isBobbyAdmitted = validationService.fulfillsNameRestrictions(bobby);
|
||||
boolean isTamaraAdmitted = validationService.fulfillsNameRestrictions(tamara);
|
||||
boolean isGabrielAdmitted = validationService.fulfillsNameRestrictions(gabriel);
|
||||
boolean isGabriel2Admitted = validationService.fulfillsNameRestrictions(gabriel2);
|
||||
boolean isEmanuelAdmitted = validationService.fulfillsNameRestrictions(emanuel);
|
||||
boolean isEmanuel2Admitted = validationService.fulfillsNameRestrictions(emanuel2);
|
||||
boolean isImyourispAdmitted = validationService.fulfillsNameRestrictions(imyourisp);
|
||||
boolean isNotRestrictedAdmitted = validationService.fulfillsNameRestrictions(notRestricted);
|
||||
boolean isBobbyAdmitted = validationServiceSpy.fulfillsNameRestrictions(bobby);
|
||||
boolean isTamaraAdmitted = validationServiceSpy.fulfillsNameRestrictions(tamara);
|
||||
boolean isGabrielAdmitted = validationServiceSpy.fulfillsNameRestrictions(gabriel);
|
||||
boolean isGabriel2Admitted = validationServiceSpy.fulfillsNameRestrictions(gabriel2);
|
||||
boolean isEmanuelAdmitted = validationServiceSpy.fulfillsNameRestrictions(emanuel);
|
||||
boolean isEmanuel2Admitted = validationServiceSpy.fulfillsNameRestrictions(emanuel2);
|
||||
boolean isImYourIspAdmitted = validationServiceSpy.fulfillsNameRestrictions(imYourIsp);
|
||||
boolean isNotRestrictedAdmitted = validationServiceSpy.fulfillsNameRestrictions(notRestricted);
|
||||
|
||||
// then
|
||||
assertThat(isBobbyAdmitted, equalTo(true));
|
||||
@@ -378,7 +387,7 @@ public class ValidationServiceTest {
|
||||
assertThat(isGabriel2Admitted, equalTo(false));
|
||||
assertThat(isEmanuelAdmitted, equalTo(true));
|
||||
assertThat(isEmanuel2Admitted, equalTo(false));
|
||||
assertThat(isImyourispAdmitted, equalTo(true));
|
||||
assertThat(isImYourIspAdmitted, equalTo(true));
|
||||
assertThat(isNotRestrictedAdmitted, equalTo(true));
|
||||
}
|
||||
|
||||
@@ -402,8 +411,7 @@ public class ValidationServiceTest {
|
||||
private static Player mockPlayer(String name, String ip) {
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn(name);
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
given(player.getAddress().getHostName()).willReturn("--");
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
return player;
|
||||
}
|
||||
|
||||
|
||||
@@ -92,7 +92,7 @@ public class WelcomeMessageConfigurationTest {
|
||||
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn("Bobby");
|
||||
TestHelper.mockPlayerIp(player, "123.45.66.77");
|
||||
TestHelper.mockIpAddressToPlayer(player, "123.45.66.77");
|
||||
given(geoIpService.getCountryName("123.45.66.77")).willReturn("Syldavia");
|
||||
given(service.getProperty(PluginSettings.SERVER_NAME)).willReturn("CrazyServer");
|
||||
|
||||
|
||||
@@ -313,7 +313,7 @@ public class CommandManagerTest {
|
||||
given(player.getName()).willReturn("Bobby");
|
||||
given(player.getDisplayName()).willReturn("bob");
|
||||
String ip = "127.0.0.3";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
given(geoIpService.getCountryName(ip)).willReturn("Syldavia");
|
||||
return player;
|
||||
}
|
||||
|
||||
@@ -40,10 +40,10 @@ public class ExceptionUtilsTest {
|
||||
@Test
|
||||
public void shouldHandleCircularCausesGracefully() {
|
||||
// given
|
||||
IllegalStateException ise = new IllegalStateException();
|
||||
UnsupportedOperationException uoe = new UnsupportedOperationException(ise);
|
||||
ExceptionWithSettableCause exceptionWithSettableCause = new ExceptionWithSettableCause();
|
||||
UnsupportedOperationException uoe = new UnsupportedOperationException(exceptionWithSettableCause);
|
||||
ReflectiveOperationException roe = new ReflectiveOperationException(uoe);
|
||||
ReflectionTestUtils.setField(Throwable.class, ise, "cause", roe);
|
||||
exceptionWithSettableCause.cause = roe;
|
||||
|
||||
// when
|
||||
NullPointerException resultNpe = ExceptionUtils.findThrowableInCause(NullPointerException.class, uoe);
|
||||
@@ -65,4 +65,14 @@ public class ExceptionUtilsTest {
|
||||
// then
|
||||
assertThat(result, equalTo("[MalformedURLException]: Unrecognized URL format"));
|
||||
}
|
||||
|
||||
private static final class ExceptionWithSettableCause extends Exception {
|
||||
|
||||
Exception cause;
|
||||
|
||||
@Override
|
||||
public synchronized Throwable getCause() {
|
||||
return cause;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -25,7 +25,7 @@ public class PlayerUtilsTest {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String ip = "124.86.248.62";
|
||||
TestHelper.mockPlayerIp(player, ip);
|
||||
TestHelper.mockIpAddressToPlayer(player, ip);
|
||||
|
||||
// when
|
||||
String result = PlayerUtils.getPlayerIp(player);
|
||||
|
||||
@@ -49,15 +49,15 @@ public class StringUtilsTest {
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckIsEmptyUtil() {
|
||||
public void shouldCheckIfIsBlankString() {
|
||||
// Should be true for null/empty/whitespace
|
||||
assertTrue(StringUtils.isEmpty(null));
|
||||
assertTrue(StringUtils.isEmpty(""));
|
||||
assertTrue(StringUtils.isEmpty(" \t"));
|
||||
assertTrue(StringUtils.isBlank(null));
|
||||
assertTrue(StringUtils.isBlank(""));
|
||||
assertTrue(StringUtils.isBlank(" \t"));
|
||||
|
||||
// Should be false if string has content
|
||||
assertFalse(StringUtils.isEmpty("P"));
|
||||
assertFalse(StringUtils.isEmpty(" test"));
|
||||
assertFalse(StringUtils.isBlank("P"));
|
||||
assertFalse(StringUtils.isBlank(" test"));
|
||||
}
|
||||
|
||||
@Test
|
||||
|
||||
Reference in New Issue
Block a user