Skip to content

Commit e133a37

Browse files
committed
Fix tests (due to new Bukkit/GeoIP updates)
1 parent 6eec2c8 commit e133a37

File tree

6 files changed

+32
-16
lines changed

6 files changed

+32
-16
lines changed

src/main/java/fr/xephi/authme/process/join/AsynchronousJoin.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ private void processJoinSync(Player player, boolean isAuthAvailable) {
197197
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
198198
// Allow infinite blindness effect
199199
int blindTimeOut = (registrationTimeout <= 0) ? 99999 : registrationTimeout;
200-
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, blindTimeOut, 2));
200+
player.addPotionEffect(bukkitService.createBlindnessEffect(blindTimeOut));
201201
}
202202
commandManager.runCommandsOnJoin(player);
203203
});

src/main/java/fr/xephi/authme/process/logout/ProcessSyncPlayerLogout.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -75,7 +75,7 @@ private void applyLogoutEffect(Player player) {
7575
// Apply Blindness effect
7676
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
7777
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
78-
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
78+
player.addPotionEffect(bukkitService.createBlindnessEffect(timeout));
7979
}
8080

8181
// Set player's data to unauthenticated

src/main/java/fr/xephi/authme/process/unregister/AsynchronousUnregister.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -144,7 +144,7 @@ private void performPostUnregisterActions(String name, Player player) {
144144
private void applyBlindEffect(Player player) {
145145
if (service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)) {
146146
int timeout = service.getProperty(RestrictionSettings.TIMEOUT) * TICKS_PER_SECOND;
147-
player.addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, timeout, 2));
147+
player.addPotionEffect(bukkitService.createBlindnessEffect(timeout));
148148
}
149149
}
150150

src/main/java/fr/xephi/authme/service/BukkitService.java

+12
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,8 @@
1313
import org.bukkit.configuration.file.YamlConfiguration;
1414
import org.bukkit.entity.Player;
1515
import org.bukkit.event.Event;
16+
import org.bukkit.potion.PotionEffect;
17+
import org.bukkit.potion.PotionEffectType;
1618
import org.bukkit.scheduler.BukkitRunnable;
1719
import org.bukkit.scheduler.BukkitTask;
1820

@@ -338,6 +340,16 @@ public Optional<Boolean> isBungeeCordConfiguredForSpigot() {
338340
}
339341
}
340342

343+
/**
344+
* Creates a PotionEffect with blindness for the given duration in ticks.
345+
*
346+
* @param timeoutInTicks duration of the effect in ticks
347+
* @return blindness potion effect
348+
*/
349+
public PotionEffect createBlindnessEffect(int timeoutInTicks) {
350+
return new PotionEffect(PotionEffectType.BLINDNESS, timeoutInTicks, 2);
351+
}
352+
341353
/**
342354
* @return the IP string that this server is bound to, otherwise empty string
343355
*/

src/test/java/fr/xephi/authme/process/unregister/AsynchronousUnregisterTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -115,6 +115,7 @@ public void shouldPerformUnregister() {
115115
given(service.getProperty(RegistrationSettings.APPLY_BLIND_EFFECT)).willReturn(true);
116116
given(service.getProperty(RestrictionSettings.TIMEOUT)).willReturn(21);
117117
setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask(bukkitService);
118+
given(bukkitService.createBlindnessEffect(21 * 20)).willReturn(mock(PotionEffect.class));
118119

119120
// when
120121
asynchronousUnregister.unregister(player, userPassword);
@@ -127,7 +128,6 @@ public void shouldPerformUnregister() {
127128
verify(teleportationService).teleportOnJoin(player);
128129
verifyCalledUnregisterEventFor(player);
129130
verify(commandManager).runCommandsOnUnregister(player);
130-
verify(player).addPotionEffect(new PotionEffect(PotionEffectType.BLINDNESS, 21 * 20, 2));
131131
}
132132

133133
@Test

src/test/java/fr/xephi/authme/service/GeoIpServiceTest.java

+16-12
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,14 @@
33
import java.io.File;
44
import java.io.IOException;
55
import java.net.InetAddress;
6+
import java.util.Collections;
7+
import java.util.List;
8+
import java.util.Map;
69

10+
import com.google.common.collect.ImmutableMap;
711
import com.maxmind.geoip2.DatabaseReader;
812
import com.maxmind.geoip2.model.CountryResponse;
13+
import com.maxmind.geoip2.record.Continent;
914
import com.maxmind.geoip2.record.Country;
1015
import fr.xephi.authme.settings.Settings;
1116
import fr.xephi.authme.settings.properties.ProtectionSettings;
@@ -58,12 +63,7 @@ public void shouldGetCountry() throws Exception {
5863
// given
5964
InetAddress ip = InetAddress.getByName("123.45.67.89");
6065
String countryCode = "XX";
61-
62-
Country country = mock(Country.class);
63-
given(country.getIsoCode()).willReturn(countryCode);
64-
65-
CountryResponse response = mock(CountryResponse.class);
66-
given(response.getCountry()).willReturn(country);
66+
CountryResponse response = createCountryResponse(countryCode, "Unknown");
6767
given(lookupService.country(ip)).willReturn(response);
6868
given(settings.getProperty(ProtectionSettings.ENABLE_GEOIP)).willReturn(true);
6969

@@ -93,12 +93,7 @@ public void shouldLookUpCountryName() throws Exception {
9393
// given
9494
InetAddress ip = InetAddress.getByName("24.45.167.89");
9595
String countryName = "Ecuador";
96-
97-
Country country = mock(Country.class);
98-
given(country.getName()).willReturn(countryName);
99-
100-
CountryResponse response = mock(CountryResponse.class);
101-
given(response.getCountry()).willReturn(country);
96+
CountryResponse response = createCountryResponse("EC", countryName);
10297
given(lookupService.country(ip)).willReturn(response);
10398
given(settings.getProperty(ProtectionSettings.ENABLE_GEOIP)).willReturn(true);
10499

@@ -136,4 +131,13 @@ public void shouldNotLookUpCountryNameIfDisabled() throws Exception {
136131
assertThat(result, equalTo("N/A"));
137132
verifyNoInteractions(lookupService);
138133
}
134+
135+
private static CountryResponse createCountryResponse(String countryCode, String countryName) {
136+
List<String> locales = Collections.singletonList("en");
137+
Continent continent = new Continent(locales, "XX", 1L, Collections.emptyMap());
138+
139+
Map<String, String> countryNames = ImmutableMap.of("en", countryName);
140+
Country country = new Country(locales, 100, 3L, false, countryCode, countryNames);
141+
return new CountryResponse(continent, country, null, country, null, null);
142+
}
139143
}

0 commit comments

Comments
 (0)