Fix refactor errors

This commit is contained in:
Gabriele C 2016-10-04 22:30:25 +02:00
parent 7394e004ce
commit 2d2c14eb0a
6 changed files with 29 additions and 31 deletions

View File

@ -33,7 +33,7 @@ import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.task.CleanupTask;
import fr.xephi.authme.task.purge.PurgeService;
import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.geoip.GeoIpManager;
import fr.xephi.authme.service.MigrationService;
import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Server;
@ -74,7 +74,7 @@ public class AuthMe extends JavaPlugin {
private DataSource database;
private BukkitService bukkitService;
private Injector injector;
private GeoLiteAPI geoLiteApi;
private GeoIpManager geoIpManager;
private PlayerCache playerCache;
/**
@ -248,7 +248,7 @@ public class AuthMe extends JavaPlugin {
permsMan = injector.getSingleton(PermissionsManager.class);
bukkitService = injector.getSingleton(BukkitService.class);
commandHandler = injector.getSingleton(CommandHandler.class);
geoLiteApi = injector.getSingleton(GeoLiteAPI.class);
geoIpManager = injector.getSingleton(GeoIpManager.class);
// Trigger construction of API classes; they will keep track of the singleton
injector.getSingleton(NewAPI.class);
@ -374,7 +374,7 @@ public class AuthMe extends JavaPlugin {
.replace("{SERVER}", server.getServerName())
.replace("{VERSION}", server.getBukkitVersion())
// TODO: We should cache info like this, maybe with a class that extends Player?
.replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress));
.replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress));
}

View File

@ -17,7 +17,7 @@ import java.net.URLConnection;
import java.util.concurrent.TimeUnit;
import java.util.zip.GZIPInputStream;
public class GeoLiteAPI {
public class GeoIpManager {
private static final String LICENSE =
"[LICENSE] This product uses data from the GeoLite API created by MaxMind, available at http://www.maxmind.com";
private static final String GEOIP_URL =
@ -28,14 +28,14 @@ public class GeoLiteAPI {
private final File dataFile;
@Inject
GeoLiteAPI(@DataFolder File dataFolder) {
GeoIpManager(@DataFolder File dataFolder) {
this.dataFile = new File(dataFolder, "GeoIP.dat");
// Fires download of recent data or the initialization of the look up service
isDataAvailable();
}
@VisibleForTesting
GeoLiteAPI(@DataFolder File dataFolder, LookupService lookupService) {
GeoIpManager(@DataFolder File dataFolder, LookupService lookupService) {
this.dataFile = dataFolder;
this.lookupService = lookupService;
}

View File

@ -2,7 +2,7 @@ package fr.xephi.authme.service;
import com.github.authme.configme.properties.Property;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.geoip.GeoIpManager;
import fr.xephi.authme.initialization.Reloadable;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.PermissionsManager;
@ -36,7 +36,7 @@ public class ValidationService implements Reloadable {
@Inject
private PermissionsManager permissionsManager;
@Inject
private GeoLiteAPI geoLiteApi;
private GeoIpManager geoIpManager;
private Pattern passwordRegex;
private Set<String> unrestrictedNames;
@ -115,7 +115,7 @@ public class ValidationService implements Reloadable {
return true;
}
String countryCode = geoLiteApi.getCountryCode(hostAddress);
String countryCode = geoIpManager.getCountryCode(hostAddress);
return validateWhitelistAndBlacklist(countryCode,
ProtectionSettings.COUNTRIES_WHITELIST,
ProtectionSettings.COUNTRIES_BLACKLIST);

View File

@ -2,7 +2,6 @@ package fr.xephi.authme.geoip;
import com.maxmind.geoip.Country;
import com.maxmind.geoip.LookupService;
import fr.xephi.authme.geoip.GeoLiteAPI;
import org.junit.Before;
import org.junit.Rule;
import org.junit.Test;
@ -23,12 +22,12 @@ import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
/**
* Test for {@link GeoLiteAPI}.
* Test for {@link GeoIpManager}.
*/
@RunWith(MockitoJUnitRunner.class)
public class GeoIpManagerTest {
private GeoLiteAPI geoLiteApi;
private GeoIpManager geoIpManager;
private File dataFolder;
@Mock
private LookupService lookupService;
@ -39,7 +38,7 @@ public class GeoIpManagerTest {
@Before
public void initializeGeoLiteApi() throws IOException {
dataFolder = temporaryFolder.newFolder();
geoLiteApi = new GeoLiteAPI(dataFolder, lookupService);
geoIpManager = new GeoIpManager(dataFolder, lookupService);
}
@Test
@ -52,7 +51,7 @@ public class GeoIpManagerTest {
given(lookupService.getCountry(ip)).willReturn(country);
// when
String result = geoLiteApi.getCountryCode(ip);
String result = geoIpManager.getCountryCode(ip);
// then
assertThat(result, equalTo(countryCode));
@ -65,7 +64,7 @@ public class GeoIpManagerTest {
String ip = "127.0.0.1";
// when
String result = geoLiteApi.getCountryCode(ip);
String result = geoIpManager.getCountryCode(ip);
// then
assertThat(result, equalTo("--"));
@ -82,7 +81,7 @@ public class GeoIpManagerTest {
given(lookupService.getCountry(ip)).willReturn(country);
// when
String result = geoLiteApi.getCountryName(ip);
String result = geoIpManager.getCountryName(ip);
// then
assertThat(result, equalTo(countryName));
@ -95,7 +94,7 @@ public class GeoIpManagerTest {
String ip = "127.0.0.1";
// when
String result = geoLiteApi.getCountryName(ip);
String result = geoIpManager.getCountryName(ip);
// then
assertThat(result, equalTo("N/A"));

View File

@ -5,11 +5,10 @@ import ch.jalu.injector.testing.DelayedInjectionRunner;
import ch.jalu.injector.testing.InjectDelayed;
import com.google.common.base.Strings;
import fr.xephi.authme.datasource.DataSource;
import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.geoip.GeoIpManager;
import fr.xephi.authme.output.MessageKey;
import fr.xephi.authme.permission.PermissionsManager;
import fr.xephi.authme.permission.PlayerStatePermission;
import fr.xephi.authme.service.ValidationService;
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.EmailSettings;
import fr.xephi.authme.settings.properties.ProtectionSettings;
@ -46,7 +45,7 @@ public class ValidationServiceTest {
@Mock
private PermissionsManager permissionsManager;
@Mock
private GeoLiteAPI geoLiteApi;
private GeoIpManager geoIpManager;
@BeforeInjecting
public void createService() {
@ -267,7 +266,7 @@ public class ValidationServiceTest {
// then
assertThat(result, equalTo(true));
verifyZeroInteractions(geoLiteApi);
verifyZeroInteractions(geoIpManager);
}
@Test
@ -276,14 +275,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it"));
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.<String>emptyList());
String ip = "127.0.0.1";
given(geoLiteApi.getCountryCode(ip)).willReturn("CH");
given(geoIpManager.getCountryCode(ip)).willReturn("CH");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(true));
verify(geoLiteApi).getCountryCode(ip);
verify(geoIpManager).getCountryCode(ip);
}
@Test
@ -292,14 +291,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(asList("ch", "it"));
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(Collections.<String>emptyList());
String ip = "123.45.67.89";
given(geoLiteApi.getCountryCode(ip)).willReturn("BR");
given(geoIpManager.getCountryCode(ip)).willReturn("BR");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(false));
verify(geoLiteApi).getCountryCode(ip);
verify(geoIpManager).getCountryCode(ip);
}
@Test
@ -308,14 +307,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.<String>emptyList());
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it"));
String ip = "127.0.0.1";
given(geoLiteApi.getCountryCode(ip)).willReturn("BR");
given(geoIpManager.getCountryCode(ip)).willReturn("BR");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(true));
verify(geoLiteApi).getCountryCode(ip);
verify(geoIpManager).getCountryCode(ip);
}
@Test
@ -324,14 +323,14 @@ public class ValidationServiceTest {
given(settings.getProperty(ProtectionSettings.COUNTRIES_WHITELIST)).willReturn(Collections.<String>emptyList());
given(settings.getProperty(ProtectionSettings.COUNTRIES_BLACKLIST)).willReturn(asList("ch", "it"));
String ip = "123.45.67.89";
given(geoLiteApi.getCountryCode(ip)).willReturn("IT");
given(geoIpManager.getCountryCode(ip)).willReturn("IT");
// when
boolean result = validationService.isCountryAdmitted(ip);
// then
assertThat(result, equalTo(false));
verify(geoLiteApi).getCountryCode(ip);
verify(geoIpManager).getCountryCode(ip);
}
private static void assertErrorEquals(ValidationResult validationResult, MessageKey messageKey, String... args) {

View File

@ -15,7 +15,7 @@ import static org.mockito.Mockito.doThrow;
import static org.mockito.Mockito.mock;
/**
* Test for {@link Utils}.
* Test for {@link PlayerUtils}.
*/
public class PlayerUtilsTest {