Revert "Fix refactor errors"

This reverts commit 2d2c14eb0a.
This commit is contained in:
Gabriele C 2016-10-04 22:31:37 +02:00
parent 2d2c14eb0a
commit 7e2912cc60
6 changed files with 31 additions and 29 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.CleanupTask;
import fr.xephi.authme.task.purge.PurgeService; import fr.xephi.authme.task.purge.PurgeService;
import fr.xephi.authme.service.BukkitService; import fr.xephi.authme.service.BukkitService;
import fr.xephi.authme.geoip.GeoIpManager; import fr.xephi.authme.geoip.GeoLiteAPI;
import fr.xephi.authme.service.MigrationService; import fr.xephi.authme.service.MigrationService;
import fr.xephi.authme.util.PlayerUtils; import fr.xephi.authme.util.PlayerUtils;
import org.bukkit.Server; import org.bukkit.Server;
@ -74,7 +74,7 @@ public class AuthMe extends JavaPlugin {
private DataSource database; private DataSource database;
private BukkitService bukkitService; private BukkitService bukkitService;
private Injector injector; private Injector injector;
private GeoIpManager geoIpManager; private GeoLiteAPI geoLiteApi;
private PlayerCache playerCache; private PlayerCache playerCache;
/** /**
@ -248,7 +248,7 @@ public class AuthMe extends JavaPlugin {
permsMan = injector.getSingleton(PermissionsManager.class); permsMan = injector.getSingleton(PermissionsManager.class);
bukkitService = injector.getSingleton(BukkitService.class); bukkitService = injector.getSingleton(BukkitService.class);
commandHandler = injector.getSingleton(CommandHandler.class); commandHandler = injector.getSingleton(CommandHandler.class);
geoIpManager = injector.getSingleton(GeoIpManager.class); geoLiteApi = injector.getSingleton(GeoLiteAPI.class);
// Trigger construction of API classes; they will keep track of the singleton // Trigger construction of API classes; they will keep track of the singleton
injector.getSingleton(NewAPI.class); injector.getSingleton(NewAPI.class);
@ -374,7 +374,7 @@ public class AuthMe extends JavaPlugin {
.replace("{SERVER}", server.getServerName()) .replace("{SERVER}", server.getServerName())
.replace("{VERSION}", server.getBukkitVersion()) .replace("{VERSION}", server.getBukkitVersion())
// TODO: We should cache info like this, maybe with a class that extends Player? // TODO: We should cache info like this, maybe with a class that extends Player?
.replace("{COUNTRY}", geoIpManager.getCountryName(ipAddress)); .replace("{COUNTRY}", geoLiteApi.getCountryName(ipAddress));
} }

View File

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

View File

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

View File

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

View File

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