counter1 = mockCounter();
diff --git a/src/test/java/fr/xephi/authme/data/VerificationCodeManagerTest.java b/src/test/java/fr/xephi/authme/data/VerificationCodeManagerTest.java
index 7486a895e2..836c0e8e06 100644
--- a/src/test/java/fr/xephi/authme/data/VerificationCodeManagerTest.java
+++ b/src/test/java/fr/xephi/authme/data/VerificationCodeManagerTest.java
@@ -9,14 +9,14 @@
import fr.xephi.authme.settings.Settings;
import fr.xephi.authme.settings.properties.SecuritySettings;
import org.bukkit.entity.Player;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
-import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
@@ -26,8 +26,8 @@
/**
* Test for {@link VerificationCodeManager}.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class VerificationCodeManagerTest {
+@ExtendWith(MockitoExtension.class)
+class VerificationCodeManagerTest {
@Mock
private Settings settings;
@@ -44,15 +44,15 @@ public class VerificationCodeManagerTest {
@Mock
private BukkitService bukkitService;
- @Before
- public void setUpBasicBehavior() {
- given(emailService.hasAllInformation()).willReturn(true);
+ @BeforeEach
+ void setUpBasicBehavior() {
given(settings.getProperty(SecuritySettings.VERIFICATION_CODE_EXPIRATION_MINUTES)).willReturn(1);
}
@Test
- public void shouldRequireVerification() {
+ void shouldRequireVerification() {
// given
+ given(emailService.hasAllInformation()).willReturn(true);
String name1 = "ILoveTests";
Player player1 = mockPlayerWithName(name1);
given(dataSource.getEmail(name1)).willReturn(DataSourceValueImpl.of("ilovetests@test.com"));
@@ -75,7 +75,7 @@ public void shouldRequireVerification() {
}
@Test
- public void shouldNotRequireVerificationIfEmailSettingsAreIncomplete() {
+ void shouldNotRequireVerificationIfEmailSettingsAreIncomplete() {
// given
given(emailService.hasAllInformation()).willReturn(false);
VerificationCodeManager codeManager = createCodeManager();
@@ -90,8 +90,9 @@ public void shouldNotRequireVerificationIfEmailSettingsAreIncomplete() {
}
@Test
- public void shouldNotRequireVerificationForMissingPermission() {
+ void shouldNotRequireVerificationForMissingPermission() {
// given
+ given(emailService.hasAllInformation()).willReturn(true);
Player player = mockPlayerWithName("ILoveTests");
given(permissionsManager.hasPermission(player, PlayerPermission.VERIFICATION_CODE)).willReturn(false);
VerificationCodeManager codeManager = createCodeManager();
@@ -106,8 +107,9 @@ public void shouldNotRequireVerificationForMissingPermission() {
}
@Test
- public void shouldGenerateCode() {
+ void shouldGenerateCode() {
// given
+ given(emailService.hasAllInformation()).willReturn(true);
String player = "ILoveTests";
String email = "ilovetests@test.com";
given(dataSource.getEmail(player)).willReturn(DataSourceValueImpl.of(email));
@@ -125,8 +127,9 @@ public void shouldGenerateCode() {
}
@Test
- public void shouldRequireCode() {
+ void shouldRequireCode() {
// given
+ given(emailService.hasAllInformation()).willReturn(true);
String player = "ILoveTests";
String email = "ilovetests@test.com";
given(dataSource.getEmail(player)).willReturn(DataSourceValueImpl.of(email));
@@ -144,8 +147,9 @@ public void shouldRequireCode() {
}
@Test
- public void shouldVerifyCode() {
+ void shouldVerifyCode() {
// given
+ given(emailService.hasAllInformation()).willReturn(true);
String player = "ILoveTests";
String code = "193458";
String email = "ilovetests@test.com";
diff --git a/src/test/java/fr/xephi/authme/data/auth/PlayerAuthTest.java b/src/test/java/fr/xephi/authme/data/auth/PlayerAuthTest.java
index 360abdc986..679dc52a0e 100644
--- a/src/test/java/fr/xephi/authme/data/auth/PlayerAuthTest.java
+++ b/src/test/java/fr/xephi/authme/data/auth/PlayerAuthTest.java
@@ -1,19 +1,19 @@
package fr.xephi.authme.data.auth;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
-import static org.junit.Assert.fail;
+import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link PlayerAuth} and its builder.
*/
-public class PlayerAuthTest {
+class PlayerAuthTest {
@Test
- public void shouldRemoveDatabaseDefaults() {
+ void shouldRemoveDatabaseDefaults() {
// given / when
PlayerAuth auth = PlayerAuth.builder()
.name("Bobby")
@@ -32,7 +32,7 @@ public void shouldRemoveDatabaseDefaults() {
}
@Test
- public void shouldThrowForMissingName() {
+ void shouldThrowForMissingName() {
try {
// given / when
PlayerAuth.builder()
@@ -48,7 +48,7 @@ public void shouldThrowForMissingName() {
}
@Test
- public void shouldCreatePlayerAuthWithNullValues() {
+ void shouldCreatePlayerAuthWithNullValues() {
// given / when
PlayerAuth auth = PlayerAuth.builder()
.name("Charlie")
diff --git a/src/test/java/fr/xephi/authme/data/captcha/LoginCaptchaManagerTest.java b/src/test/java/fr/xephi/authme/data/captcha/LoginCaptchaManagerTest.java
index c313fc571b..e612bd8bb0 100644
--- a/src/test/java/fr/xephi/authme/data/captcha/LoginCaptchaManagerTest.java
+++ b/src/test/java/fr/xephi/authme/data/captcha/LoginCaptchaManagerTest.java
@@ -5,24 +5,24 @@
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.expiring.TimedCounter;
import org.bukkit.entity.Player;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import java.util.Locale;
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Test for {@link LoginCaptchaManager}.
*/
-public class LoginCaptchaManagerTest {
+class LoginCaptchaManagerTest {
@Test
- public void shouldAddCounts() {
+ void shouldAddCounts() {
// given
Settings settings = mockSettings(3, 4);
LoginCaptchaManager manager = new LoginCaptchaManager(settings);
@@ -41,7 +41,7 @@ public void shouldAddCounts() {
}
@Test
- public void shouldCreateAndCheckCaptcha() {
+ void shouldCreateAndCheckCaptcha() {
// given
String name = "Miner";
Player player = mock(Player.class);
@@ -61,7 +61,7 @@ public void shouldCreateAndCheckCaptcha() {
}
@Test
- public void shouldGenerateNewCodeOnFailure() {
+ void shouldGenerateNewCodeOnFailure() {
// given
String name = "Tarheel";
Player player = mock(Player.class);
@@ -80,7 +80,7 @@ public void shouldGenerateNewCodeOnFailure() {
}
@Test
- public void shouldHaveSameCodeAfterGeneration() {
+ void shouldHaveSameCodeAfterGeneration() {
// given
String player = "Tester";
Settings settings = mockSettings(1, 5);
@@ -98,7 +98,7 @@ public void shouldHaveSameCodeAfterGeneration() {
}
@Test
- public void shouldIncreaseAndResetCount() {
+ void shouldIncreaseAndResetCount() {
// given
String player = "plaYer";
Settings settings = mockSettings(2, 3);
@@ -121,7 +121,7 @@ public void shouldIncreaseAndResetCount() {
}
@Test
- public void shouldNotIncreaseCountForDisabledCaptcha() {
+ void shouldNotIncreaseCountForDisabledCaptcha() {
// given
String player = "someone_";
Settings settings = mockSettings(1, 3);
@@ -137,7 +137,7 @@ public void shouldNotIncreaseCountForDisabledCaptcha() {
}
@Test
- public void shouldNotCheckCountIfCaptchaIsDisabled() {
+ void shouldNotCheckCountIfCaptchaIsDisabled() {
// given
String player = "Robert001";
Settings settings = mockSettings(1, 5);
diff --git a/src/test/java/fr/xephi/authme/data/captcha/RegistrationCaptchaManagerTest.java b/src/test/java/fr/xephi/authme/data/captcha/RegistrationCaptchaManagerTest.java
index 07aeaf0b8b..a0ef35bcac 100644
--- a/src/test/java/fr/xephi/authme/data/captcha/RegistrationCaptchaManagerTest.java
+++ b/src/test/java/fr/xephi/authme/data/captcha/RegistrationCaptchaManagerTest.java
@@ -5,21 +5,21 @@
import fr.xephi.authme.settings.properties.SecuritySettings;
import fr.xephi.authme.util.expiring.ExpiringMap;
import org.bukkit.entity.Player;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
-import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.MatcherAssert.assertThat;
+import static org.hamcrest.Matchers.equalTo;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
/**
* Test for {@link RegistrationCaptchaManager}.
*/
-public class RegistrationCaptchaManagerTest {
+class RegistrationCaptchaManagerTest {
@Test
- public void shouldBeDisabled() {
+ void shouldBeDisabled() {
// given
Settings settings = mock(Settings.class);
// Return false first time, and true after that
@@ -37,7 +37,7 @@ public void shouldBeDisabled() {
}
@Test
- public void shouldVerifyCodeSuccessfully() {
+ void shouldVerifyCodeSuccessfully() {
// given
Settings settings = mock(Settings.class);
given(settings.getProperty(SecuritySettings.ENABLE_CAPTCHA_FOR_REGISTRATION)).willReturn(true);
@@ -60,7 +60,7 @@ public void shouldVerifyCodeSuccessfully() {
}
@Test
- public void shouldGenerateAndRetrieveCode() {
+ void shouldGenerateAndRetrieveCode() {
// given
Settings settings = mock(Settings.class);
given(settings.getProperty(SecuritySettings.ENABLE_CAPTCHA_FOR_REGISTRATION)).willReturn(true);
diff --git a/src/test/java/fr/xephi/authme/data/limbo/AllowFlightRestoreTypeTest.java b/src/test/java/fr/xephi/authme/data/limbo/AllowFlightRestoreTypeTest.java
index eb7ee38936..efc7d75196 100644
--- a/src/test/java/fr/xephi/authme/data/limbo/AllowFlightRestoreTypeTest.java
+++ b/src/test/java/fr/xephi/authme/data/limbo/AllowFlightRestoreTypeTest.java
@@ -1,7 +1,7 @@
package fr.xephi.authme.data.limbo;
import org.bukkit.entity.Player;
-import org.junit.Test;
+import org.junit.jupiter.api.Test;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
@@ -11,10 +11,10 @@
/**
* Test for {@link AllowFlightRestoreType}.
*/
-public class AllowFlightRestoreTypeTest {
+class AllowFlightRestoreTypeTest {
@Test
- public void shouldRestoreValue() {
+ void shouldRestoreValue() {
// given
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
@@ -31,7 +31,7 @@ public void shouldRestoreValue() {
}
@Test
- public void shouldEnableFlight() {
+ void shouldEnableFlight() {
// given
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
@@ -49,7 +49,7 @@ public void shouldEnableFlight() {
@Test
- public void shouldDisableFlight() {
+ void shouldDisableFlight() {
// given
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
@@ -66,7 +66,7 @@ public void shouldDisableFlight() {
}
@Test
- public void shouldNotInteractWithPlayer() {
+ void shouldNotInteractWithPlayer() {
// given
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
@@ -82,7 +82,7 @@ public void shouldNotInteractWithPlayer() {
}
@Test
- public void shouldRemoveFlightExceptForNothingType() {
+ void shouldRemoveFlightExceptForNothingType() {
// given
AllowFlightRestoreType noInteractionType = AllowFlightRestoreType.NOTHING;
diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java
index fdc82abe6b..b9fcdf4a51 100644
--- a/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java
+++ b/src/test/java/fr/xephi/authme/data/limbo/LimboPlayerTaskManagerTest.java
@@ -13,21 +13,21 @@
import fr.xephi.authme.task.TimeoutTask;
import org.bukkit.entity.Player;
import org.bukkit.scheduler.BukkitTask;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collections;
import static fr.xephi.authme.service.BukkitService.TICKS_PER_SECOND;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.anyLong;
import static org.mockito.ArgumentMatchers.eq;
@@ -39,8 +39,8 @@
/**
* Test for {@link LimboPlayerTaskManager}.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class LimboPlayerTaskManagerTest {
+@ExtendWith(MockitoExtension.class)
+class LimboPlayerTaskManagerTest {
@InjectMocks
private LimboPlayerTaskManager limboPlayerTaskManager;
@@ -60,13 +60,13 @@ public class LimboPlayerTaskManagerTest {
@Mock
private RegistrationCaptchaManager registrationCaptchaManager;
- @BeforeClass
- public static void setupLogger() {
+ @BeforeAll
+ static void setupLogger() {
TestHelper.setupLogger();
}
@Test
- public void shouldRegisterMessageTask() {
+ void shouldRegisterMessageTask() {
// given
Player player = mock(Player.class);
LimboPlayer limboPlayer = mock(LimboPlayer.class);
@@ -86,7 +86,7 @@ public void shouldRegisterMessageTask() {
}
@Test
- public void shouldNotScheduleTaskForZeroAsInterval() {
+ void shouldNotScheduleTaskForZeroAsInterval() {
// given
Player player = mock(Player.class);
LimboPlayer limboPlayer = mock(LimboPlayer.class);
@@ -101,7 +101,7 @@ public void shouldNotScheduleTaskForZeroAsInterval() {
}
@Test
- public void shouldCancelExistingMessageTask() {
+ void shouldCancelExistingMessageTask() {
// given
String name = "rats";
Player player = mock(Player.class);
@@ -124,7 +124,7 @@ public void shouldCancelExistingMessageTask() {
}
@Test
- public void shouldInitializeMessageTaskWithCaptchaMessage() {
+ void shouldInitializeMessageTaskWithCaptchaMessage() {
// given
String name = "race";
Player player = mock(Player.class);
@@ -145,7 +145,7 @@ public void shouldInitializeMessageTaskWithCaptchaMessage() {
}
@Test
- public void shouldRegisterTimeoutTask() {
+ void shouldRegisterTimeoutTask() {
// given
Player player = mock(Player.class);
LimboPlayer limboPlayer = mock(LimboPlayer.class);
@@ -163,7 +163,7 @@ public void shouldRegisterTimeoutTask() {
}
@Test
- public void shouldNotRegisterTimeoutTaskForZeroTimeout() {
+ void shouldNotRegisterTimeoutTaskForZeroTimeout() {
// given
Player player = mock(Player.class);
LimboPlayer limboPlayer = mock(LimboPlayer.class);
@@ -177,7 +177,7 @@ public void shouldNotRegisterTimeoutTaskForZeroTimeout() {
}
@Test
- public void shouldCancelExistingTimeoutTask() {
+ void shouldCancelExistingTimeoutTask() {
// given
Player player = mock(Player.class);
LimboPlayer limboPlayer = new LimboPlayer(null, false, Collections.emptyList(), true, 0.3f, 0.1f);
diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboServiceHelperTest.java b/src/test/java/fr/xephi/authme/data/limbo/LimboServiceHelperTest.java
index f5c3fc21e5..6019c7c3a2 100644
--- a/src/test/java/fr/xephi/authme/data/limbo/LimboServiceHelperTest.java
+++ b/src/test/java/fr/xephi/authme/data/limbo/LimboServiceHelperTest.java
@@ -2,18 +2,18 @@
import fr.xephi.authme.TestHelper;
import org.bukkit.Location;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
import org.mockito.InjectMocks;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
import java.util.Collections;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.nullValue;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verifyNoInteractions;
@@ -22,19 +22,19 @@
*
* Note: some methods are tested directly where they are used via {@link LimboServiceTest}.
*/
-@RunWith(MockitoJUnitRunner.class)
-public class LimboServiceHelperTest {
+@ExtendWith(MockitoExtension.class)
+class LimboServiceHelperTest {
@InjectMocks
private LimboServiceHelper limboServiceHelper;
- @BeforeClass
- public static void initLogger() {
+ @BeforeAll
+ static void initLogger() {
TestHelper.setupLogger();
}
@Test
- public void shouldMergeLimboPlayers() {
+ void shouldMergeLimboPlayers() {
// given
Location newLocation = mock(Location.class);
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList(new UserGroup("grp-new")), false, 0.0f, 0.0f);
@@ -55,7 +55,7 @@ public void shouldMergeLimboPlayers() {
}
@Test
- public void shouldFallBackToNewLimboForMissingData() {
+ void shouldFallBackToNewLimboForMissingData() {
// given
Location newLocation = mock(Location.class);
LimboPlayer newLimbo = new LimboPlayer(newLocation, false, Collections.singletonList(new UserGroup("grp-new")), true, 0.3f, 0.0f);
@@ -75,7 +75,7 @@ public void shouldFallBackToNewLimboForMissingData() {
}
@Test
- public void shouldHandleNullInputs() {
+ void shouldHandleNullInputs() {
// given
LimboPlayer limbo = mock(LimboPlayer.class);
diff --git a/src/test/java/fr/xephi/authme/data/limbo/LimboServiceTest.java b/src/test/java/fr/xephi/authme/data/limbo/LimboServiceTest.java
index aadab82b41..f4123d6ab3 100644
--- a/src/test/java/fr/xephi/authme/data/limbo/LimboServiceTest.java
+++ b/src/test/java/fr/xephi/authme/data/limbo/LimboServiceTest.java
@@ -1,7 +1,5 @@
package fr.xephi.authme.data.limbo;
-import ch.jalu.injector.testing.DelayedInjectionRunner;
-import ch.jalu.injector.testing.InjectDelayed;
import fr.xephi.authme.ReflectionTestUtils;
import fr.xephi.authme.TestHelper;
import fr.xephi.authme.data.limbo.persistence.LimboPersistence;
@@ -12,25 +10,28 @@
import fr.xephi.authme.settings.properties.RestrictionSettings;
import org.bukkit.Location;
import org.bukkit.entity.Player;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeAll;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
+import org.mockito.InjectMocks;
import org.mockito.Mock;
import org.mockito.Mockito;
+import org.mockito.junit.jupiter.MockitoExtension;
-import java.util.Collection;
+import java.util.Arrays;
import java.util.Collections;
import java.util.Map;
+import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.not;
import static org.hamcrest.Matchers.nullValue;
import static org.hamcrest.Matchers.sameInstance;
-import static org.hamcrest.MatcherAssert.assertThat;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.ArgumentMatchers.eq;
import static org.mockito.BDDMockito.given;
+import static org.mockito.Mockito.lenient;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
import static org.mockito.Mockito.verify;
@@ -39,13 +40,13 @@
/**
* Test for {@link LimboService}, and {@link LimboServiceHelper}.
*/
-@RunWith(DelayedInjectionRunner.class)
-public class LimboServiceTest {
+@ExtendWith(MockitoExtension.class)
+class LimboServiceTest {
- @InjectDelayed
+ @InjectMocks
private LimboService limboService;
- @InjectDelayed
+ @InjectMocks
private LimboServiceHelper limboServiceHelper;
@Mock
@@ -66,18 +67,18 @@ public class LimboServiceTest {
@Mock
private AuthGroupHandler authGroupHandler;
- @BeforeClass
+ @BeforeAll
public static void initLogger() {
TestHelper.setupLogger();
}
- @Before
- public void mockSettings() {
- given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false);
+ @BeforeEach
+ void mockSettings() {
+ ReflectionTestUtils.setField(limboService, "helper", limboServiceHelper);
}
@Test
- public void shouldCreateLimboPlayer() {
+ void shouldCreateLimboPlayer() {
// given
Player player = newPlayer("Bobby", true, 0.3f, false, 0.2f);
Location playerLoc = mock(Location.class);
@@ -85,6 +86,7 @@ public void shouldCreateLimboPlayer() {
given(permissionsManager.hasGroupSupport()).willReturn(true);
given(permissionsManager.getGroups(player)).willReturn(Collections.singletonList(new UserGroup("permgrwp")));
given(settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)).willReturn(AllowFlightRestoreType.ENABLE);
+ given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false);
// when
limboService.createLimboPlayer(player, true);
@@ -109,13 +111,14 @@ public void shouldCreateLimboPlayer() {
}
@Test
- public void shouldNotKeepOpStatusForUnregisteredPlayer() {
+ void shouldNotKeepOpStatusForUnregisteredPlayer() {
// given
Player player = newPlayer("CharleS", true, 0.1f, true, 0.4f);
Location playerLoc = mock(Location.class);
given(spawnLoader.getPlayerLocationOrSpawn(player)).willReturn(playerLoc);
given(permissionsManager.hasGroupSupport()).willReturn(false);
given(settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)).willReturn(AllowFlightRestoreType.RESTORE);
+ given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false);
// when
limboService.createLimboPlayer(player, false);
@@ -140,12 +143,13 @@ public void shouldNotKeepOpStatusForUnregisteredPlayer() {
}
@Test
- public void shouldClearTasksOnAlreadyExistingLimbo() {
+ void shouldClearTasksOnAlreadyExistingLimbo() {
// given
LimboPlayer existingLimbo = mock(LimboPlayer.class);
getLimboMap().put("carlos", existingLimbo);
Player player = newPlayer("Carlos");
given(settings.getProperty(LimboSettings.RESTORE_ALLOW_FLIGHT)).willReturn(AllowFlightRestoreType.ENABLE);
+ given(settings.getProperty(RestrictionSettings.ALLOW_UNAUTHED_MOVEMENT)).willReturn(false);
// when
limboService.createLimboPlayer(player, false);
@@ -159,10 +163,9 @@ public void shouldClearTasksOnAlreadyExistingLimbo() {
}
@Test
- public void shouldRestoreData() {
+ void shouldRestoreData() {
// given
- LimboPlayer limbo = Mockito.spy(convertToLimboPlayer(
- newPlayer("John", true, 0.4f, false, 0.0f), null, Collections.emptyList()));
+ LimboPlayer limbo = Mockito.spy(newLimboPlayer(null, true, true, 0.4f, 0.0f));
getLimboMap().put("john", limbo);
Player player = newPlayer("John", false, 0.2f, false, 0.7f);
@@ -185,7 +188,7 @@ public void shouldRestoreData() {
}
@Test
- public void shouldHandleMissingLimboPlayerWhileRestoring() {
+ void shouldHandleMissingLimboPlayerWhileRestoring() {
// given
Player player = newPlayer("Test");
@@ -201,7 +204,7 @@ public void shouldHandleMissingLimboPlayerWhileRestoring() {
}
@Test
- public void shouldRemoveDiskLimboEvenWhenNoInMemoryLimboExists() {
+ void shouldRemoveDiskLimboEvenWhenNoInMemoryLimboExists() {
// given - simulates race condition: player quit before createLimboPlayer ran
Player player = newPlayer("Speedy");
// no entry in memory map for this player
@@ -215,7 +218,7 @@ public void shouldRemoveDiskLimboEvenWhenNoInMemoryLimboExists() {
}
@Test
- public void shouldReplaceTasks() {
+ void shouldReplaceTasks() {
// given
LimboPlayer limbo = mock(LimboPlayer.class);
getLimboMap().put("jeff", limbo);
@@ -232,7 +235,7 @@ public void shouldReplaceTasks() {
}
@Test
- public void shouldHandleMissingLimboForReplaceTasks() {
+ void shouldHandleMissingLimboForReplaceTasks() {
// given
Player player = newPlayer("ghost");
@@ -252,16 +255,16 @@ private static Player newPlayer(String name) {
private static Player newPlayer(String name, boolean isOp, float walkSpeed, boolean canFly, float flySpeed) {
Player player = newPlayer(name);
- given(player.isOp()).willReturn(isOp);
- given(player.getWalkSpeed()).willReturn(walkSpeed);
- given(player.getAllowFlight()).willReturn(canFly);
- given(player.getFlySpeed()).willReturn(flySpeed);
+ lenient().when(player.isOp()).thenReturn(isOp);
+ lenient().when(player.getWalkSpeed()).thenReturn(walkSpeed);
+ lenient().when(player.getAllowFlight()).thenReturn(canFly);
+ lenient().when(player.getFlySpeed()).thenReturn(flySpeed);
return player;
}
- private static LimboPlayer convertToLimboPlayer(Player player, Location location, Collection groups) {
- return new LimboPlayer(location, player.isOp(), groups, player.getAllowFlight(),
- player.getWalkSpeed(), player.getFlySpeed());
+ private static LimboPlayer newLimboPlayer(Location location, boolean isOp,
+ boolean allowFlight, float walkSpeed, float flySpeed, UserGroup... groups) {
+ return new LimboPlayer(location, isOp, Arrays.asList(groups), allowFlight, walkSpeed, flySpeed);
}
private Map getLimboMap() {
diff --git a/src/test/java/fr/xephi/authme/data/limbo/WalkFlySpeedRestoreTypeTest.java b/src/test/java/fr/xephi/authme/data/limbo/WalkFlySpeedRestoreTypeTest.java
index f8aa2719c7..110665b08b 100644
--- a/src/test/java/fr/xephi/authme/data/limbo/WalkFlySpeedRestoreTypeTest.java
+++ b/src/test/java/fr/xephi/authme/data/limbo/WalkFlySpeedRestoreTypeTest.java
@@ -1,13 +1,11 @@
package fr.xephi.authme.data.limbo;
import org.bukkit.entity.Player;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.junit.runners.Parameterized;
+import org.junit.jupiter.params.ParameterizedTest;
+import org.junit.jupiter.params.provider.MethodSource;
import java.util.Arrays;
import java.util.List;
-import java.util.stream.Collectors;
import static fr.xephi.authme.data.limbo.LimboPlayer.DEFAULT_FLY_SPEED;
import static fr.xephi.authme.data.limbo.LimboPlayer.DEFAULT_WALK_SPEED;
@@ -22,17 +20,11 @@
/**
* Test for {@link WalkFlySpeedRestoreType}.
*/
-@RunWith(Parameterized.class)
-public class WalkFlySpeedRestoreTypeTest {
+class WalkFlySpeedRestoreTypeTest {
- private final TestParameters parameters;
-
- public WalkFlySpeedRestoreTypeTest(TestParameters parameters) {
- this.parameters = parameters;
- }
-
- @Test
- public void shouldRestoreToExpectedValue() {
+ @ParameterizedTest
+ @MethodSource("buildParams")
+ void shouldRestoreToExpectedValue(TestParameters parameters) {
// given
LimboPlayer limbo = mock(LimboPlayer.class);
given(limbo.getWalkSpeed()).willReturn(parameters.givenLimboWalkSpeed);
@@ -50,10 +42,9 @@ public void shouldRestoreToExpectedValue() {
verify(player).setWalkSpeed(parameters.expectedWalkSpeed);
verify(player).setFlySpeed(parameters.expectedFlySpeed);
}
-
- @Parameterized.Parameters(name = "{0}")
- public static List