Update to spigot 1.20.5, bump mvn plugin version, require jvm 17, require mvn 3.9, require spigot 1.19, use the spigot runtime dependency download system, use the official maxmind geoip database parser

This commit is contained in:
Gabriele C.
2024-04-26 01:29:21 +02:00
parent a14df80a87
commit 1b69abd09e
7 changed files with 277 additions and 340 deletions
@@ -18,6 +18,7 @@ import org.mockito.Mock;
import java.util.logging.Logger;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.both;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.equalTo;
@@ -25,7 +26,6 @@ import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
import static org.junit.Assert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
@@ -40,6 +40,7 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
@RunWith(DelayedInjectionRunner.class)
public class LimboPersistenceTest {
@SuppressWarnings("unused")
@InjectDelayed
private LimboPersistence limboPersistence;
@@ -59,7 +60,7 @@ public class LimboPersistenceTest {
public void setUpMocks() {
given(settings.getProperty(LimboSettings.LIMBO_PERSISTENCE_TYPE)).willReturn(LimboPersistenceType.DISABLED);
given(handlerFactory.newInstance(any(Class.class)))
.willAnswer(invocation -> mock(invocation.getArgument(0)));
.willAnswer(invocation -> mock((Class<?>) invocation.getArgument(0)));
}
@Test
@@ -1,13 +1,12 @@
package fr.xephi.authme.service;
import com.maxmind.db.GeoIp2Provider;
import com.maxmind.db.model.Country;
import com.maxmind.db.model.CountryResponse;
import java.io.File;
import java.io.IOException;
import java.net.InetAddress;
import com.maxmind.geoip2.DatabaseReader;
import com.maxmind.geoip2.model.CountryResponse;
import com.maxmind.geoip2.record.Country;
import fr.xephi.authme.settings.Settings;
import org.junit.Before;
import org.junit.Rule;
@@ -17,11 +16,11 @@ import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.mockito.junit.MockitoJUnitRunner;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.BDDMockito.given;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.never;
import static org.mockito.Mockito.verify;
@@ -33,10 +32,9 @@ import static org.mockito.Mockito.verify;
public class GeoIpServiceTest {
private GeoIpService geoIpService;
private File dataFolder;
@Mock
private GeoIp2Provider lookupService;
private DatabaseReader lookupService;
@Mock
private BukkitService bukkitService;
@@ -49,7 +47,7 @@ public class GeoIpServiceTest {
@Before
public void initializeGeoLiteApi() throws IOException {
dataFolder = temporaryFolder.newFolder();
File dataFolder = temporaryFolder.newFolder();
geoIpService = new GeoIpService(dataFolder, bukkitService, settings, lookupService);
}
@@ -64,14 +62,14 @@ public class GeoIpServiceTest {
CountryResponse response = mock(CountryResponse.class);
given(response.getCountry()).willReturn(country);
given(lookupService.getCountry(ip)).willReturn(response);
given(lookupService.country(ip)).willReturn(response);
// when
String result = geoIpService.getCountryCode(ip.getHostAddress());
// then
assertThat(result, equalTo(countryCode));
verify(lookupService).getCountry(ip);
verify(lookupService).country(ip);
}
@Test
@@ -84,7 +82,7 @@ public class GeoIpServiceTest {
// then
assertThat(result, equalTo("LOCALHOST"));
verify(lookupService, never()).getCountry(any());
verify(lookupService, never()).country(any());
}
@Test
@@ -98,14 +96,14 @@ public class GeoIpServiceTest {
CountryResponse response = mock(CountryResponse.class);
given(response.getCountry()).willReturn(country);
given(lookupService.getCountry(ip)).willReturn(response);
given(lookupService.country(ip)).willReturn(response);
// when
String result = geoIpService.getCountryName(ip.getHostAddress());
// then
assertThat(result, equalTo(countryName));
verify(lookupService).getCountry(ip);
verify(lookupService).country(ip);
}
@Test
@@ -118,6 +116,6 @@ public class GeoIpServiceTest {
// then
assertThat(result, equalTo("LocalHost"));
verify(lookupService, never()).getCountry(ip);
verify(lookupService, never()).country(ip);
}
}