Merge 6161d95f56
into f56a23f4b7
This commit is contained in:
commit
2c1ef2656a
30
pom.xml
30
pom.xml
|
@ -1010,30 +1010,36 @@
|
|||
<!-- Unit Testing Libraries -->
|
||||
|
||||
<dependency>
|
||||
<groupId>junit</groupId>
|
||||
<artifactId>junit</artifactId>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-engine</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>4.13.2</version>
|
||||
<version>5.10.1</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.junit.jupiter</groupId>
|
||||
<artifactId>junit-jupiter-params</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>5.10.1</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
<artifactId>java-hamcrest</artifactId>
|
||||
<artifactId>hamcrest</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>2.0.0.0</version>
|
||||
<version>2.2</version>
|
||||
</dependency>
|
||||
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-core</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>4.8.1</version>
|
||||
<exclusions>
|
||||
<exclusion>
|
||||
<artifactId>hamcrest-core</artifactId>
|
||||
<groupId>org.hamcrest</groupId>
|
||||
</exclusion>
|
||||
</exclusions>
|
||||
<version>4.11.0</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.mockito</groupId>
|
||||
<artifactId>mockito-junit-jupiter</artifactId>
|
||||
<scope>test</scope>
|
||||
<version>4.11.0</version>
|
||||
</dependency>
|
||||
|
||||
<!-- Required to mock the LuckPerms API-->
|
||||
|
|
|
@ -24,7 +24,7 @@ public class HelpMessagesService {
|
|||
private final HelpMessagesFileHandler helpMessagesFileHandler;
|
||||
|
||||
@Inject
|
||||
HelpMessagesService(HelpMessagesFileHandler helpMessagesFileHandler) {
|
||||
public HelpMessagesService(HelpMessagesFileHandler helpMessagesFileHandler) {
|
||||
this.helpMessagesFileHandler = helpMessagesFileHandler;
|
||||
}
|
||||
|
||||
|
|
|
@ -12,7 +12,6 @@ import org.bukkit.configuration.file.FileConfiguration;
|
|||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import javax.annotation.PostConstruct;
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
|
||||
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_LANGUAGE;
|
||||
|
@ -24,18 +23,16 @@ public abstract class AbstractMessageFileHandler implements Reloadable {
|
|||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(AbstractMessageFileHandler.class);
|
||||
|
||||
@DataFolder
|
||||
@Inject
|
||||
private File dataFolder;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
private final File dataFolder;
|
||||
private final Settings settings;
|
||||
|
||||
private String filename;
|
||||
private FileConfiguration configuration;
|
||||
private final String defaultFile;
|
||||
|
||||
protected AbstractMessageFileHandler() {
|
||||
protected AbstractMessageFileHandler(@DataFolder File dataFolder, Settings settings) {
|
||||
this.dataFolder = dataFolder;
|
||||
this.settings = settings;
|
||||
this.defaultFile = createFilePath(DEFAULT_LANGUAGE);
|
||||
}
|
||||
|
||||
|
|
|
@ -1,12 +1,15 @@
|
|||
package fr.xephi.authme.message;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
import java.io.InputStream;
|
||||
import java.io.InputStreamReader;
|
||||
|
||||
|
@ -21,8 +24,9 @@ public class HelpMessagesFileHandler extends AbstractMessageFileHandler {
|
|||
|
||||
private FileConfiguration defaultConfiguration;
|
||||
|
||||
@Inject // Trigger injection in the superclass
|
||||
HelpMessagesFileHandler() {
|
||||
@Inject
|
||||
public HelpMessagesFileHandler(@DataFolder File dataFolder, Settings settings) {
|
||||
super(dataFolder, settings);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1,10 +1,13 @@
|
|||
package fr.xephi.authme.message;
|
||||
|
||||
import fr.xephi.authme.ConsoleLogger;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.message.updater.MessageUpdater;
|
||||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import javax.inject.Inject;
|
||||
import java.io.File;
|
||||
|
||||
import static fr.xephi.authme.message.MessagePathHelper.DEFAULT_LANGUAGE;
|
||||
|
||||
|
@ -15,10 +18,12 @@ public class MessagesFileHandler extends AbstractMessageFileHandler {
|
|||
|
||||
private final ConsoleLogger logger = ConsoleLoggerFactory.get(MessagesFileHandler.class);
|
||||
|
||||
@Inject
|
||||
private MessageUpdater messageUpdater;
|
||||
private final MessageUpdater messageUpdater;
|
||||
|
||||
MessagesFileHandler() {
|
||||
@Inject
|
||||
MessagesFileHandler(@DataFolder File dataFolder, Settings settings, MessageUpdater messageUpdater) {
|
||||
super(dataFolder, settings);
|
||||
this.messageUpdater = messageUpdater;
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -29,18 +29,19 @@ import java.util.Map;
|
|||
*/
|
||||
public class HelpTranslationGenerator {
|
||||
|
||||
@Inject
|
||||
private CommandInitializer commandInitializer;
|
||||
private final CommandInitializer commandInitializer;
|
||||
private final HelpMessagesService helpMessagesService;
|
||||
private final Settings settings;
|
||||
private final File dataFolder;
|
||||
|
||||
@Inject
|
||||
private HelpMessagesService helpMessagesService;
|
||||
|
||||
@Inject
|
||||
private Settings settings;
|
||||
|
||||
@DataFolder
|
||||
@Inject
|
||||
private File dataFolder;
|
||||
HelpTranslationGenerator(CommandInitializer commandInitializer, HelpMessagesService helpMessagesService,
|
||||
Settings settings, @DataFolder File dataFolder) {
|
||||
this.commandInitializer = commandInitializer;
|
||||
this.helpMessagesService = helpMessagesService;
|
||||
this.settings = settings;
|
||||
this.dataFolder = dataFolder;
|
||||
}
|
||||
|
||||
/**
|
||||
* Updates the help file to contain entries for all commands.
|
||||
|
|
|
@ -25,13 +25,12 @@ import org.bukkit.plugin.PluginDescriptionFile;
|
|||
import org.bukkit.plugin.PluginManager;
|
||||
import org.bukkit.plugin.java.JavaPluginLoader;
|
||||
import org.bukkit.scheduler.BukkitScheduler;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
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.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -39,9 +38,9 @@ import java.util.Collections;
|
|||
import java.util.logging.Logger;
|
||||
|
||||
import static fr.xephi.authme.settings.properties.AuthMeSettingsRetriever.buildConfigurationData;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.RETURNS_DEEP_STUBS;
|
||||
|
@ -52,24 +51,18 @@ import static org.mockito.Mockito.verify;
|
|||
* Integration test verifying that all services can be initialized in {@link AuthMe}
|
||||
* with the {@link Injector}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuthMeInitializationTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AuthMeInitializationTest {
|
||||
|
||||
@Mock
|
||||
private Server server;
|
||||
|
||||
@Mock
|
||||
private PluginManager pluginManager;
|
||||
|
||||
private AuthMe authMe;
|
||||
private File dataFolder;
|
||||
@TempDir
|
||||
File dataFolder;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@Before
|
||||
public void initAuthMe() throws IOException {
|
||||
dataFolder = temporaryFolder.newFolder();
|
||||
@BeforeEach
|
||||
void initAuthMe() throws IOException {
|
||||
File settingsFile = new File(dataFolder, "config.yml");
|
||||
given(server.getLogger()).willReturn(Logger.getAnonymousLogger());
|
||||
JavaPluginLoader pluginLoader = new JavaPluginLoader(server);
|
||||
|
@ -77,7 +70,6 @@ public class AuthMeInitializationTest {
|
|||
|
||||
// Mock / wire various Bukkit components
|
||||
ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
|
||||
given(server.getPluginManager()).willReturn(pluginManager);
|
||||
|
||||
// PluginDescriptionFile is final: need to create a sample one
|
||||
PluginDescriptionFile descriptionFile = new PluginDescriptionFile(
|
||||
|
@ -88,13 +80,15 @@ public class AuthMeInitializationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeAllServices() {
|
||||
void shouldInitializeAllServices() {
|
||||
// given
|
||||
PropertyReader reader = mock(PropertyReader.class);
|
||||
PropertyResource resource = mock(PropertyResource.class);
|
||||
given(resource.createReader()).willReturn(reader);
|
||||
Settings settings = new Settings(dataFolder, resource, null, buildConfigurationData());
|
||||
|
||||
PluginManager pluginManager = mock(PluginManager.class);
|
||||
given(server.getPluginManager()).willReturn(pluginManager);
|
||||
TestHelper.setupLogger();
|
||||
|
||||
Injector injector = new InjectorBuilder()
|
||||
|
@ -128,7 +122,7 @@ public class AuthMeInitializationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandlePrematureShutdownGracefully() {
|
||||
void shouldHandlePrematureShutdownGracefully() {
|
||||
// given
|
||||
BukkitScheduler scheduler = mock(BukkitScheduler.class);
|
||||
given(server.getScheduler()).willReturn(scheduler);
|
||||
|
|
|
@ -16,7 +16,7 @@ import fr.xephi.authme.security.crypts.Whirlpool;
|
|||
import fr.xephi.authme.util.expiring.ExpiringMap;
|
||||
import fr.xephi.authme.util.expiring.ExpiringSet;
|
||||
import fr.xephi.authme.util.expiring.TimedCounter;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.lang.reflect.Field;
|
||||
|
@ -32,14 +32,14 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Contains consistency tests across all AuthMe classes.
|
||||
*/
|
||||
public class ClassesConsistencyTest {
|
||||
class ClassesConsistencyTest {
|
||||
|
||||
/** Contains all production classes. */
|
||||
private static final List<Class<?>> ALL_CLASSES =
|
||||
|
@ -71,7 +71,7 @@ public class ClassesConsistencyTest {
|
|||
* Checks that there aren't two classes with the same name; this is confusing and should be avoided.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotHaveSameName() {
|
||||
void shouldNotHaveSameName() {
|
||||
// given
|
||||
Set<String> names = new HashSet<>();
|
||||
|
||||
|
@ -87,7 +87,7 @@ public class ClassesConsistencyTest {
|
|||
* Checks that fields of classes are either private or static final fields of an immutable type.
|
||||
*/
|
||||
@Test
|
||||
public void shouldHaveNonPrivateConstantsOnly() {
|
||||
void shouldHaveNonPrivateConstantsOnly() {
|
||||
// given / when
|
||||
Set<String> invalidFields = ALL_CLASSES.stream()
|
||||
.filter(clz -> !CLASSES_EXCLUDED_FROM_VISIBILITY_TEST.contains(clz))
|
||||
|
@ -145,7 +145,7 @@ public class ClassesConsistencyTest {
|
|||
* interface to regularly clean up expired data.
|
||||
*/
|
||||
@Test
|
||||
public void shouldImplementHasCleanup() {
|
||||
void shouldImplementHasCleanup() {
|
||||
// given / when / then
|
||||
for (Class<?> clazz : ALL_CLASSES) {
|
||||
if (hasExpiringCollectionAsField(clazz) && !EXPIRING_STRUCTURES.contains(clazz)) {
|
||||
|
|
|
@ -2,26 +2,26 @@ package fr.xephi.authme;
|
|||
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Consistency test for the CodeClimate configuration file.
|
||||
*/
|
||||
public class CodeClimateConfigTest {
|
||||
class CodeClimateConfigTest {
|
||||
|
||||
private static final String CONFIG_FILE = ".codeclimate.yml";
|
||||
|
||||
@Test
|
||||
public void shouldHaveExistingClassesInExclusions() {
|
||||
void shouldHaveExistingClassesInExclusions() {
|
||||
// given / when
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(new File(CONFIG_FILE));
|
||||
List<String> excludePaths = configuration.getStringList("exclude_patterns");
|
||||
|
|
|
@ -4,15 +4,14 @@ import fr.xephi.authme.output.LogLevel;
|
|||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.junit.After;
|
||||
import org.junit.AfterClass;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.AfterAll;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.FileWriter;
|
||||
|
@ -22,13 +21,13 @@ import java.nio.file.Files;
|
|||
import java.util.List;
|
||||
import java.util.logging.Logger;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
|
@ -40,23 +39,22 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
/**
|
||||
* Test for {@link ConsoleLogger}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConsoleLoggerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ConsoleLoggerTest {
|
||||
|
||||
private ConsoleLogger consoleLogger;
|
||||
|
||||
@Mock
|
||||
private Logger logger;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
@TempDir
|
||||
File tempFolder;
|
||||
|
||||
private File logFile;
|
||||
|
||||
@Before
|
||||
public void setMockLogger() throws IOException {
|
||||
File folder = temporaryFolder.newFolder();
|
||||
File logFile = new File(folder, "authme.log");
|
||||
@BeforeEach
|
||||
void setMockLogger() throws IOException {
|
||||
File logFile = new File(tempFolder, "authme.log");
|
||||
if (!logFile.createNewFile()) {
|
||||
throw new IOException("Could not create file '" + logFile.getPath() + "'");
|
||||
}
|
||||
|
@ -65,8 +63,8 @@ public class ConsoleLoggerTest {
|
|||
this.consoleLogger = new ConsoleLogger("test");
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeFileHandlers() {
|
||||
@AfterEach
|
||||
void closeFileHandlers() {
|
||||
ConsoleLogger.closeFileWriter();
|
||||
}
|
||||
|
||||
|
@ -75,13 +73,13 @@ public class ConsoleLoggerTest {
|
|||
* is that we no longer enable logging to a file as the log file we've supplied will no longer
|
||||
* be around after this test class has finished.
|
||||
*/
|
||||
@AfterClass
|
||||
public static void resetConsoleToDefault() {
|
||||
@AfterAll
|
||||
static void resetConsoleToDefault() {
|
||||
ConsoleLogger.initializeSharedSettings(newSettings(false, LogLevel.INFO));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogToFile() throws IOException {
|
||||
void shouldLogToFile() throws IOException {
|
||||
// given
|
||||
Settings settings = newSettings(true, LogLevel.FINE);
|
||||
ConsoleLogger.initializeSharedSettings(settings);
|
||||
|
@ -102,7 +100,7 @@ public class ConsoleLoggerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotLogToFile() {
|
||||
void shouldNotLogToFile() {
|
||||
// given
|
||||
Settings settings = newSettings(false, LogLevel.DEBUG);
|
||||
ConsoleLogger.initializeSharedSettings(settings);
|
||||
|
@ -120,9 +118,10 @@ public class ConsoleLoggerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldLogStackTraceToFile() throws IOException {
|
||||
void shouldLogStackTraceToFile() throws IOException {
|
||||
// given
|
||||
Settings settings = newSettings(true, LogLevel.INFO);
|
||||
Settings settings = mock(Settings.class);
|
||||
given(settings.getProperty(SecuritySettings.USE_LOGGING)).willReturn(true);
|
||||
ConsoleLogger.initializeSharedSettings(settings);
|
||||
Exception e = new IllegalStateException("Test exception message");
|
||||
|
||||
|
@ -146,7 +145,7 @@ public class ConsoleLoggerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSupportVariousDebugMethods() throws IOException {
|
||||
void shouldSupportVariousDebugMethods() throws IOException {
|
||||
// given
|
||||
Settings settings = newSettings(true, LogLevel.DEBUG);
|
||||
ConsoleLogger.initializeSharedSettings(settings);
|
||||
|
@ -174,7 +173,7 @@ public class ConsoleLoggerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCloseFileWriterDespiteExceptionOnFlush() throws IOException {
|
||||
void shouldCloseFileWriterDespiteExceptionOnFlush() throws IOException {
|
||||
// given
|
||||
FileWriter fileWriter = mock(FileWriter.class);
|
||||
doThrow(new IOException("Error during flush")).when(fileWriter).flush();
|
||||
|
@ -190,7 +189,7 @@ public class ConsoleLoggerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionOnFileWriterClose() throws IOException {
|
||||
void shouldHandleExceptionOnFileWriterClose() throws IOException {
|
||||
// given
|
||||
FileWriter fileWriter = mock(FileWriter.class);
|
||||
doThrow(new IOException("Cannot close")).when(fileWriter).close();
|
||||
|
|
|
@ -10,7 +10,8 @@ import java.util.ArrayList;
|
|||
import java.util.List;
|
||||
import java.util.Objects;
|
||||
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
|
||||
/**
|
||||
* Matcher which checks with reflection that all fields have the same value.
|
||||
|
|
|
@ -6,6 +6,7 @@ import org.bukkit.entity.Player;
|
|||
import org.mockito.Mockito;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.net.InetAddress;
|
||||
import java.net.InetSocketAddress;
|
||||
import java.net.URI;
|
||||
|
@ -118,4 +119,21 @@ public final class TestHelper {
|
|||
given(settings.getProperty(any(Property.class)))
|
||||
.willAnswer(invocation -> ((Property<?>) invocation.getArgument(0)).getDefaultValue());
|
||||
}
|
||||
|
||||
/**
|
||||
* Creates a file with the given name in the provided folder. Throws an exception if the file
|
||||
* could not be created.
|
||||
*
|
||||
* @param folder the folder to create the file in
|
||||
* @param filename the name of the file to create
|
||||
* @return the created file
|
||||
*/
|
||||
public static File createFile(File folder, String filename) throws IOException {
|
||||
File file = new File(folder, filename);
|
||||
boolean created = file.createNewFile();
|
||||
if (!created) {
|
||||
throw new IllegalStateException("Could not create file '" + filename + "' in " + folder);
|
||||
}
|
||||
return file;
|
||||
}
|
||||
}
|
||||
|
|
|
@ -17,12 +17,12 @@ import org.bukkit.Location;
|
|||
import org.bukkit.Server;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Arrays;
|
||||
|
@ -51,8 +51,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link AuthMeApi}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AuthMeApiTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AuthMeApiTest {
|
||||
|
||||
@InjectMocks
|
||||
private AuthMeApi api;
|
||||
|
@ -73,7 +73,7 @@ public class AuthMeApiTest {
|
|||
private GeoIpService geoIpService;
|
||||
|
||||
@Test
|
||||
public void shouldReturnInstanceOrNull() {
|
||||
void shouldReturnInstanceOrNull() {
|
||||
AuthMeApi result = AuthMeApi.getInstance();
|
||||
assertThat(result, sameInstance(api));
|
||||
|
||||
|
@ -82,7 +82,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIfPlayerIsAuthenticated() {
|
||||
void shouldReturnIfPlayerIsAuthenticated() {
|
||||
// given
|
||||
String name = "Bobby";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -97,7 +97,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIfPlayerIsNpc() {
|
||||
void shouldReturnIfPlayerIsNpc() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.hasMetadata("NPC")).willReturn(true);
|
||||
|
@ -111,7 +111,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIfPlayerIsUnrestricted() {
|
||||
void shouldReturnIfPlayerIsUnrestricted() {
|
||||
// given
|
||||
String name = "Tester";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -126,7 +126,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLastLocation() {
|
||||
void shouldGetLastLocation() {
|
||||
// given
|
||||
String name = "Gary";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -158,7 +158,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLastIp() {
|
||||
void shouldGetLastIp() {
|
||||
// given
|
||||
String name = "Gabriel";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -176,7 +176,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullAsLastIpForUnknownUser() {
|
||||
void shouldReturnNullAsLastIpForUnknownUser() {
|
||||
// given
|
||||
String name = "Harrison";
|
||||
given(playerCache.getAuth(name)).willReturn(null);
|
||||
|
@ -192,7 +192,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLastLogin() {
|
||||
void shouldGetLastLogin() {
|
||||
// given
|
||||
String name = "David";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name)
|
||||
|
@ -209,7 +209,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullLastLogin() {
|
||||
void shouldHandleNullLastLogin() {
|
||||
// given
|
||||
String name = "John";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name)
|
||||
|
@ -226,7 +226,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLastLoginTime() {
|
||||
void shouldGetLastLoginTime() {
|
||||
// given
|
||||
String name = "David";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name)
|
||||
|
@ -243,13 +243,16 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testGetLastLoginMillis() {
|
||||
AuthMeApi result = AuthMeApi.getInstance();
|
||||
assertThat(result.getLastLoginTime("notAPlayer"), nullValue());
|
||||
void shouldReturnNullLastLoginForUnknownPlayer() {
|
||||
// given / when
|
||||
Instant result = api.getLastLoginTime("notAPlayer");
|
||||
|
||||
// then
|
||||
assertThat(result, nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullLastLoginTime() {
|
||||
void shouldHandleNullLastLoginTime() {
|
||||
// given
|
||||
String name = "John";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name)
|
||||
|
@ -266,7 +269,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullForUnavailablePlayer() {
|
||||
void shouldReturnNullForUnavailablePlayer() {
|
||||
// given
|
||||
String name = "Numan";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -280,7 +283,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckForRegisteredName() {
|
||||
void shouldCheckForRegisteredName() {
|
||||
// given
|
||||
String name = "toaster";
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(true);
|
||||
|
@ -293,7 +296,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCheckPassword() {
|
||||
void shouldCheckPassword() {
|
||||
// given
|
||||
String playerName = "Robert";
|
||||
String password = "someSecretPhrase2983";
|
||||
|
@ -308,7 +311,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAuthNames() {
|
||||
void shouldReturnAuthNames() {
|
||||
// given
|
||||
String[] names = {"bobby", "peter", "elisabeth", "craig"};
|
||||
List<PlayerAuth> auths = Arrays.stream(names)
|
||||
|
@ -324,7 +327,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAuthRealNames() {
|
||||
void shouldReturnAuthRealNames() {
|
||||
// given
|
||||
String[] names = {"Bobby", "peter", "Elisabeth", "CRAIG"};
|
||||
List<PlayerAuth> auths = Arrays.stream(names)
|
||||
|
@ -340,7 +343,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUnregisterPlayer() {
|
||||
void shouldUnregisterPlayer() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String name = "Donald";
|
||||
|
@ -354,7 +357,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUnregisterPlayerByName() {
|
||||
void shouldUnregisterPlayerByName() {
|
||||
// given
|
||||
Server server = mock(Server.class);
|
||||
ReflectionTestUtils.setField(Bukkit.class, null, "server", server);
|
||||
|
@ -370,7 +373,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldChangePassword() {
|
||||
void shouldChangePassword() {
|
||||
// given
|
||||
String name = "Bobby12";
|
||||
String password = "resetPw!";
|
||||
|
@ -383,7 +386,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAuthMeInstance() {
|
||||
void shouldReturnAuthMeInstance() {
|
||||
// given / when
|
||||
AuthMe result = api.getPlugin();
|
||||
|
||||
|
@ -392,7 +395,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnVersion() {
|
||||
void shouldReturnVersion() {
|
||||
// given / when
|
||||
String result = api.getPluginVersion();
|
||||
|
||||
|
@ -401,7 +404,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForceLogin() {
|
||||
void shouldForceLogin() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
|
@ -413,7 +416,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForceLogout() {
|
||||
void shouldForceLogout() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
|
@ -425,7 +428,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForceRegister() {
|
||||
void shouldForceRegister() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String pass = "test235";
|
||||
|
@ -439,7 +442,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForceRegisterAndNotAutoLogin() {
|
||||
void shouldForceRegisterAndNotAutoLogin() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String pass = "test235";
|
||||
|
@ -453,7 +456,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRegisterPlayer() {
|
||||
void shouldRegisterPlayer() {
|
||||
// given
|
||||
String name = "Marco";
|
||||
String password = "myP4ss";
|
||||
|
@ -475,7 +478,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRegisterAlreadyRegisteredPlayer() {
|
||||
void shouldNotRegisterAlreadyRegisteredPlayer() {
|
||||
// given
|
||||
String name = "jonah";
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(true);
|
||||
|
@ -490,7 +493,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetNamesByIp() {
|
||||
void shouldGetNamesByIp() {
|
||||
// given
|
||||
String ip = "123.123.123.123";
|
||||
List<String> names = Arrays.asList("Morgan", "Batista", "QUINN");
|
||||
|
@ -505,7 +508,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnGeoIpInfo() {
|
||||
void shouldReturnGeoIpInfo() {
|
||||
// given
|
||||
String ip = "127.127.12.1";
|
||||
given(geoIpService.getCountryCode(ip)).willReturn("XA");
|
||||
|
@ -521,7 +524,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAuthMePlayerInfo() {
|
||||
void shouldReturnAuthMePlayerInfo() {
|
||||
// given
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name("bobb")
|
||||
|
@ -540,7 +543,7 @@ public class AuthMeApiTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullForNonExistentAuth() {
|
||||
void shouldReturnNullForNonExistentAuth() {
|
||||
// given / when
|
||||
Optional<AuthMePlayer> result = api.getPlayerInfo("doesNotExist");
|
||||
|
||||
|
|
|
@ -4,7 +4,7 @@ import fr.xephi.authme.data.auth.PlayerAuth;
|
|||
import org.hamcrest.Description;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.hamcrest.TypeSafeMatcher;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.time.Instant;
|
||||
import java.util.Optional;
|
||||
|
@ -16,16 +16,16 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
/**
|
||||
* Test for {@link AuthMePlayerImpl}.
|
||||
*/
|
||||
public class AuthMePlayerImplTest {
|
||||
class AuthMePlayerImplTest {
|
||||
|
||||
@Test
|
||||
public void shouldMapNullWithoutError() {
|
||||
void shouldMapNullWithoutError() {
|
||||
// given / when / then
|
||||
assertThat(AuthMePlayerImpl.fromPlayerAuth(null), emptyOptional());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapFromPlayerAuth() {
|
||||
void shouldMapFromPlayerAuth() {
|
||||
// given
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name("victor")
|
||||
|
@ -53,7 +53,7 @@ public class AuthMePlayerImplTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullAndDefaultValues() {
|
||||
void shouldHandleNullAndDefaultValues() {
|
||||
// given
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name("victor")
|
||||
|
|
|
@ -3,7 +3,7 @@ package fr.xephi.authme.command;
|
|||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -13,20 +13,20 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
|
||||
import static fr.xephi.authme.TestHelper.getJarFile;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Checks that the commands declared in plugin.yml correspond
|
||||
* to the ones built by the {@link CommandInitializer}.
|
||||
*/
|
||||
public class CommandConsistencyTest {
|
||||
class CommandConsistencyTest {
|
||||
|
||||
@Test
|
||||
public void shouldHaveEqualDefinitions() {
|
||||
void shouldHaveEqualDefinitions() {
|
||||
// given
|
||||
Collection<List<String>> initializedCommands = initializeCommands();
|
||||
Map<String, List<String>> pluginFileLabels = getLabelsFromPluginFile();
|
||||
|
|
|
@ -11,13 +11,13 @@ import fr.xephi.authme.message.MessageKey;
|
|||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
import java.util.Collections;
|
||||
|
@ -30,8 +30,8 @@ import static fr.xephi.authme.command.FoundResultStatus.NO_PERMISSION;
|
|||
import static fr.xephi.authme.command.FoundResultStatus.SUCCESS;
|
||||
import static fr.xephi.authme.command.FoundResultStatus.UNKNOWN_LABEL;
|
||||
import static java.util.Arrays.asList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
|
@ -51,8 +51,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
// Justification: It's more readable to use asList() everywhere in the test when we often generated two lists where one
|
||||
// often consists of only one element, e.g. myMethod(asList("authme"), asList("my", "args"), ...)
|
||||
@SuppressWarnings("ArraysAsListWithZeroOrOneArgument")
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CommandHandlerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CommandHandlerTest {
|
||||
|
||||
private CommandHandler handler;
|
||||
|
||||
|
@ -69,9 +69,9 @@ public class CommandHandlerTest {
|
|||
|
||||
private Map<Class<? extends ExecutableCommand>, ExecutableCommand> mockedCommands = new HashMap<>();
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initializeCommandMapper() {
|
||||
void initializeCommandMapper() {
|
||||
given(commandMapper.getCommandClasses()).willReturn(Sets.newHashSet(
|
||||
ExecutableCommand.class, TestLoginCommand.class, TestRegisterCommand.class, TestUnregisterCommand.class));
|
||||
setInjectorToMockExecutableCommandClasses();
|
||||
|
@ -105,7 +105,7 @@ public class CommandHandlerTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldCallMappedCommandWithArgs() {
|
||||
void shouldCallMappedCommandWithArgs() {
|
||||
// given
|
||||
String bukkitLabel = "Authme";
|
||||
String[] bukkitArgs = {"Login", "myPass"};
|
||||
|
@ -128,7 +128,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCallExecutableCommandIfNoPermission() {
|
||||
void shouldNotCallExecutableCommandIfNoPermission() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -147,7 +147,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCallExecutableForWrongArguments() {
|
||||
void shouldNotCallExecutableForWrongArguments() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -167,7 +167,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseCustomMessageUponArgumentMismatch() {
|
||||
void shouldUseCustomMessageUponArgumentMismatch() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -190,7 +190,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCallExecutableForWrongArgumentsAndPermissionDenied() {
|
||||
void shouldNotCallExecutableForWrongArgumentsAndPermissionDenied() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -210,7 +210,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCallExecutableForFailedParsing() {
|
||||
void shouldNotCallExecutableForFailedParsing() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -229,7 +229,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCallExecutableForUnknownLabelAndHaveSuggestion() {
|
||||
void shouldNotCallExecutableForUnknownLabelAndHaveSuggestion() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -255,7 +255,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCallExecutableForUnknownLabelAndNotSuggestCommand() {
|
||||
void shouldNotCallExecutableForUnknownLabelAndNotSuggestCommand() {
|
||||
// given
|
||||
String bukkitLabel = "unreg";
|
||||
String[] bukkitArgs = {"testPlayer"};
|
||||
|
@ -278,7 +278,7 @@ public class CommandHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStripWhitespace() {
|
||||
void shouldStripWhitespace() {
|
||||
// given
|
||||
String bukkitLabel = "AuthMe";
|
||||
String[] bukkitArgs = {" ", "", "REGISTER", " ", "testArg", " "};
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package fr.xephi.authme.command;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Collection;
|
||||
|
@ -15,15 +15,15 @@ import java.util.Set;
|
|||
import java.util.function.BiConsumer;
|
||||
import java.util.regex.Pattern;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandInitializer} to guarantee the integrity of the defined commands.
|
||||
*/
|
||||
public class CommandInitializerTest {
|
||||
class CommandInitializerTest {
|
||||
|
||||
/**
|
||||
* Defines the maximum allowed depths for nesting CommandDescription instances.
|
||||
|
@ -33,14 +33,14 @@ public class CommandInitializerTest {
|
|||
|
||||
private static Collection<CommandDescription> commands;
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeCommandCollection() {
|
||||
@BeforeAll
|
||||
static void initializeCommandCollection() {
|
||||
CommandInitializer commandInitializer = new CommandInitializer();
|
||||
commands = commandInitializer.getCommands();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeCommands() {
|
||||
void shouldInitializeCommands() {
|
||||
// given/when/then
|
||||
// It obviously doesn't make sense to test much of the concrete data
|
||||
// that is being initialized; we just want to guarantee with this test
|
||||
|
@ -52,7 +52,7 @@ public class CommandInitializerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotBeNestedExcessively() {
|
||||
void shouldNotBeNestedExcessively() {
|
||||
// given
|
||||
BiConsumer<CommandDescription, Integer> descriptionTester =
|
||||
(command, depth) -> assertThat(depth <= MAX_ALLOWED_DEPTH, equalTo(true));
|
||||
|
@ -63,7 +63,7 @@ public class CommandInitializerTest {
|
|||
|
||||
/** Ensure that all children of a command stored the parent. */
|
||||
@Test
|
||||
public void shouldHaveConnectionBetweenParentAndChild() {
|
||||
void shouldHaveConnectionBetweenParentAndChild() {
|
||||
// given
|
||||
BiConsumer<CommandDescription, Integer> connectionTester = new BiConsumer<CommandDescription, Integer>() {
|
||||
@Override
|
||||
|
@ -84,7 +84,7 @@ public class CommandInitializerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUseProperLowerCaseLabels() {
|
||||
void shouldUseProperLowerCaseLabels() {
|
||||
// given
|
||||
final Pattern invalidPattern = Pattern.compile("\\s");
|
||||
BiConsumer<CommandDescription, Integer> labelFormatTester = new BiConsumer<CommandDescription, Integer>() {
|
||||
|
@ -105,7 +105,7 @@ public class CommandInitializerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotDefineSameLabelTwice() {
|
||||
void shouldNotDefineSameLabelTwice() {
|
||||
// given
|
||||
final Set<String> commandMappings = new HashSet<>();
|
||||
BiConsumer<CommandDescription, Integer> uniqueMappingTester = new BiConsumer<CommandDescription, Integer>() {
|
||||
|
@ -130,7 +130,7 @@ public class CommandInitializerTest {
|
|||
* detailed description should be longer and end with a period.
|
||||
*/
|
||||
@Test
|
||||
public void shouldHaveProperDescription() {
|
||||
void shouldHaveProperDescription() {
|
||||
// given
|
||||
BiConsumer<CommandDescription, Integer> descriptionTester = new BiConsumer<CommandDescription, Integer>() {
|
||||
@Override
|
||||
|
@ -153,7 +153,7 @@ public class CommandInitializerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveOptionalArgumentsAfterMandatoryOnes() {
|
||||
void shouldHaveOptionalArgumentsAfterMandatoryOnes() {
|
||||
// given
|
||||
BiConsumer<CommandDescription, Integer> argumentOrderTester = new BiConsumer<CommandDescription, Integer>() {
|
||||
@Override
|
||||
|
@ -179,7 +179,7 @@ public class CommandInitializerTest {
|
|||
* clash with the label of the child.
|
||||
*/
|
||||
@Test
|
||||
public void shouldNotHaveArgumentsIfCommandHasChildren() {
|
||||
void shouldNotHaveArgumentsIfCommandHasChildren() {
|
||||
// given
|
||||
BiConsumer<CommandDescription, Integer> noArgumentForParentChecker = new BiConsumer<CommandDescription, Integer>() {
|
||||
@Override
|
||||
|
@ -202,7 +202,7 @@ public class CommandInitializerTest {
|
|||
* count of arguments.
|
||||
*/
|
||||
@Test
|
||||
public void shouldPointToSameExecutableCommandWithConsistentArgumentCount() {
|
||||
void shouldPointToSameExecutableCommandWithConsistentArgumentCount() {
|
||||
// given
|
||||
final Map<Class<? extends ExecutableCommand>, Integer> mandatoryArguments = new HashMap<>();
|
||||
final Map<Class<? extends ExecutableCommand>, Integer> totalArguments = new HashMap<>();
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package fr.xephi.authme.command;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.command.TestCommandsUtil.TestLoginCommand;
|
||||
import fr.xephi.authme.command.TestCommandsUtil.TestRegisterCommand;
|
||||
import fr.xephi.authme.command.TestCommandsUtil.TestUnregisterCommand;
|
||||
|
@ -10,10 +7,12 @@ import fr.xephi.authme.command.executable.HelpCommand;
|
|||
import fr.xephi.authme.permission.PermissionNode;
|
||||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
@ -21,28 +20,28 @@ import java.util.Set;
|
|||
import static fr.xephi.authme.command.TestCommandsUtil.getCommandWithLabel;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.ArgumentMatchers.isNull;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandMapper}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class CommandMapperTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CommandMapperTest {
|
||||
|
||||
private static List<CommandDescription> commands;
|
||||
|
||||
@InjectDelayed
|
||||
private CommandMapper mapper;
|
||||
|
||||
@Mock
|
||||
|
@ -51,21 +50,22 @@ public class CommandMapperTest {
|
|||
@Mock
|
||||
private CommandInitializer commandInitializer;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpCommandHandler() {
|
||||
@BeforeAll
|
||||
static void setUpCommandHandler() {
|
||||
commands = TestCommandsUtil.generateCommands();
|
||||
}
|
||||
|
||||
@BeforeInjecting
|
||||
public void setUpMocks() {
|
||||
@BeforeEach
|
||||
void setUpMocksAndMapper() {
|
||||
given(commandInitializer.getCommands()).willReturn(commands);
|
||||
mapper = new CommandMapper(commandInitializer, permissionsManager);
|
||||
}
|
||||
|
||||
// -----------
|
||||
// mapPartsToCommand() tests
|
||||
// -----------
|
||||
@Test
|
||||
public void shouldMapPartsToLoginChildCommand() {
|
||||
void shouldMapPartsToLoginChildCommand() {
|
||||
// given
|
||||
List<String> parts = asList("authme", "login", "test1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -84,7 +84,7 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapPartsToCommandWithNoCaseSensitivity() {
|
||||
void shouldMapPartsToCommandWithNoCaseSensitivity() {
|
||||
// given
|
||||
List<String> parts = asList("Authme", "REG", "arg1", "arg2");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -102,16 +102,16 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectCommandWithTooManyArguments() {
|
||||
void shouldRejectCommandWithTooManyArguments() {
|
||||
// given
|
||||
List<String> parts = asList("authme", "register", "pass123", "pass123", "pass123");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "authme", "register")));
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
|
||||
assertThat(result.getDifference(), equalTo(0.0));
|
||||
|
@ -120,16 +120,16 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectCommandWithTooFewArguments() {
|
||||
void shouldRejectCommandWithTooFewArguments() {
|
||||
// given
|
||||
List<String> parts = asList("authme", "Reg");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "authme", "register")));
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
|
||||
assertThat(result.getDifference(), equalTo(0.0));
|
||||
|
@ -138,16 +138,16 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSuggestCommandWithSimilarLabel() {
|
||||
void shouldSuggestCommandWithSimilarLabel() {
|
||||
// given
|
||||
List<String> parts = asList("authme", "reh", "pass123", "pass123");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "authme", "register")));
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.UNKNOWN_LABEL));
|
||||
assertThat(result.getDifference() < 0.75, equalTo(true));
|
||||
|
@ -157,16 +157,16 @@ public class CommandMapperTest {
|
|||
|
||||
/** In contrast to the previous test, we test a command request with a very apart label. */
|
||||
@Test
|
||||
public void shouldSuggestMostSimilarCommand() {
|
||||
void shouldSuggestMostSimilarCommand() {
|
||||
// given
|
||||
List<String> parts = asList("authme", "asdfawetawty4asdca");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getCommandDescription(), not(nullValue()));
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.UNKNOWN_LABEL));
|
||||
assertThat(result.getDifference() > 0.75, equalTo(true));
|
||||
|
@ -175,16 +175,16 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleBaseWithWrongArguments() {
|
||||
void shouldHandleBaseWithWrongArguments() {
|
||||
// given
|
||||
List<String> parts = singletonList("unregister");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
|
||||
assertThat(result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "unregister")));
|
||||
assertThat(result.getDifference(), equalTo(0.0));
|
||||
|
@ -193,22 +193,22 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnknownBase() {
|
||||
void shouldHandleUnknownBase() {
|
||||
// given
|
||||
List<String> parts = asList("bogus", "label1", "arg1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.MISSING_BASE_COMMAND));
|
||||
assertThat(result.getCommandDescription(), nullValue());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullInput() {
|
||||
void shouldHandleNullInput() {
|
||||
// given / when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(mock(CommandSender.class), null);
|
||||
|
||||
|
@ -218,7 +218,7 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldMapToBaseWithProperArguments() {
|
||||
void shouldMapToBaseWithProperArguments() {
|
||||
// given
|
||||
List<String> parts = asList("Unreg", "player1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -236,16 +236,16 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnChildlessBaseCommandWithArgCountError() {
|
||||
void shouldReturnChildlessBaseCommandWithArgCountError() {
|
||||
// given
|
||||
List<String> parts = asList("unregistER", "player1", "wrongArg");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(true);
|
||||
|
||||
// when
|
||||
FoundCommandResult result = mapper.mapPartsToCommand(sender, parts);
|
||||
|
||||
// then
|
||||
verifyNoInteractions(permissionsManager);
|
||||
assertThat(result.getResultStatus(), equalTo(FoundResultStatus.INCORRECT_ARGUMENTS));
|
||||
assertThat(result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "unregister")));
|
||||
assertThat(result.getDifference(), equalTo(0.0));
|
||||
|
@ -254,7 +254,7 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPassCommandPathAsArgumentsToHelpCommand() {
|
||||
void shouldPassCommandPathAsArgumentsToHelpCommand() {
|
||||
// given
|
||||
List<String> parts = asList("email", "helptest", "arg1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -272,7 +272,7 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRecognizeMissingPermissionForCommand() {
|
||||
void shouldRecognizeMissingPermissionForCommand() {
|
||||
// given
|
||||
List<String> parts = asList("authme", "login", "test1");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -291,7 +291,7 @@ public class CommandMapperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSupportAuthMePrefix() {
|
||||
void shouldSupportAuthMePrefix() {
|
||||
// given
|
||||
List<String> parts = asList("authme:unregister", "Betty");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -305,9 +305,8 @@ public class CommandMapperTest {
|
|||
assertThat(result.getCommandDescription(), equalTo(getCommandWithLabel(commands, "unregister")));
|
||||
}
|
||||
|
||||
@SuppressWarnings("unchecked")
|
||||
@Test
|
||||
public void shouldReturnExecutableCommandClasses() {
|
||||
void shouldReturnExecutableCommandClasses() {
|
||||
// given / when
|
||||
Set<Class<? extends ExecutableCommand>> commandClasses = mapper.getCommandClasses();
|
||||
|
||||
|
|
|
@ -1,31 +1,31 @@
|
|||
package fr.xephi.authme.command;
|
||||
|
||||
import org.bukkit.ChatColor;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link CommandUtils}.
|
||||
*/
|
||||
public class CommandUtilsTest {
|
||||
class CommandUtilsTest {
|
||||
|
||||
private static Collection<CommandDescription> commands;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpTestCommands() {
|
||||
@BeforeAll
|
||||
static void setUpTestCommands() {
|
||||
commands = Collections.unmodifiableCollection(TestCommandsUtil.generateCommands());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnCommandPath() {
|
||||
void shouldReturnCommandPath() {
|
||||
// given
|
||||
CommandDescription base = CommandDescription.builder()
|
||||
.labels("authme", "auth")
|
||||
|
@ -49,7 +49,7 @@ public class CommandUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldComputeMinAndMaxOnEmptyCommand() {
|
||||
void shouldComputeMinAndMaxOnEmptyCommand() {
|
||||
// given
|
||||
CommandDescription command = getBuilderForArgsTest().register();
|
||||
|
||||
|
@ -58,7 +58,7 @@ public class CommandUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldComputeMinAndMaxOnCommandWithMandatoryArgs() {
|
||||
void shouldComputeMinAndMaxOnCommandWithMandatoryArgs() {
|
||||
// given
|
||||
CommandDescription command = getBuilderForArgsTest()
|
||||
.withArgument("Test", "Arg description", false)
|
||||
|
@ -70,7 +70,7 @@ public class CommandUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldComputeMinAndMaxOnCommandIncludingOptionalArgs() {
|
||||
void shouldComputeMinAndMaxOnCommandIncludingOptionalArgs() {
|
||||
// given
|
||||
CommandDescription command = getBuilderForArgsTest()
|
||||
.withArgument("arg1", "Arg description", false)
|
||||
|
@ -83,7 +83,7 @@ public class CommandUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormatSimpleArgument() {
|
||||
void shouldFormatSimpleArgument() {
|
||||
// given
|
||||
CommandDescription command = TestCommandsUtil.getCommandWithLabel(commands, "authme");
|
||||
List<String> labels = Collections.singletonList("authme");
|
||||
|
@ -96,7 +96,7 @@ public class CommandUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormatCommandWithMultipleArguments() {
|
||||
void shouldFormatCommandWithMultipleArguments() {
|
||||
// given
|
||||
CommandDescription command = TestCommandsUtil.getCommandWithLabel(commands, "authme", "register");
|
||||
List<String> labels = Arrays.asList("authme", "reg");
|
||||
|
@ -110,7 +110,7 @@ public class CommandUtilsTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldFormatCommandWithOptionalArgument() {
|
||||
void shouldFormatCommandWithOptionalArgument() {
|
||||
// given
|
||||
CommandDescription command = TestCommandsUtil.getCommandWithLabel(commands, "email");
|
||||
List<String> labels = Collections.singletonList("email");
|
||||
|
|
|
@ -3,7 +3,7 @@ package fr.xephi.authme.command;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -18,10 +18,10 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link PlayerCommand}.
|
||||
*/
|
||||
public class PlayerCommandTest {
|
||||
class PlayerCommandTest {
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
void shouldRejectNonPlayerSender() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
PlayerCommandImpl command = new PlayerCommandImpl();
|
||||
|
@ -34,7 +34,7 @@ public class PlayerCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCallRunCommandForPlayer() {
|
||||
void shouldCallRunCommandForPlayer() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
List<String> arguments = Arrays.asList("arg1", "testarg2");
|
||||
|
@ -48,7 +48,7 @@ public class PlayerCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerAndSendAlternative() {
|
||||
void shouldRejectNonPlayerAndSendAlternative() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerCommandWithAlt command = new PlayerCommandWithAlt();
|
||||
|
|
|
@ -6,12 +6,12 @@ import fr.xephi.authme.command.FoundCommandResult;
|
|||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
@ -26,8 +26,8 @@ import static fr.xephi.authme.command.help.HelpProvider.SHOW_COMMAND;
|
|||
import static fr.xephi.authme.command.help.HelpProvider.SHOW_DESCRIPTION;
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.singletonList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -39,8 +39,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link HelpCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HelpCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HelpCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private HelpCommand command;
|
||||
|
@ -52,7 +52,7 @@ public class HelpCommandTest {
|
|||
private HelpProvider helpProvider;
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingBaseCommand() {
|
||||
void shouldHandleMissingBaseCommand() {
|
||||
// given
|
||||
List<String> arguments = asList("some", "command");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -68,7 +68,7 @@ public class HelpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleWrongCommandWithSuggestion() {
|
||||
void shouldHandleWrongCommandWithSuggestion() {
|
||||
// given
|
||||
List<String> arguments = asList("authme", "ragister", "test");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -88,7 +88,7 @@ public class HelpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleWrongCommandWithoutSuggestion() {
|
||||
void shouldHandleWrongCommandWithoutSuggestion() {
|
||||
List<String> arguments = asList("authme", "ragister", "test");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
FoundCommandResult foundCommandResult = new FoundCommandResult(null, asList("authme", "ragister"),
|
||||
|
@ -106,7 +106,7 @@ public class HelpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowChildrenOfBaseCommand() {
|
||||
void shouldShowChildrenOfBaseCommand() {
|
||||
List<String> arguments = singletonList("authme");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription commandDescription = mock(CommandDescription.class);
|
||||
|
@ -125,7 +125,7 @@ public class HelpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowDetailedHelpForChildCommand() {
|
||||
void shouldShowDetailedHelpForChildCommand() {
|
||||
List<String> arguments = asList("authme", "getpos");
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
CommandDescription commandDescription = mock(CommandDescription.class);
|
||||
|
|
|
@ -6,20 +6,20 @@ import fr.xephi.authme.message.MessageKey;
|
|||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskAsynchronously;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -30,8 +30,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link AccountsCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AccountsCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AccountsCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private AccountsCommand command;
|
||||
|
@ -43,7 +43,7 @@ public class AccountsCommandTest {
|
|||
private BukkitService bukkitService;
|
||||
|
||||
@Test
|
||||
public void shouldGetAccountsOfCurrentUser() {
|
||||
void shouldGetAccountsOfCurrentUser() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(sender.getName()).willReturn("Tester");
|
||||
|
@ -62,7 +62,7 @@ public class AccountsCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnUnknownUserForNullAuth() {
|
||||
void shouldReturnUnknownUserForNullAuth() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
|
@ -78,7 +78,7 @@ public class AccountsCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnUnregisteredMessageForEmptyAuthList() {
|
||||
void shouldReturnUnregisteredMessageForEmptyAuthList() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
|
@ -95,7 +95,7 @@ public class AccountsCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSingleAccountMessage() {
|
||||
void shouldReturnSingleAccountMessage() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("SomeUser");
|
||||
|
@ -115,7 +115,7 @@ public class AccountsCommandTest {
|
|||
// Query by IP
|
||||
// -----
|
||||
@Test
|
||||
public void shouldReturnIpUnknown() {
|
||||
void shouldReturnIpUnknown() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("123.45.67.89");
|
||||
|
@ -131,7 +131,7 @@ public class AccountsCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSingleAccountForIpQuery() {
|
||||
void shouldReturnSingleAccountForIpQuery() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("24.24.48.48");
|
||||
|
@ -147,7 +147,7 @@ public class AccountsCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAccountListForIpQuery() {
|
||||
void shouldReturnAccountListForIpQuery() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
List<String> arguments = Collections.singletonList("98.76.41.122");
|
||||
|
|
|
@ -2,13 +2,13 @@ package fr.xephi.authme.command.executable.authme;
|
|||
|
||||
import fr.xephi.authme.command.ExecutableCommand;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -16,10 +16,10 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link AuthMeCommand}.
|
||||
*/
|
||||
public class AuthMeCommandTest {
|
||||
class AuthMeCommandTest {
|
||||
|
||||
@Test
|
||||
public void shouldDisplayInformation() {
|
||||
void shouldDisplayInformation() {
|
||||
// given
|
||||
ExecutableCommand command = new AuthMeCommand();
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
|
|
@ -2,11 +2,11 @@ package fr.xephi.authme.command.executable.authme;
|
|||
|
||||
import fr.xephi.authme.service.BackupService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -16,8 +16,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link BackupCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class BackupCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class BackupCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private BackupCommand command;
|
||||
|
@ -26,7 +26,7 @@ public class BackupCommandTest {
|
|||
private BackupService backupService;
|
||||
|
||||
@Test
|
||||
public void shouldStartBackup() {
|
||||
void shouldStartBackup() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
|
|
@ -6,11 +6,11 @@ import fr.xephi.authme.service.CommonService;
|
|||
import fr.xephi.authme.service.ValidationService;
|
||||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Arrays;
|
||||
|
||||
|
@ -22,8 +22,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link ChangePasswordAdminCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ChangePasswordAdminCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ChangePasswordAdminCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ChangePasswordAdminCommand command;
|
||||
|
@ -38,7 +38,7 @@ public class ChangePasswordAdminCommandTest {
|
|||
private Management management;
|
||||
|
||||
@Test
|
||||
public void shouldForwardRequestToManagement() {
|
||||
void shouldForwardRequestToManagement() {
|
||||
// given
|
||||
String name = "theUser";
|
||||
String pass = "newPassword";
|
||||
|
@ -54,7 +54,7 @@ public class ChangePasswordAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendErrorToCommandSender() {
|
||||
void shouldSendErrorToCommandSender() {
|
||||
// given
|
||||
String name = "theUser";
|
||||
String pass = "newPassword";
|
||||
|
|
|
@ -8,12 +8,12 @@ import fr.xephi.authme.service.BukkitService;
|
|||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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 java.util.HashSet;
|
||||
|
@ -22,9 +22,9 @@ import java.util.Map;
|
|||
import java.util.Set;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskAsynchronously;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.doThrow;
|
||||
|
@ -37,8 +37,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link ConverterCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConverterCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ConverterCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ConverterCommand command;
|
||||
|
@ -52,13 +52,13 @@ public class ConverterCommandTest {
|
|||
@Mock
|
||||
private Factory<Converter> converterFactory;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
@BeforeAll
|
||||
static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnknownConversionType() {
|
||||
void shouldHandleUnknownConversionType() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -72,7 +72,7 @@ public class ConverterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleCommandWithNoArgs() {
|
||||
void shouldHandleCommandWithNoArgs() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -86,7 +86,7 @@ public class ConverterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveUniqueClassForEachConverter() {
|
||||
void shouldHaveUniqueClassForEachConverter() {
|
||||
// given
|
||||
Set<Class<? extends Converter>> classes = new HashSet<>();
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class ConverterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldLaunchConverterForAllTypes() {
|
||||
void shouldLaunchConverterForAllTypes() {
|
||||
// given
|
||||
String converterName = "rakamak";
|
||||
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||
|
@ -120,7 +120,7 @@ public class ConverterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCatchExceptionInConverterAndInformSender() {
|
||||
void shouldCatchExceptionInConverterAndInformSender() {
|
||||
// given
|
||||
String converterName = "vauth";
|
||||
Class<? extends Converter> converterClass = ConverterCommand.CONVERTERS.get(converterName);
|
||||
|
|
|
@ -3,11 +3,11 @@ package fr.xephi.authme.command.executable.authme;
|
|||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -23,8 +23,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link FirstSpawnCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class FirstSpawnCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class FirstSpawnCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private FirstSpawnCommand command;
|
||||
|
@ -33,7 +33,7 @@ public class FirstSpawnCommandTest {
|
|||
private SpawnLoader spawnLoader;
|
||||
|
||||
@Test
|
||||
public void shouldTeleportToFirstSpawn() {
|
||||
void shouldTeleportToFirstSpawn() {
|
||||
// given
|
||||
Location firstSpawn = mock(Location.class);
|
||||
given(spawnLoader.getFirstSpawn()).willReturn(firstSpawn);
|
||||
|
@ -48,7 +48,7 @@ public class FirstSpawnCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingFirstSpawn() {
|
||||
void shouldHandleMissingFirstSpawn() {
|
||||
// given
|
||||
given(spawnLoader.getFirstSpawn()).willReturn(null);
|
||||
Player player = mock(Player.class);
|
||||
|
|
|
@ -6,11 +6,11 @@ import fr.xephi.authme.process.Management;
|
|||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -24,8 +24,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link ForceLoginCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ForceLoginCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ForceLoginCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ForceLoginCommand command;
|
||||
|
@ -40,7 +40,7 @@ public class ForceLoginCommandTest {
|
|||
private BukkitService bukkitService;
|
||||
|
||||
@Test
|
||||
public void shouldRejectOfflinePlayer() {
|
||||
void shouldRejectOfflinePlayer() {
|
||||
// given
|
||||
String playerName = "Bobby";
|
||||
Player player = mockPlayer(false);
|
||||
|
@ -57,7 +57,7 @@ public class ForceLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInexistentPlayer() {
|
||||
void shouldRejectInexistentPlayer() {
|
||||
// given
|
||||
String playerName = "us3rname01";
|
||||
given(bukkitService.getPlayerExact(playerName)).willReturn(null);
|
||||
|
@ -73,7 +73,7 @@ public class ForceLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectPlayerWithMissingPermission() {
|
||||
void shouldRejectPlayerWithMissingPermission() {
|
||||
// given
|
||||
String playerName = "testTest";
|
||||
Player player = mockPlayer(true);
|
||||
|
@ -91,7 +91,7 @@ public class ForceLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForceLoginPlayer() {
|
||||
void shouldForceLoginPlayer() {
|
||||
// given
|
||||
String playerName = "tester23";
|
||||
Player player = mockPlayer(true);
|
||||
|
@ -108,7 +108,7 @@ public class ForceLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForceLoginSenderSelf() {
|
||||
void shouldForceLoginSenderSelf() {
|
||||
// given
|
||||
String senderName = "tester23";
|
||||
Player player = mockPlayer(true);
|
||||
|
|
|
@ -5,11 +5,11 @@ import fr.xephi.authme.datasource.DataSource;
|
|||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -22,8 +22,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link GetEmailCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GetEmailCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class GetEmailCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private GetEmailCommand command;
|
||||
|
@ -35,7 +35,7 @@ public class GetEmailCommandTest {
|
|||
private CommonService service;
|
||||
|
||||
@Test
|
||||
public void shouldReportUnknownUser() {
|
||||
void shouldReportUnknownUser() {
|
||||
// given
|
||||
String user = "myTestUser";
|
||||
given(dataSource.getEmail(user)).willReturn(DataSourceValueImpl.unknownRow());
|
||||
|
@ -49,7 +49,7 @@ public class GetEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnEmail() {
|
||||
void shouldReturnEmail() {
|
||||
// given
|
||||
String user = "userToView";
|
||||
String email = "user.email@example.org";
|
||||
|
|
|
@ -6,11 +6,11 @@ import fr.xephi.authme.datasource.DataSource;
|
|||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -26,8 +26,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link GetIpCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class GetIpCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class GetIpCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private GetIpCommand command;
|
||||
|
@ -40,7 +40,7 @@ public class GetIpCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldGetIpOfPlayer() {
|
||||
void shouldGetIpOfPlayer() {
|
||||
// given
|
||||
given(bukkitService.getPlayerExact(anyString())).willReturn(null);
|
||||
given(dataSource.getAuth(anyString())).willReturn(null);
|
||||
|
@ -57,7 +57,7 @@ public class GetIpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnIpAddressOfPlayer() {
|
||||
void shouldReturnIpAddressOfPlayer() {
|
||||
// given
|
||||
String playerName = "charlie";
|
||||
String ip = "123.34.56.88";
|
||||
|
@ -78,7 +78,7 @@ public class GetIpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnregisteredOnlinePlayer() {
|
||||
void shouldHandleUnregisteredOnlinePlayer() {
|
||||
// given
|
||||
String playerName = "Test";
|
||||
String ip = "44.111.22.33";
|
||||
|
|
|
@ -5,19 +5,19 @@ import fr.xephi.authme.datasource.DataSource;
|
|||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Date;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.allOf;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.times;
|
||||
|
@ -26,8 +26,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link LastLoginCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LastLoginCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class LastLoginCommandTest {
|
||||
|
||||
private static final long HOUR_IN_MSEC = 3600 * 1000;
|
||||
private static final long DAY_IN_MSEC = 24 * HOUR_IN_MSEC;
|
||||
|
@ -43,7 +43,7 @@ public class LastLoginCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonExistentUser() {
|
||||
void shouldRejectNonExistentUser() {
|
||||
// given
|
||||
String player = "tester";
|
||||
given(dataSource.getAuth(player)).willReturn(null);
|
||||
|
@ -58,7 +58,7 @@ public class LastLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDisplayLastLoginOfUser() {
|
||||
void shouldDisplayLastLoginOfUser() {
|
||||
// given
|
||||
String player = "SomePlayer";
|
||||
long lastLogin = System.currentTimeMillis() -
|
||||
|
@ -84,7 +84,7 @@ public class LastLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDisplayLastLoginOfCommandSender() {
|
||||
void shouldDisplayLastLoginOfCommandSender() {
|
||||
// given
|
||||
String name = "CommandSender";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -112,7 +112,7 @@ public class LastLoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullLastLoginDate() {
|
||||
void shouldHandleNullLastLoginDate() {
|
||||
// given
|
||||
String name = "player";
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
|
|
|
@ -4,11 +4,11 @@ import fr.xephi.authme.service.BukkitService;
|
|||
import fr.xephi.authme.task.purge.PurgeService;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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 java.util.HashSet;
|
||||
|
@ -26,8 +26,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link PurgeBannedPlayersCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PurgeBannedPlayersCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PurgeBannedPlayersCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private PurgeBannedPlayersCommand command;
|
||||
|
@ -39,7 +39,7 @@ public class PurgeBannedPlayersCommandTest {
|
|||
private BukkitService bukkitService;
|
||||
|
||||
@Test
|
||||
public void shouldForwardRequestToService() {
|
||||
void shouldForwardRequestToService() {
|
||||
// given
|
||||
String[] names = {"bannedPlayer", "other_banned", "evilplayer", "Someone"};
|
||||
OfflinePlayer[] players = offlinePlayersWithNames(names);
|
||||
|
|
|
@ -2,20 +2,20 @@ package fr.xephi.authme.command.executable.authme;
|
|||
|
||||
import fr.xephi.authme.task.purge.PurgeService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -25,8 +25,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link PurgeCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PurgeCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PurgeCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private PurgeCommand command;
|
||||
|
@ -35,7 +35,7 @@ public class PurgeCommandTest {
|
|||
private PurgeService purgeService;
|
||||
|
||||
@Test
|
||||
public void shouldHandleInvalidNumber() {
|
||||
void shouldHandleInvalidNumber() {
|
||||
// given
|
||||
String interval = "invalid";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -49,7 +49,7 @@ public class PurgeCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectTooSmallInterval() {
|
||||
void shouldRejectTooSmallInterval() {
|
||||
// given
|
||||
String interval = "29";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -63,7 +63,7 @@ public class PurgeCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardToService() {
|
||||
void shouldForwardToService() {
|
||||
// given
|
||||
String interval = "45";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
|
|
@ -6,11 +6,11 @@ import fr.xephi.authme.message.MessageKey;
|
|||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.bungeecord.BungeeSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -24,8 +24,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link PurgeLastPositionCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PurgeLastPositionCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PurgeLastPositionCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private PurgeLastPositionCommand command;
|
||||
|
@ -40,7 +40,7 @@ public class PurgeLastPositionCommandTest {
|
|||
private BungeeSender bungeeSender;
|
||||
|
||||
@Test
|
||||
public void shouldPurgeLastPosOfUser() {
|
||||
void shouldPurgeLastPosOfUser() {
|
||||
// given
|
||||
String player = "_Bobby";
|
||||
PlayerAuth auth = mock(PlayerAuth.class);
|
||||
|
@ -57,7 +57,7 @@ public class PurgeLastPositionCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPurgePositionOfCommandSender() {
|
||||
void shouldPurgePositionOfCommandSender() {
|
||||
// given
|
||||
String player = "_Bobby";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -75,7 +75,7 @@ public class PurgeLastPositionCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNonExistentUser() {
|
||||
void shouldHandleNonExistentUser() {
|
||||
// given
|
||||
String name = "invalidPlayer";
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -89,7 +89,7 @@ public class PurgeLastPositionCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldResetAllLastPositions() {
|
||||
void shouldResetAllLastPositions() {
|
||||
// given
|
||||
PlayerAuth auth1 = mock(PlayerAuth.class);
|
||||
PlayerAuth auth2 = mock(PlayerAuth.class);
|
||||
|
|
|
@ -5,11 +5,11 @@ import fr.xephi.authme.service.BukkitService;
|
|||
import fr.xephi.authme.task.purge.PurgeExecutor;
|
||||
import org.bukkit.OfflinePlayer;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Locale;
|
||||
|
||||
|
@ -27,8 +27,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link PurgePlayerCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PurgePlayerCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PurgePlayerCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private PurgePlayerCommand command;
|
||||
|
@ -43,7 +43,7 @@ public class PurgePlayerCommandTest {
|
|||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void shouldNotExecutePurgeForRegisteredPlayer() {
|
||||
void shouldNotExecutePurgeForRegisteredPlayer() {
|
||||
// given
|
||||
String name = "Bobby";
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(true);
|
||||
|
@ -59,7 +59,7 @@ public class PurgePlayerCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecutePurge() {
|
||||
void shouldExecutePurge() {
|
||||
// given
|
||||
String name = "Frank";
|
||||
given(dataSource.isAuthAvailable(name)).willReturn(false);
|
||||
|
@ -77,7 +77,7 @@ public class PurgePlayerCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldExecutePurgeOfRegisteredPlayer() {
|
||||
void shouldExecutePurgeOfRegisteredPlayer() {
|
||||
// given
|
||||
String name = "GhiJKlmn7";
|
||||
OfflinePlayer player = mock(OfflinePlayer.class);
|
||||
|
|
|
@ -3,12 +3,12 @@ package fr.xephi.authme.command.executable.authme;
|
|||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.Spy;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.time.ZoneId;
|
||||
import java.util.Arrays;
|
||||
|
@ -25,8 +25,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link RecentPlayersCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RecentPlayersCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RecentPlayersCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
@Spy
|
||||
|
@ -36,7 +36,7 @@ public class RecentPlayersCommandTest {
|
|||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void shouldShowRecentPlayers() {
|
||||
void shouldShowRecentPlayers() {
|
||||
// given
|
||||
PlayerAuth auth1 = PlayerAuth.builder()
|
||||
.name("hannah").realName("Hannah").lastIp("11.11.11.11")
|
||||
|
@ -61,7 +61,7 @@ public class RecentPlayersCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandlePlayerWithNullLastLogin() {
|
||||
void shouldHandlePlayerWithNullLastLogin() {
|
||||
// given
|
||||
PlayerAuth auth1 = PlayerAuth.builder()
|
||||
.name("xephren").realName("Xephren").lastIp("11.11.11.11")
|
||||
|
|
|
@ -12,21 +12,21 @@ import fr.xephi.authme.service.ValidationService;
|
|||
import fr.xephi.authme.service.ValidationService.ValidationResult;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
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.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Locale;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskOptionallyAsync;
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToScheduleSyncTaskFromOptionallyAsyncTask;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -36,8 +36,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link RegisterAdminCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RegisterAdminCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RegisterAdminCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private RegisterAdminCommand command;
|
||||
|
@ -57,13 +57,13 @@ public class RegisterAdminCommandTest {
|
|||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidPassword() {
|
||||
void shouldRejectInvalidPassword() {
|
||||
// given
|
||||
String user = "tester";
|
||||
String password = "myPassword";
|
||||
|
@ -81,7 +81,7 @@ public class RegisterAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectAlreadyRegisteredAccount() {
|
||||
void shouldRejectAlreadyRegisteredAccount() {
|
||||
// given
|
||||
String user = "my_name55";
|
||||
String password = "@some-pass@";
|
||||
|
@ -100,7 +100,7 @@ public class RegisterAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleSavingError() {
|
||||
void shouldHandleSavingError() {
|
||||
// given
|
||||
String user = "test-test";
|
||||
String password = "afdjhfkt";
|
||||
|
@ -124,7 +124,7 @@ public class RegisterAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRegisterOfflinePlayer() {
|
||||
void shouldRegisterOfflinePlayer() {
|
||||
// given
|
||||
String user = "someone";
|
||||
String password = "Al1O3P49S5%";
|
||||
|
@ -149,7 +149,7 @@ public class RegisterAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRegisterOnlinePlayer() {
|
||||
void shouldRegisterOnlinePlayer() {
|
||||
// given
|
||||
String user = "someone";
|
||||
String password = "Al1O3P49S5%";
|
||||
|
|
|
@ -16,13 +16,13 @@ import fr.xephi.authme.settings.properties.DatabaseSettings;
|
|||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -38,8 +38,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link ReloadCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ReloadCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ReloadCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ReloadCommand command;
|
||||
|
@ -65,20 +65,20 @@ public class ReloadCommandTest {
|
|||
@Mock
|
||||
private SingletonStore<SettingsDependent> settingsDependentStore;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void setDefaultSettings() {
|
||||
@BeforeEach
|
||||
void setDefaultSettings() {
|
||||
// Mock properties retrieved by ConsoleLogger
|
||||
given(settings.getProperty(PluginSettings.LOG_LEVEL)).willReturn(LogLevel.INFO);
|
||||
given(settings.getProperty(SecuritySettings.USE_LOGGING)).willReturn(false);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReload() {
|
||||
void shouldReload() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
|
||||
|
@ -101,7 +101,7 @@ public class ReloadCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleReloadError() {
|
||||
void shouldHandleReloadError() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
doThrow(IllegalStateException.class).when(reloadableStore).retrieveAllOfType();
|
||||
|
@ -119,7 +119,7 @@ public class ReloadCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldIssueWarningForChangedDataSourceSetting() {
|
||||
void shouldIssueWarningForChangedDataSourceSetting() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(settings.getProperty(DatabaseSettings.BACKEND)).willReturn(DataSourceType.MYSQL);
|
||||
|
|
|
@ -8,11 +8,11 @@ import fr.xephi.authme.service.BukkitService;
|
|||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Arrays;
|
||||
|
||||
|
@ -28,8 +28,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
/**
|
||||
* Test for {@link SetEmailCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SetEmailCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SetEmailCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private SetEmailCommand command;
|
||||
|
@ -50,7 +50,7 @@ public class SetEmailCommandTest {
|
|||
private ValidationService validationService;
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidMail() {
|
||||
void shouldRejectInvalidMail() {
|
||||
// given
|
||||
String user = "somebody";
|
||||
String email = "some.test@example.org";
|
||||
|
@ -67,7 +67,7 @@ public class SetEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnknownUser() {
|
||||
void shouldHandleUnknownUser() {
|
||||
// given
|
||||
String user = "nonexistent";
|
||||
String email = "mail@example.com";
|
||||
|
@ -87,7 +87,7 @@ public class SetEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleAlreadyTakenEmail() {
|
||||
void shouldHandleAlreadyTakenEmail() {
|
||||
// given
|
||||
String user = "someone";
|
||||
String email = "mail@example.com";
|
||||
|
@ -111,7 +111,7 @@ public class SetEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandlePersistenceError() {
|
||||
void shouldHandlePersistenceError() {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
|
@ -136,7 +136,7 @@ public class SetEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateEmail() {
|
||||
void shouldUpdateEmail() {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
|
@ -163,7 +163,7 @@ public class SetEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateEmailAndPlayerCache() {
|
||||
void shouldUpdateEmailAndPlayerCache() {
|
||||
// given
|
||||
String user = "Bobby";
|
||||
String email = "new-addr@example.org";
|
||||
|
|
|
@ -3,11 +3,11 @@ package fr.xephi.authme.command.executable.authme;
|
|||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -20,8 +20,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link SetFirstSpawnCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SetFirstSpawnCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SetFirstSpawnCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private SetFirstSpawnCommand command;
|
||||
|
@ -31,7 +31,7 @@ public class SetFirstSpawnCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldSetFirstSpawn() {
|
||||
void shouldSetFirstSpawn() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
Location location = mock(Location.class);
|
||||
|
@ -47,7 +47,7 @@ public class SetFirstSpawnCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleError() {
|
||||
void shouldHandleError() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
Location location = mock(Location.class);
|
||||
|
|
|
@ -3,11 +3,11 @@ package fr.xephi.authme.command.executable.authme;
|
|||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -20,8 +20,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link SetSpawnCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SetSpawnCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SetSpawnCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private SetSpawnCommand command;
|
||||
|
@ -31,7 +31,7 @@ public class SetSpawnCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldSetSpawn() {
|
||||
void shouldSetSpawn() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
Location location = mock(Location.class);
|
||||
|
@ -47,7 +47,7 @@ public class SetSpawnCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleError() {
|
||||
void shouldHandleError() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
Location location = mock(Location.class);
|
||||
|
|
|
@ -3,11 +3,11 @@ package fr.xephi.authme.command.executable.authme;
|
|||
import fr.xephi.authme.settings.SpawnLoader;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -23,8 +23,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link SpawnCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SpawnCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SpawnCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private SpawnCommand command;
|
||||
|
@ -34,7 +34,7 @@ public class SpawnCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldTeleportToSpawn() {
|
||||
void shouldTeleportToSpawn() {
|
||||
// given
|
||||
Location spawn = mock(Location.class);
|
||||
given(spawnLoader.getSpawn()).willReturn(spawn);
|
||||
|
@ -49,7 +49,7 @@ public class SpawnCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingSpawn() {
|
||||
void shouldHandleMissingSpawn() {
|
||||
// given
|
||||
given(spawnLoader.getSpawn()).willReturn(null);
|
||||
Player player = mock(Player.class);
|
||||
|
|
|
@ -5,11 +5,11 @@ import fr.xephi.authme.command.FoundCommandResult;
|
|||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import fr.xephi.authme.service.AntiBotService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -25,8 +25,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link SwitchAntiBotCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class SwitchAntiBotCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class SwitchAntiBotCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private SwitchAntiBotCommand command;
|
||||
|
@ -41,7 +41,7 @@ public class SwitchAntiBotCommandTest {
|
|||
private HelpProvider helpProvider;
|
||||
|
||||
@Test
|
||||
public void shouldReturnAntiBotState() {
|
||||
void shouldReturnAntiBotState() {
|
||||
// given
|
||||
given(antiBot.getAntiBotStatus()).willReturn(AntiBotService.AntiBotStatus.ACTIVE);
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
@ -54,7 +54,7 @@ public class SwitchAntiBotCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldActivateAntiBot() {
|
||||
void shouldActivateAntiBot() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -67,7 +67,7 @@ public class SwitchAntiBotCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeactivateAntiBot() {
|
||||
void shouldDeactivateAntiBot() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class SwitchAntiBotCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowHelpForUnknownState() {
|
||||
void shouldShowHelpForUnknownState() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
FoundCommandResult foundCommandResult = mock(FoundCommandResult.class);
|
||||
|
|
|
@ -8,12 +8,12 @@ import fr.xephi.authme.message.Messages;
|
|||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
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;
|
||||
|
||||
|
@ -27,8 +27,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link TotpDisableAdminCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TotpDisableAdminCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TotpDisableAdminCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private TotpDisableAdminCommand command;
|
||||
|
@ -42,13 +42,13 @@ public class TotpDisableAdminCommandTest {
|
|||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
@BeforeAll
|
||||
static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnknownUser() {
|
||||
void shouldHandleUnknownUser() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(dataSource.getAuth("user")).willReturn(null);
|
||||
|
@ -62,7 +62,7 @@ public class TotpDisableAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUserWithNoTotpEnabled() {
|
||||
void shouldHandleUserWithNoTotpEnabled() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
|
@ -80,7 +80,7 @@ public class TotpDisableAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveTotpFromUser() {
|
||||
void shouldRemoveTotpFromUser() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
|
@ -101,7 +101,7 @@ public class TotpDisableAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleErrorWhileRemovingTotp() {
|
||||
void shouldHandleErrorWhileRemovingTotp() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
|
|
|
@ -6,12 +6,12 @@ import fr.xephi.authme.datasource.DataSource;
|
|||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.message.Messages;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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;
|
||||
|
||||
|
@ -25,8 +25,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link TotpViewStatusCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TotpViewStatusCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TotpViewStatusCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private TotpViewStatusCommand command;
|
||||
|
@ -37,13 +37,13 @@ public class TotpViewStatusCommandTest {
|
|||
@Mock
|
||||
private Messages messages;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
@BeforeAll
|
||||
static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnknownUser() {
|
||||
void shouldHandleUnknownUser() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(dataSource.getAuth("user")).willReturn(null);
|
||||
|
@ -57,7 +57,7 @@ public class TotpViewStatusCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldInformForUserWithoutTotp() {
|
||||
void shouldInformForUserWithoutTotp() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
|
@ -74,7 +74,7 @@ public class TotpViewStatusCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldInformForUserWithTotpEnabled() {
|
||||
void shouldInformForUserWithTotpEnabled() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
|
|
|
@ -7,11 +7,11 @@ import fr.xephi.authme.service.BukkitService;
|
|||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -23,8 +23,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link UnregisterAdminCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UnregisterAdminCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UnregisterAdminCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private UnregisterAdminCommand command;
|
||||
|
@ -42,7 +42,7 @@ public class UnregisterAdminCommandTest {
|
|||
private Management management;
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnknownPlayer() {
|
||||
void shouldHandleUnknownPlayer() {
|
||||
// given
|
||||
String user = "bobby";
|
||||
given(dataSource.isAuthAvailable(user)).willReturn(false);
|
||||
|
@ -57,7 +57,7 @@ public class UnregisterAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldInvokeUnregisterProcess() {
|
||||
void shouldInvokeUnregisterProcess() {
|
||||
// given
|
||||
String user = "personaNonGrata";
|
||||
given(dataSource.isAuthAvailable(user)).willReturn(true);
|
||||
|
@ -75,7 +75,7 @@ public class UnregisterAdminCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldInvokeUnregisterProcessWithNullPlayer() {
|
||||
void shouldInvokeUnregisterProcessWithNullPlayer() {
|
||||
// given
|
||||
String user = "personaNonGrata";
|
||||
given(dataSource.isAuthAvailable(user)).willReturn(true);
|
||||
|
|
|
@ -4,12 +4,12 @@ import fr.xephi.authme.TestHelper;
|
|||
import fr.xephi.authme.command.help.HelpMessagesService;
|
||||
import fr.xephi.authme.service.HelpTranslationGenerator;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -23,8 +23,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link UpdateHelpMessagesCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UpdateHelpMessagesCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UpdateHelpMessagesCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private UpdateHelpMessagesCommand command;
|
||||
|
@ -34,13 +34,13 @@ public class UpdateHelpMessagesCommandTest {
|
|||
@Mock
|
||||
private HelpMessagesService helpMessagesService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateHelpMessage() throws IOException {
|
||||
void shouldUpdateHelpMessage() throws IOException {
|
||||
// given
|
||||
File updatedFile = new File("some/path/help_xx.yml");
|
||||
given(helpTranslationGenerator.updateHelpFile()).willReturn(updatedFile);
|
||||
|
@ -55,7 +55,7 @@ public class UpdateHelpMessagesCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCatchAndReportException() throws IOException {
|
||||
void shouldCatchAndReportException() throws IOException {
|
||||
// given
|
||||
given(helpTranslationGenerator.updateHelpFile()).willThrow(new IOException("Couldn't do the thing"));
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
|
|
@ -15,13 +15,13 @@ import fr.xephi.authme.initialization.SettingsDependent;
|
|||
import fr.xephi.authme.output.ConsoleLoggerFactory;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
|
@ -29,9 +29,9 @@ import java.util.List;
|
|||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -40,8 +40,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link DataStatistics}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DataStatisticsTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DataStatisticsTest {
|
||||
|
||||
@InjectMocks
|
||||
private DataStatistics dataStatistics;
|
||||
|
@ -55,15 +55,15 @@ public class DataStatisticsTest {
|
|||
@Mock
|
||||
private SingletonStore<Object> singletonStore;
|
||||
|
||||
@Before
|
||||
public void setUpLimboCacheMap() {
|
||||
@BeforeEach
|
||||
void setUpLimboCacheMap() {
|
||||
Map<String, LimboPlayer> limboMap = new HashMap<>();
|
||||
limboMap.put("test", mock(LimboPlayer.class));
|
||||
ReflectionTestUtils.setField(LimboService.class, limboService, "entries", limboMap);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldOutputStatistics() {
|
||||
void shouldOutputStatistics() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(singletonStore.retrieveAllOfType()).willReturn(mockListOfSize(Object.class, 7));
|
||||
|
@ -96,7 +96,7 @@ public class DataStatisticsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldOutputCachedDataSourceStatistics() {
|
||||
void shouldOutputCachedDataSourceStatistics() {
|
||||
// given
|
||||
CacheDataSource cacheDataSource = mock(CacheDataSource.class);
|
||||
LoadingCache<String, Optional<PlayerAuth>> cache = mock(LoadingCache.class);
|
||||
|
|
|
@ -6,13 +6,13 @@ import fr.xephi.authme.permission.PermissionNode;
|
|||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
@ -20,10 +20,10 @@ import java.util.Locale;
|
|||
|
||||
import static com.google.common.base.Preconditions.checkArgument;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyList;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
@ -41,8 +41,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link DebugCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class DebugCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DebugCommandTest {
|
||||
|
||||
/**
|
||||
* Number we test against if we expect an action to have been performed for each debug section.
|
||||
|
@ -60,9 +60,9 @@ public class DebugCommandTest {
|
|||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Before
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void initFactory() {
|
||||
void initFactory() {
|
||||
given(debugSectionFactory.newInstance(any(Class.class))).willAnswer(
|
||||
invocation -> {
|
||||
Class<?> classArgument = invocation.getArgument(0);
|
||||
|
@ -72,7 +72,7 @@ public class DebugCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldListAllAvailableDebugSections() {
|
||||
void shouldListAllAvailableDebugSections() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(false);
|
||||
|
@ -96,7 +96,7 @@ public class DebugCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotListAnyDebugSection() {
|
||||
void shouldNotListAnyDebugSection() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
given(permissionsManager.hasPermission(eq(sender), any(PermissionNode.class))).willReturn(false);
|
||||
|
@ -117,7 +117,7 @@ public class DebugCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRunSection() {
|
||||
void shouldRunSection() {
|
||||
// given
|
||||
DebugSection section = spy(InputValidator.class);
|
||||
doNothing().when(section).execute(any(CommandSender.class), anyList());
|
||||
|
@ -137,7 +137,7 @@ public class DebugCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRunSectionForMissingPermission() {
|
||||
void shouldNotRunSectionForMissingPermission() {
|
||||
// given
|
||||
DebugSection section = spy(InputValidator.class);
|
||||
// Mockito throws a runtime error if below we use the usual "given(factory.newInstance(...)).willReturn(...)"
|
||||
|
|
|
@ -2,30 +2,30 @@ package fr.xephi.authme.command.executable.authme.debug;
|
|||
|
||||
import fr.xephi.authme.ClassCollector;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.lang.reflect.Modifier;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.Set;
|
||||
|
||||
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.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Consistency tests for {@link DebugSection} implementors.
|
||||
*/
|
||||
public class DebugSectionConsistencyTest {
|
||||
class DebugSectionConsistencyTest {
|
||||
|
||||
private static List<Class<?>> debugClasses;
|
||||
private static List<DebugSection> debugSections;
|
||||
|
||||
@BeforeClass
|
||||
public static void collectClasses() {
|
||||
@BeforeAll
|
||||
static void collectClasses() {
|
||||
// TODO ljacqu 20171021: Improve ClassCollector (pass pkg by class, improve #getInstancesOfType's instantiation)
|
||||
ClassCollector classCollector = new ClassCollector(
|
||||
TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT + "command/executable/authme/debug");
|
||||
|
@ -35,7 +35,7 @@ public class DebugSectionConsistencyTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllBePackagePrivate() {
|
||||
void shouldAllBePackagePrivate() {
|
||||
for (Class<?> clazz : debugClasses) {
|
||||
if (clazz != DebugCommand.class) {
|
||||
assertThat(clazz + " should be package-private",
|
||||
|
@ -45,7 +45,7 @@ public class DebugSectionConsistencyTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveDifferentSubcommandName() throws IllegalAccessException, InstantiationException {
|
||||
void shouldHaveDifferentSubcommandName() {
|
||||
Set<String> names = new HashSet<>();
|
||||
for (DebugSection debugSection : debugSections) {
|
||||
if (!names.add(debugSection.getName())) {
|
||||
|
@ -55,7 +55,7 @@ public class DebugSectionConsistencyTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldAllHaveDescription() {
|
||||
void shouldAllHaveDescription() {
|
||||
for (DebugSection debugSection : debugSections) {
|
||||
assertThat("Description of '" + debugSection.getClass() + "' may not be null",
|
||||
debugSection.getDescription(), not(nullValue()));
|
||||
|
|
|
@ -8,31 +8,31 @@ import fr.xephi.authme.data.limbo.LimboService;
|
|||
import fr.xephi.authme.datasource.CacheDataSource;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import org.bukkit.Location;
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
import java.util.function.Function;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link DebugSectionUtils}.
|
||||
*/
|
||||
public class DebugSectionUtilsTest {
|
||||
class DebugSectionUtilsTest {
|
||||
|
||||
@Before
|
||||
public void initMockLogger() {
|
||||
@BeforeEach
|
||||
void initMockLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFormatLocation() {
|
||||
void shouldFormatLocation() {
|
||||
// given / when
|
||||
String result = DebugSectionUtils.formatLocation(0.0, 10.248592, -18934.2349023, "Main");
|
||||
|
||||
|
@ -41,7 +41,7 @@ public class DebugSectionUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullWorld() {
|
||||
void shouldHandleNullWorld() {
|
||||
// given
|
||||
Location location = new Location(null, 3.7777, 2.14156, 1);
|
||||
|
||||
|
@ -53,13 +53,13 @@ public class DebugSectionUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullLocation() {
|
||||
void shouldHandleNullLocation() {
|
||||
// given / when / then
|
||||
assertThat(DebugSectionUtils.formatLocation(null), equalTo("null"));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldFetchMapInLimboService() {
|
||||
void shouldFetchMapInLimboService() {
|
||||
// given
|
||||
LimboService limboService = mock(LimboService.class);
|
||||
Map<String, LimboPlayer> limboMap = new HashMap<>();
|
||||
|
@ -73,7 +73,7 @@ public class DebugSectionUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleErrorGracefully() {
|
||||
void shouldHandleErrorGracefully() {
|
||||
// given
|
||||
LimboService limboService = mock(LimboService.class);
|
||||
Map<String, LimboPlayer> limboMap = new HashMap<>();
|
||||
|
@ -89,7 +89,7 @@ public class DebugSectionUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSameDataSourceInstance() {
|
||||
void shouldReturnSameDataSourceInstance() {
|
||||
// given
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
|
||||
|
@ -101,7 +101,7 @@ public class DebugSectionUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUnwrapCacheDataSource() {
|
||||
void shouldUnwrapCacheDataSource() {
|
||||
// given
|
||||
DataSource source = mock(DataSource.class);
|
||||
PlayerCache playerCache = mock(PlayerCache.class);
|
||||
|
@ -115,7 +115,7 @@ public class DebugSectionUtilsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCastOrReturnNull() {
|
||||
void shouldCastOrReturnNull() {
|
||||
// given / when / then
|
||||
assertThat(DebugSectionUtils.castToTypeOrNull("test", String.class), equalTo("test"));
|
||||
assertThat(DebugSectionUtils.castToTypeOrNull("test", Integer.class), nullValue());
|
||||
|
|
|
@ -8,22 +8,22 @@ import fr.xephi.authme.permission.PermissionsManager;
|
|||
import fr.xephi.authme.service.BukkitService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.InjectMocks;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.List;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
import static java.util.Arrays.asList;
|
||||
import static java.util.Collections.emptyList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeast;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -33,8 +33,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link HasPermissionChecker}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class HasPermissionCheckerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HasPermissionCheckerTest {
|
||||
|
||||
@InjectMocks
|
||||
private HasPermissionChecker hasPermissionChecker;
|
||||
|
@ -46,7 +46,7 @@ public class HasPermissionCheckerTest {
|
|||
private BukkitService bukkitService;
|
||||
|
||||
@Test
|
||||
public void shouldListAllPermissionNodeClasses() {
|
||||
void shouldListAllPermissionNodeClasses() {
|
||||
// given
|
||||
List<Class<? extends PermissionNode>> permissionClasses =
|
||||
new ClassCollector(TestHelper.SOURCES_FOLDER, TestHelper.PROJECT_ROOT)
|
||||
|
@ -59,7 +59,7 @@ public class HasPermissionCheckerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowUsageInfo() {
|
||||
void shouldShowUsageInfo() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -75,7 +75,7 @@ public class HasPermissionCheckerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowSuccessfulTestWithRegularPlayer() {
|
||||
void shouldShowSuccessfulTestWithRegularPlayer() {
|
||||
// given
|
||||
String name = "Chuck";
|
||||
Player player = mock(Player.class);
|
||||
|
|
|
@ -1,21 +1,21 @@
|
|||
package fr.xephi.authme.command.executable.authme.debug;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Consistency test for {@link MySqlDefaultChanger.Columns} enum.
|
||||
*/
|
||||
public class MySqlDefaultChangerColumnsTest {
|
||||
class MySqlDefaultChangerColumnsTest {
|
||||
|
||||
@Test
|
||||
public void shouldAllHaveDifferentNameProperty() {
|
||||
void shouldAllHaveDifferentNameProperty() {
|
||||
// given
|
||||
Set<String> properties = new HashSet<>();
|
||||
|
||||
|
@ -29,14 +29,14 @@ public class MySqlDefaultChangerColumnsTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveMatchingNullableAndNotNullDefinition() {
|
||||
void shouldHaveMatchingNullableAndNotNullDefinition() {
|
||||
for (MySqlDefaultChanger.Columns col : MySqlDefaultChanger.Columns.values()) {
|
||||
verifyHasCorrespondingColumnDefinitions(col);
|
||||
}
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveMatchingDefaultValueInNotNullDefinition() {
|
||||
void shouldHaveMatchingDefaultValueInNotNullDefinition() {
|
||||
for (MySqlDefaultChanger.Columns col : MySqlDefaultChanger.Columns.values()) {
|
||||
verifyHasSameDefaultValueInNotNullDefinition(col);
|
||||
}
|
||||
|
|
|
@ -9,19 +9,19 @@ import fr.xephi.authme.datasource.DataSource;
|
|||
import fr.xephi.authme.datasource.MySQL;
|
||||
import fr.xephi.authme.datasource.SqlDataSourceTestUtil;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
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.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.sql.Connection;
|
||||
import java.sql.SQLException;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -29,19 +29,19 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link MySqlDefaultChanger}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class MySqlDefaultChangerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class MySqlDefaultChangerTest {
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnMySqlConnection() throws SQLException {
|
||||
void shouldReturnMySqlConnection() throws SQLException {
|
||||
// given
|
||||
Settings settings = mock(Settings.class);
|
||||
TestHelper.returnDefaultsForAllProperties(settings);
|
||||
|
@ -60,7 +60,7 @@ public class MySqlDefaultChangerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetMySqlFieldOnInitialization() {
|
||||
void shouldSetMySqlFieldOnInitialization() {
|
||||
// given
|
||||
MySQL mySql = mock(MySQL.class);
|
||||
MySqlDefaultChanger defaultChanger = createDefaultChanger(mySql);
|
||||
|
@ -74,7 +74,7 @@ public class MySqlDefaultChangerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldLeaveMySqlFieldToNullOnInitialization() {
|
||||
void shouldLeaveMySqlFieldToNullOnInitialization() {
|
||||
// given
|
||||
DataSource dataSource = mock(DataSource.class);
|
||||
PlayerCache playerCache = mock(PlayerCache.class);
|
||||
|
|
|
@ -3,18 +3,18 @@ package fr.xephi.authme.command.executable.authme.debug;
|
|||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
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 org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.hasItem;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -24,8 +24,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link PlayerAuthViewer}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class PlayerAuthViewerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class PlayerAuthViewerTest {
|
||||
|
||||
@InjectMocks
|
||||
private PlayerAuthViewer authViewer;
|
||||
|
@ -34,7 +34,7 @@ public class PlayerAuthViewerTest {
|
|||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void shouldMakeExample() {
|
||||
void shouldMakeExample() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class PlayerAuthViewerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingPlayer() {
|
||||
void shouldHandleMissingPlayer() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -59,7 +59,7 @@ public class PlayerAuthViewerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDisplayAuthInfo() {
|
||||
void shouldDisplayAuthInfo() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder().name("george").realName("George")
|
||||
|
@ -82,7 +82,7 @@ public class PlayerAuthViewerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleCornerCases() {
|
||||
void shouldHandleCornerCases() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
PlayerAuth auth = PlayerAuth.builder().name("tar")
|
||||
|
|
|
@ -8,11 +8,11 @@ import fr.xephi.authme.datasource.DataSource;
|
|||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -25,8 +25,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
/**
|
||||
* Test for {@link CaptchaCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class CaptchaCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class CaptchaCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private CaptchaCommand command;
|
||||
|
@ -50,7 +50,7 @@ public class CaptchaCommandTest {
|
|||
private DataSource dataSource;
|
||||
|
||||
@Test
|
||||
public void shouldDetectIfPlayerIsLoggedIn() {
|
||||
void shouldDetectIfPlayerIsLoggedIn() {
|
||||
// given
|
||||
String name = "creeper011";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -64,7 +64,7 @@ public class CaptchaCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowLoginUsageIfCaptchaIsNotRequired() {
|
||||
void shouldShowLoginUsageIfCaptchaIsNotRequired() {
|
||||
// given
|
||||
String name = "bobby";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -82,7 +82,7 @@ public class CaptchaCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleCorrectCaptchaInput() {
|
||||
void shouldHandleCorrectCaptchaInput() {
|
||||
// given
|
||||
String name = "smith";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -105,7 +105,7 @@ public class CaptchaCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleWrongCaptchaInput() {
|
||||
void shouldHandleWrongCaptchaInput() {
|
||||
// given
|
||||
String name = "smith";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -129,7 +129,7 @@ public class CaptchaCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldVerifyWithRegisterCaptchaManager() {
|
||||
void shouldVerifyWithRegisterCaptchaManager() {
|
||||
// given
|
||||
String name = "john";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -149,7 +149,7 @@ public class CaptchaCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleFailedRegisterCaptcha() {
|
||||
void shouldHandleFailedRegisterCaptcha() {
|
||||
// given
|
||||
String name = "asfd";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -168,7 +168,7 @@ public class CaptchaCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowRegisterUsageWhenRegistrationCaptchaIsSolved() {
|
||||
void shouldShowRegisterUsageWhenRegistrationCaptchaIsSolved() {
|
||||
// given
|
||||
String name = "alice";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
|
|
@ -10,18 +10,18 @@ import fr.xephi.authme.service.ValidationService.ValidationResult;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.any;
|
||||
import static org.mockito.Mockito.eq;
|
||||
|
@ -34,8 +34,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link ChangePasswordCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ChangePasswordCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ChangePasswordCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ChangePasswordCommand command;
|
||||
|
@ -56,7 +56,7 @@ public class ChangePasswordCommandTest {
|
|||
private Management management;
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
void shouldRejectNonPlayerSender() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
|
@ -68,7 +68,7 @@ public class ChangePasswordCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectNotLoggedInPlayer() {
|
||||
void shouldRejectNotLoggedInPlayer() {
|
||||
// given
|
||||
CommandSender sender = initPlayerWithName("name", false);
|
||||
|
||||
|
@ -80,7 +80,7 @@ public class ChangePasswordCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidPassword() {
|
||||
void shouldRejectInvalidPassword() {
|
||||
// given
|
||||
Player sender = initPlayerWithName("abc12", true);
|
||||
String password = "newPW";
|
||||
|
@ -97,7 +97,7 @@ public class ChangePasswordCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardTheDataForValidPassword() {
|
||||
void shouldForwardTheDataForValidPassword() {
|
||||
// given
|
||||
String oldPass = "oldpass";
|
||||
String newPass = "abc123";
|
||||
|
@ -116,7 +116,7 @@ public class ChangePasswordCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_CHANGE_PASSWORD));
|
||||
}
|
||||
|
|
|
@ -6,17 +6,17 @@ import fr.xephi.authme.service.CommonService;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
@ -24,8 +24,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link AddEmailCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AddEmailCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AddEmailCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private AddEmailCommand command;
|
||||
|
@ -37,7 +37,7 @@ public class AddEmailCommandTest {
|
|||
private Management management;
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
void shouldRejectNonPlayerSender() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
|
@ -49,7 +49,7 @@ public class AddEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardData() {
|
||||
void shouldForwardData() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
String email = "mail@example";
|
||||
|
@ -62,7 +62,7 @@ public class AddEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFailForConfirmationMismatch() {
|
||||
void shouldFailForConfirmationMismatch() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
String email = "asdfasdf@example.com";
|
||||
|
@ -76,7 +76,7 @@ public class AddEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_ADD_EMAIL));
|
||||
}
|
||||
|
|
|
@ -7,17 +7,17 @@ import fr.xephi.authme.service.CommonService;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.Arrays;
|
||||
import java.util.Collections;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -27,8 +27,8 @@ import static org.mockito.Mockito.when;
|
|||
/**
|
||||
* Test for {@link ChangeEmailCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ChangeEmailCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ChangeEmailCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ChangeEmailCommand command;
|
||||
|
@ -44,7 +44,7 @@ public class ChangeEmailCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldRejectNonPlayerSender() {
|
||||
void shouldRejectNonPlayerSender() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
|
@ -56,7 +56,7 @@ public class ChangeEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopIfVerificationIsRequired() {
|
||||
void shouldStopIfVerificationIsRequired() {
|
||||
// given
|
||||
String name = "Testeroni";
|
||||
Player player = initPlayerWithName(name);
|
||||
|
@ -72,7 +72,7 @@ public class ChangeEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardData() {
|
||||
void shouldForwardData() {
|
||||
// given
|
||||
Player sender = initPlayerWithName("AmATest");
|
||||
given(codeManager.isVerificationRequired(sender)).willReturn(false);
|
||||
|
@ -86,7 +86,7 @@ public class ChangeEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_CHANGE_EMAIL));
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import fr.xephi.authme.command.CommandMapper;
|
|||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -21,8 +21,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link EmailBaseCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EmailBaseCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class EmailBaseCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private EmailBaseCommand command;
|
||||
|
@ -33,7 +33,7 @@ public class EmailBaseCommandTest {
|
|||
private CommandMapper commandMapper;
|
||||
|
||||
@Test
|
||||
public void shouldDisplayHelp() {
|
||||
void shouldDisplayHelp() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
FoundCommandResult result = mock(FoundCommandResult.class);
|
||||
|
|
|
@ -9,12 +9,12 @@ import fr.xephi.authme.service.CommonService;
|
|||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.ValidationService;
|
||||
import org.bukkit.entity.Player;
|
||||
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;
|
||||
|
||||
|
@ -26,8 +26,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Tests for {@link EmailSetPasswordCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class EmailSetPasswordCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class EmailSetPasswordCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private EmailSetPasswordCommand command;
|
||||
|
@ -47,13 +47,13 @@ public class EmailSetPasswordCommandTest {
|
|||
@Mock
|
||||
private ValidationService validationService;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldChangePassword() {
|
||||
void shouldChangePassword() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String name = "Jerry";
|
||||
|
@ -75,7 +75,7 @@ public class EmailSetPasswordCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidPassword() {
|
||||
void shouldRejectInvalidPassword() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String name = "Morgan";
|
||||
|
@ -94,7 +94,7 @@ public class EmailSetPasswordCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDoNothingCantChangePass() {
|
||||
void shouldDoNothingCantChangePass() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
|
|
|
@ -5,11 +5,11 @@ import fr.xephi.authme.service.CommonService;
|
|||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -21,8 +21,8 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
/**
|
||||
* Tests for {@link ProcessCodeCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ProcessCodeCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ProcessCodeCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ProcessCodeCommand command;
|
||||
|
@ -37,7 +37,7 @@ public class ProcessCodeCommandTest {
|
|||
private PasswordRecoveryService recoveryService;
|
||||
|
||||
@Test
|
||||
public void shouldSendErrorForInvalidRecoveryCode() {
|
||||
void shouldSendErrorForInvalidRecoveryCode() {
|
||||
// given
|
||||
String name = "Vultur3";
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -55,7 +55,7 @@ public class ProcessCodeCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSendErrorForNoMoreTries() {
|
||||
void shouldSendErrorForNoMoreTries() {
|
||||
// given
|
||||
String name = "BobbY";
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -72,7 +72,7 @@ public class ProcessCodeCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldProcessCorrectCode() {
|
||||
void shouldProcessCorrectCode() {
|
||||
// given
|
||||
String name = "Dwight";
|
||||
String code = "chickenDinner";
|
||||
|
|
|
@ -1,35 +1,32 @@
|
|||
package fr.xephi.authme.command.executable.email;
|
||||
|
||||
import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerCache;
|
||||
import fr.xephi.authme.datasource.DataSource;
|
||||
import fr.xephi.authme.mail.EmailService;
|
||||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.security.PasswordSecurity;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.service.PasswordRecoveryService;
|
||||
import fr.xephi.authme.service.RecoveryCodeService;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.entity.Player;
|
||||
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.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Collections;
|
||||
import java.util.Locale;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToRunTaskAsynchronously;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
import static org.mockito.Mockito.verifyNoMoreInteractions;
|
||||
|
@ -37,17 +34,14 @@ import static org.mockito.Mockito.verifyNoMoreInteractions;
|
|||
/**
|
||||
* Test for {@link RecoverEmailCommand}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class RecoverEmailCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RecoverEmailCommandTest {
|
||||
|
||||
private static final String DEFAULT_EMAIL = "your@email.com";
|
||||
|
||||
@InjectDelayed
|
||||
@InjectMocks
|
||||
private RecoverEmailCommand command;
|
||||
|
||||
@Mock
|
||||
private PasswordSecurity passwordSecurity;
|
||||
|
||||
@Mock
|
||||
private CommonService commonService;
|
||||
|
||||
|
@ -69,18 +63,13 @@ public class RecoverEmailCommandTest {
|
|||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
@BeforeAll
|
||||
static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@BeforeInjecting
|
||||
public void initSettings() {
|
||||
given(commonService.getProperty(SecuritySettings.EMAIL_RECOVERY_COOLDOWN_SECONDS)).willReturn(40);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingMailProperties() {
|
||||
void shouldHandleMissingMailProperties() {
|
||||
// given
|
||||
given(emailService.hasAllInformation()).willReturn(false);
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -90,11 +79,11 @@ public class RecoverEmailCommandTest {
|
|||
|
||||
// then
|
||||
verify(commonService).send(sender, MessageKey.INCOMPLETE_EMAIL_SETTINGS);
|
||||
verifyNoInteractions(dataSource, passwordSecurity);
|
||||
verifyNoInteractions(dataSource);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowErrorForAuthenticatedUser() {
|
||||
void shouldShowErrorForAuthenticatedUser() {
|
||||
// given
|
||||
String name = "Bobby";
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -112,7 +101,7 @@ public class RecoverEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowRegisterMessageForUnregisteredPlayer() {
|
||||
void shouldShowRegisterMessageForUnregisteredPlayer() {
|
||||
// given
|
||||
String name = "Player123";
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -132,7 +121,7 @@ public class RecoverEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleDefaultEmail() {
|
||||
void shouldHandleDefaultEmail() {
|
||||
// given
|
||||
String name = "Tract0r";
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -152,7 +141,7 @@ public class RecoverEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleInvalidEmailInput() {
|
||||
void shouldHandleInvalidEmailInput() {
|
||||
// given
|
||||
String name = "Rapt0r";
|
||||
Player sender = mock(Player.class);
|
||||
|
@ -172,38 +161,32 @@ public class RecoverEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateRecoveryCode() {
|
||||
void shouldGenerateRecoveryCode() {
|
||||
// given
|
||||
String name = "Vultur3";
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
given(emailService.hasAllInformation()).willReturn(true);
|
||||
given(emailService.sendRecoveryCode(anyString(), anyString(), anyString())).willReturn(true);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
String email = "v@example.com";
|
||||
given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.of(email));
|
||||
String code = "a94f37";
|
||||
given(recoveryCodeService.isRecoveryCodeNeeded()).willReturn(true);
|
||||
given(recoveryCodeService.generateCode(name)).willReturn(code);
|
||||
setBukkitServiceToRunTaskAsynchronously(bukkitService);
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.singletonList(email.toUpperCase(Locale.ROOT)));
|
||||
|
||||
// then
|
||||
verify(emailService).hasAllInformation();
|
||||
verify(dataSource).getEmail(name);
|
||||
verify(recoveryService).createAndSendRecoveryCode(sender, email);
|
||||
verify(recoveryService, only()).createAndSendRecoveryCode(sender, email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateNewPasswordWithoutRecoveryCode() {
|
||||
void shouldGenerateNewPasswordWithoutRecoveryCode() {
|
||||
// given
|
||||
String name = "Vultur3";
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(name);
|
||||
given(emailService.hasAllInformation()).willReturn(true);
|
||||
given(emailService.sendPasswordMail(anyString(), anyString(), anyString())).willReturn(true);
|
||||
given(playerCache.isAuthenticated(name)).willReturn(false);
|
||||
String email = "vulture@example.com";
|
||||
given(dataSource.getEmail(name)).willReturn(DataSourceValueImpl.of(email));
|
||||
|
@ -214,13 +197,11 @@ public class RecoverEmailCommandTest {
|
|||
command.executeCommand(sender, Collections.singletonList(email));
|
||||
|
||||
// then
|
||||
verify(emailService).hasAllInformation();
|
||||
verify(dataSource).getEmail(name);
|
||||
verify(recoveryService).generateAndSendNewPassword(sender, email);
|
||||
verify(recoveryService, only()).generateAndSendNewPassword(sender, email);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_RECOVER_EMAIL));
|
||||
}
|
||||
|
|
|
@ -6,11 +6,11 @@ import fr.xephi.authme.message.MessageKey;
|
|||
import fr.xephi.authme.service.CommonService;
|
||||
import fr.xephi.authme.settings.properties.SecuritySettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -21,8 +21,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link ShowEmailCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ShowEmailCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ShowEmailCommandTest {
|
||||
|
||||
private static final String CURRENT_EMAIL = "my.email@example.com";
|
||||
private static final String USERNAME = "name";
|
||||
|
@ -37,7 +37,7 @@ public class ShowEmailCommandTest {
|
|||
private PlayerCache playerCache;
|
||||
|
||||
@Test
|
||||
public void shouldShowCurrentEmailMessage() {
|
||||
void shouldShowCurrentEmailMessage() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(USERNAME);
|
||||
|
@ -52,7 +52,7 @@ public class ShowEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowHiddenEmailMessage() {
|
||||
void shouldShowHiddenEmailMessage() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(USERNAME);
|
||||
|
@ -67,7 +67,7 @@ public class ShowEmailCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNoEmailMessage() {
|
||||
void shouldReturnNoEmailMessage() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
given(sender.getName()).willReturn(USERNAME);
|
||||
|
|
|
@ -5,17 +5,17 @@ import fr.xephi.authme.process.Management;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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 org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
@ -24,8 +24,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link LoginCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LoginCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class LoginCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private LoginCommand command;
|
||||
|
@ -35,7 +35,7 @@ public class LoginCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotAPlayer() {
|
||||
void shouldStopIfSenderIsNotAPlayer() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
|
@ -48,7 +48,7 @@ public class LoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCallManagementForPlayerCaller() {
|
||||
void shouldCallManagementForPlayerCaller() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
|
@ -60,7 +60,7 @@ public class LoginCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_LOGIN));
|
||||
}
|
||||
|
|
|
@ -4,11 +4,11 @@ import fr.xephi.authme.process.Management;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.ArrayList;
|
||||
import java.util.Collections;
|
||||
|
@ -22,8 +22,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link LogoutCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class LogoutCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class LogoutCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private LogoutCommand command;
|
||||
|
@ -33,7 +33,7 @@ public class LogoutCommandTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotAPlayer() {
|
||||
void shouldStopIfSenderIsNotAPlayer() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
|
||||
|
@ -46,7 +46,7 @@ public class LogoutCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCallManagementForPlayerCaller() {
|
||||
void shouldCallManagementForPlayerCaller() {
|
||||
// given
|
||||
Player sender = mock(Player.class);
|
||||
|
||||
|
|
|
@ -19,13 +19,13 @@ import fr.xephi.authme.settings.properties.SecuritySettings;
|
|||
import org.bukkit.command.BlockCommandSender;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
|
@ -43,8 +43,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link RegisterCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RegisterCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RegisterCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private RegisterCommand command;
|
||||
|
@ -64,22 +64,21 @@ public class RegisterCommandTest {
|
|||
@Mock
|
||||
private RegistrationCaptchaManager registrationCaptchaManager;
|
||||
|
||||
@BeforeClass
|
||||
public static void setup() {
|
||||
@BeforeAll
|
||||
static void setup() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Before
|
||||
public void linkMocksAndProvideSettingDefaults() {
|
||||
given(commonService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.NONE);
|
||||
@BeforeEach
|
||||
void setPasswordHashProperty() {
|
||||
given(commonService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.BCRYPT);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRunForNonPlayerSender() {
|
||||
void shouldNotRunForNonPlayerSender() {
|
||||
// given
|
||||
CommandSender sender = mock(BlockCommandSender.class);
|
||||
commonService.getProperty(SecuritySettings.PASSWORD_HASH); // Prevent UnnecessaryStubbingException
|
||||
|
||||
// when
|
||||
command.executeCommand(sender, Collections.emptyList());
|
||||
|
@ -90,7 +89,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardToManagementForTwoFactor() {
|
||||
void shouldForwardToManagementForTwoFactor() {
|
||||
// given
|
||||
given(commonService.getProperty(SecuritySettings.PASSWORD_HASH)).willReturn(HashAlgorithm.TWO_FACTOR);
|
||||
Player player = mockPlayerWithName("test2");
|
||||
|
@ -106,7 +105,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnErrorForEmptyArguments() {
|
||||
void shouldReturnErrorForEmptyArguments() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
|
||||
|
@ -119,7 +118,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnErrorForMissingConfirmation() {
|
||||
void shouldReturnErrorForMissingConfirmation() {
|
||||
// given
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||
|
@ -134,7 +133,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnErrorForMissingEmailConfirmation() {
|
||||
void shouldReturnErrorForMissingEmailConfirmation() {
|
||||
// given
|
||||
given(emailService.hasAllInformation()).willReturn(true);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||
|
@ -151,7 +150,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowErrorForMissingEmailConfiguration() {
|
||||
void shouldThrowErrorForMissingEmailConfiguration() {
|
||||
// given
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.EMAIL);
|
||||
given(emailService.hasAllInformation()).willReturn(false);
|
||||
|
@ -167,7 +166,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidEmail() {
|
||||
void shouldRejectInvalidEmail() {
|
||||
// given
|
||||
String playerMail = "player@example.org";
|
||||
given(validationService.validateEmail(playerMail)).willReturn(false);
|
||||
|
@ -185,7 +184,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidEmailConfirmation() {
|
||||
void shouldRejectInvalidEmailConfirmation() {
|
||||
// given
|
||||
String playerMail = "bobber@bobby.org";
|
||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||
|
@ -204,7 +203,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformEmailRegistration() {
|
||||
void shouldPerformEmailRegistration() {
|
||||
// given
|
||||
String playerMail = "asfd@lakjgre.lds";
|
||||
given(validationService.validateEmail(playerMail)).willReturn(true);
|
||||
|
@ -225,7 +224,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectInvalidPasswordConfirmation() {
|
||||
void shouldRejectInvalidPasswordConfirmation() {
|
||||
// given
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.CONFIRMATION);
|
||||
|
@ -240,9 +239,11 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformPasswordRegistration() {
|
||||
void shouldPerformPasswordRegistration() {
|
||||
// given
|
||||
Player player = mockPlayerWithName("newPlayer");
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.NONE);
|
||||
|
||||
// when
|
||||
command.executeCommand(player, Collections.singletonList("myPass"));
|
||||
|
@ -254,7 +255,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformMailValidationForPasswordWithEmail() {
|
||||
void shouldPerformMailValidationForPasswordWithEmail() {
|
||||
// given
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_MANDATORY);
|
||||
|
@ -272,7 +273,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopForInvalidEmail() {
|
||||
void shouldStopForInvalidEmail() {
|
||||
// given
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_OPTIONAL);
|
||||
|
@ -291,7 +292,7 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformNormalPasswordRegisterForOneArgument() {
|
||||
void shouldPerformNormalPasswordRegisterForOneArgument() {
|
||||
// given
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTRATION_TYPE)).willReturn(RegistrationType.PASSWORD);
|
||||
given(commonService.getProperty(RegistrationSettings.REGISTER_SECOND_ARGUMENT)).willReturn(RegisterSecondaryArgument.EMAIL_OPTIONAL);
|
||||
|
@ -307,8 +308,9 @@ public class RegisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRequestCaptcha() {
|
||||
void shouldRequestCaptcha() {
|
||||
// given
|
||||
commonService.getProperty(SecuritySettings.PASSWORD_HASH); // Prevent UnnecessaryStubbingException
|
||||
given(registrationCaptchaManager.isCaptchaRequired(anyString())).willReturn(true);
|
||||
String name = "Brian";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
|
|
@ -7,11 +7,11 @@ import fr.xephi.authme.message.Messages;
|
|||
import fr.xephi.authme.security.totp.GenerateTotpService;
|
||||
import fr.xephi.authme.security.totp.TotpAuthenticator.TotpGenerationResult;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -23,8 +23,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link AddTotpCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class AddTotpCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class AddTotpCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private AddTotpCommand addTotpCommand;
|
||||
|
@ -37,7 +37,7 @@ public class AddTotpCommandTest {
|
|||
private Messages messages;
|
||||
|
||||
@Test
|
||||
public void shouldHandleNonLoggedInUser() {
|
||||
void shouldHandleNonLoggedInUser() {
|
||||
// given
|
||||
Player player = mockPlayerWithName("bob");
|
||||
given(playerCache.getAuth("bob")).willReturn(null);
|
||||
|
@ -51,7 +51,7 @@ public class AddTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotAddCodeForAlreadyExistingTotp() {
|
||||
void shouldNotAddCodeForAlreadyExistingTotp() {
|
||||
// given
|
||||
Player player = mockPlayerWithName("arend");
|
||||
PlayerAuth auth = PlayerAuth.builder().name("arend")
|
||||
|
@ -67,7 +67,7 @@ public class AddTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateTotpCode() {
|
||||
void shouldGenerateTotpCode() {
|
||||
// given
|
||||
Player player = mockPlayerWithName("charles");
|
||||
PlayerAuth auth = PlayerAuth.builder().name("charles").build();
|
||||
|
|
|
@ -9,17 +9,17 @@ import fr.xephi.authme.message.Messages;
|
|||
import fr.xephi.authme.security.totp.GenerateTotpService;
|
||||
import fr.xephi.authme.security.totp.TotpAuthenticator.TotpGenerationResult;
|
||||
import org.bukkit.entity.Player;
|
||||
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 org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
|
@ -32,8 +32,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link ConfirmTotpCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class ConfirmTotpCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class ConfirmTotpCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private ConfirmTotpCommand command;
|
||||
|
@ -47,13 +47,13 @@ public class ConfirmTotpCommandTest {
|
|||
@Mock
|
||||
private Messages messages;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddTotpCodeToUserAfterSuccessfulConfirmation() {
|
||||
void shouldAddTotpCodeToUserAfterSuccessfulConfirmation() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String playerName = "George";
|
||||
|
@ -79,7 +79,7 @@ public class ConfirmTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleWrongTotpCode() {
|
||||
void shouldHandleWrongTotpCode() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String playerName = "George";
|
||||
|
@ -102,7 +102,7 @@ public class ConfirmTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingTotpKey() {
|
||||
void shouldHandleMissingTotpKey() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String playerName = "George";
|
||||
|
@ -122,7 +122,7 @@ public class ConfirmTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopForAlreadyExistingTotpKeyOnAccount() {
|
||||
void shouldStopForAlreadyExistingTotpKeyOnAccount() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String playerName = "George";
|
||||
|
@ -140,7 +140,7 @@ public class ConfirmTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingAuthAccount() {
|
||||
void shouldHandleMissingAuthAccount() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String playerName = "George";
|
||||
|
|
|
@ -8,16 +8,16 @@ import fr.xephi.authme.message.MessageKey;
|
|||
import fr.xephi.authme.message.Messages;
|
||||
import fr.xephi.authme.security.totp.TotpAuthenticator;
|
||||
import org.bukkit.entity.Player;
|
||||
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 static java.util.Collections.singletonList;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
|
@ -27,8 +27,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link RemoveTotpCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class RemoveTotpCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class RemoveTotpCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private RemoveTotpCommand command;
|
||||
|
@ -42,13 +42,13 @@ public class RemoveTotpCommandTest {
|
|||
@Mock
|
||||
private Messages messages;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveTotpKey() {
|
||||
void shouldRemoveTotpKey() {
|
||||
// given
|
||||
String name = "aws";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).totpKey("some-totp-key").build();
|
||||
|
@ -70,7 +70,7 @@ public class RemoveTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleDatabaseError() {
|
||||
void shouldHandleDatabaseError() {
|
||||
// given
|
||||
String name = "aws";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).totpKey("some-totp-key").build();
|
||||
|
@ -91,7 +91,7 @@ public class RemoveTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleInvalidCode() {
|
||||
void shouldHandleInvalidCode() {
|
||||
// given
|
||||
String name = "cesar";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).totpKey("some-totp-key").build();
|
||||
|
@ -111,7 +111,7 @@ public class RemoveTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUserWithoutTotpKey() {
|
||||
void shouldHandleUserWithoutTotpKey() {
|
||||
// given
|
||||
String name = "cesar";
|
||||
PlayerAuth auth = PlayerAuth.builder().name(name).build();
|
||||
|
@ -130,7 +130,7 @@ public class RemoveTotpCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNonLoggedInUser() {
|
||||
void shouldHandleNonLoggedInUser() {
|
||||
// given
|
||||
String name = "cesar";
|
||||
given(playerCache.getAuth(name)).willReturn(null);
|
||||
|
|
|
@ -4,11 +4,11 @@ import fr.xephi.authme.command.CommandMapper;
|
|||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.help.HelpProvider;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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;
|
||||
|
||||
|
@ -19,8 +19,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link TotpBaseCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TotpBaseCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TotpBaseCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private TotpBaseCommand command;
|
||||
|
@ -31,7 +31,7 @@ public class TotpBaseCommandTest {
|
|||
private HelpProvider helpProvider;
|
||||
|
||||
@Test
|
||||
public void shouldOutputHelp() {
|
||||
void shouldOutputHelp() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
FoundCommandResult mappingResult = mock(FoundCommandResult.class);
|
||||
|
|
|
@ -7,17 +7,17 @@ import fr.xephi.authme.process.Management;
|
|||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.command.CommandSender;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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 org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -27,8 +27,8 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link UnregisterCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class UnregisterCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class UnregisterCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private UnregisterCommand command;
|
||||
|
@ -46,7 +46,7 @@ public class UnregisterCommandTest {
|
|||
private VerificationCodeManager codeManager;
|
||||
|
||||
@Test
|
||||
public void shouldCatchUnauthenticatedUser() {
|
||||
void shouldCatchUnauthenticatedUser() {
|
||||
// given
|
||||
String password = "mySecret123";
|
||||
String name = "player77";
|
||||
|
@ -64,7 +64,7 @@ public class UnregisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopForMissingVerificationCode() {
|
||||
void shouldStopForMissingVerificationCode() {
|
||||
// given
|
||||
String name = "asldjf";
|
||||
Player player = mock(Player.class);
|
||||
|
@ -83,7 +83,7 @@ public class UnregisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldForwardDataToAsyncTask() {
|
||||
void shouldForwardDataToAsyncTask() {
|
||||
// given
|
||||
String password = "p@ssw0rD";
|
||||
String name = "jas0n_";
|
||||
|
@ -102,7 +102,7 @@ public class UnregisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldStopIfSenderIsNotPlayer() {
|
||||
void shouldStopIfSenderIsNotPlayer() {
|
||||
// given
|
||||
CommandSender sender = mock(CommandSender.class);
|
||||
|
||||
|
@ -115,7 +115,7 @@ public class UnregisterCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_UNREGISTER));
|
||||
}
|
||||
|
|
|
@ -5,17 +5,17 @@ import fr.xephi.authme.data.VerificationCodeManager;
|
|||
import fr.xephi.authme.message.MessageKey;
|
||||
import fr.xephi.authme.service.CommonService;
|
||||
import org.bukkit.entity.Player;
|
||||
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 org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -23,8 +23,8 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link VerificationCommand}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VerificationCommandTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class VerificationCommandTest {
|
||||
|
||||
@InjectMocks
|
||||
private VerificationCommand command;
|
||||
|
@ -35,13 +35,13 @@ public class VerificationCommandTest {
|
|||
@Mock
|
||||
private VerificationCodeManager codeManager;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDetectIfMailHasASetup() {
|
||||
void shouldDetectIfMailHasASetup() {
|
||||
// given
|
||||
String name = "Alligator";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
@ -55,7 +55,7 @@ public class VerificationCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRequireAndAcceptCode() {
|
||||
void shouldRequireAndAcceptCode() {
|
||||
// given
|
||||
String name = "Duck";
|
||||
String code = "123932";
|
||||
|
@ -76,7 +76,7 @@ public class VerificationCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectCode() {
|
||||
void shouldRejectCode() {
|
||||
// given
|
||||
String name = "Spider";
|
||||
String code = "98345222"; // more than 6 digits
|
||||
|
@ -97,7 +97,7 @@ public class VerificationCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectVerificationDueToExpiration() {
|
||||
void shouldRejectVerificationDueToExpiration() {
|
||||
// given
|
||||
String name = "Dog";
|
||||
String code = "131552";
|
||||
|
@ -116,7 +116,7 @@ public class VerificationCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectVerificationDueToVerifiedIdentity() {
|
||||
void shouldRejectVerificationDueToVerifiedIdentity() {
|
||||
// given
|
||||
String name = "Cow";
|
||||
String code = "973583";
|
||||
|
@ -135,7 +135,7 @@ public class VerificationCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRejectVerificationDueToUndefinedEmail() {
|
||||
void shouldRejectVerificationDueToUndefinedEmail() {
|
||||
// given
|
||||
String name = "Frog";
|
||||
String code = "774543";
|
||||
|
@ -155,7 +155,7 @@ public class VerificationCommandTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDefineArgumentMismatchMessage() {
|
||||
void shouldDefineArgumentMismatchMessage() {
|
||||
// given / when / then
|
||||
assertThat(command.getArgumentsMismatchMessage(), equalTo(MessageKey.USAGE_VERIFICATION_CODE));
|
||||
}
|
||||
|
|
|
@ -1,22 +1,22 @@
|
|||
package fr.xephi.authme.command.help;
|
||||
|
||||
import fr.xephi.authme.util.StringUtils;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Test for enums {@link HelpMessage} and {@link HelpSection}.
|
||||
*/
|
||||
public class HelpMessageAndHelpSectionConsistencyTest {
|
||||
class HelpMessageAndHelpSectionConsistencyTest {
|
||||
|
||||
@Test
|
||||
public void shouldHaveUniqueNonEmptyKeys() {
|
||||
void shouldHaveUniqueNonEmptyKeys() {
|
||||
// given
|
||||
Set<String> keys = new HashSet<>();
|
||||
|
||||
|
|
|
@ -9,28 +9,28 @@ import fr.xephi.authme.message.MessagePathHelper;
|
|||
import org.bukkit.configuration.MemorySection;
|
||||
import org.bukkit.configuration.file.FileConfiguration;
|
||||
import org.bukkit.configuration.file.YamlConfiguration;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.io.File;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.instanceOf;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Tests that /messages/help_en.yml contains texts that correspond
|
||||
* to the texts provided in the CommandDescription.
|
||||
*/
|
||||
public class HelpMessagesConsistencyTest {
|
||||
class HelpMessagesConsistencyTest {
|
||||
|
||||
private static final File DEFAULT_MESSAGES_FILE =
|
||||
TestHelper.getJarFile("/" + MessagePathHelper.createHelpMessageFilePath(MessagePathHelper.DEFAULT_LANGUAGE));
|
||||
|
||||
@Test
|
||||
public void shouldHaveIdenticalTexts() {
|
||||
void shouldHaveIdenticalTexts() {
|
||||
// given
|
||||
CommandDescription description = getAuthMeRegisterDescription();
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(DEFAULT_MESSAGES_FILE);
|
||||
|
@ -50,7 +50,7 @@ public class HelpMessagesConsistencyTest {
|
|||
* only contains an entry for one command as to provide an example.
|
||||
*/
|
||||
@Test
|
||||
public void shouldOnlyHaveDescriptionForOneCommand() {
|
||||
void shouldOnlyHaveDescriptionForOneCommand() {
|
||||
// given
|
||||
FileConfiguration configuration = YamlConfiguration.loadConfiguration(DEFAULT_MESSAGES_FILE);
|
||||
|
||||
|
@ -63,7 +63,7 @@ public class HelpMessagesConsistencyTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveEntryForEachHelpMessageKey() {
|
||||
void shouldHaveEntryForEachHelpMessageKey() {
|
||||
// given
|
||||
PropertyReader reader = new YamlFileReader(DEFAULT_MESSAGES_FILE);
|
||||
|
||||
|
|
|
@ -5,46 +5,42 @@ import fr.xephi.authme.ReflectionTestUtils;
|
|||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.TestCommandsUtil;
|
||||
import fr.xephi.authme.message.AbstractMessageFileHandler;
|
||||
import fr.xephi.authme.message.HelpMessagesFileHandler;
|
||||
import fr.xephi.authme.message.MessagePathHelper;
|
||||
import fr.xephi.authme.permission.DefaultPermission;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.PluginSettings;
|
||||
import org.junit.Before;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.io.TempDir;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.util.Collection;
|
||||
|
||||
import static fr.xephi.authme.command.TestCommandsUtil.getCommandWithLabel;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.sameInstance;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link HelpMessagesService}.
|
||||
*/
|
||||
public class HelpMessagesServiceTest {
|
||||
class HelpMessagesServiceTest {
|
||||
|
||||
private static final String TEST_FILE = TestHelper.PROJECT_ROOT + "command/help/help_test.yml";
|
||||
private static final Collection<CommandDescription> COMMANDS = TestCommandsUtil.generateCommands();
|
||||
|
||||
private HelpMessagesService helpMessagesService;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
private File dataFolder;
|
||||
@TempDir
|
||||
File dataFolder;
|
||||
|
||||
@Before
|
||||
public void initializeHandler() throws IOException {
|
||||
dataFolder = temporaryFolder.newFolder();
|
||||
@BeforeEach
|
||||
void initializeHandler() throws IOException {
|
||||
new File(dataFolder, "messages").mkdirs();
|
||||
File messagesFile = new File(dataFolder, MessagePathHelper.createHelpMessageFilePath("test"));
|
||||
Files.copy(TestHelper.getJarFile(TEST_FILE), messagesFile);
|
||||
|
@ -54,7 +50,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnLocalizedCommand() {
|
||||
void shouldReturnLocalizedCommand() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(COMMANDS, "authme", "register");
|
||||
|
||||
|
@ -74,7 +70,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnLocalizedCommandWithDefaults() {
|
||||
void shouldReturnLocalizedCommandWithDefaults() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(COMMANDS, "authme", "login");
|
||||
|
||||
|
@ -90,7 +86,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnSameCommandForNoLocalization() {
|
||||
void shouldReturnSameCommandForNoLocalization() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(COMMANDS, "email");
|
||||
|
||||
|
@ -102,7 +98,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldKeepChildrenInLocalCommand() {
|
||||
void shouldKeepChildrenInLocalCommand() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(COMMANDS, "authme");
|
||||
|
||||
|
@ -116,7 +112,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetTranslationsForSectionAndMessage() {
|
||||
void shouldGetTranslationsForSectionAndMessage() {
|
||||
// given / when / then
|
||||
assertThat(helpMessagesService.getMessage(DefaultPermission.OP_ONLY), equalTo("only op"));
|
||||
assertThat(helpMessagesService.getMessage(HelpMessage.RESULT), equalTo("res."));
|
||||
|
@ -124,7 +120,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLocalCommandDescription() {
|
||||
void shouldGetLocalCommandDescription() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(COMMANDS, "authme", "register");
|
||||
|
||||
|
@ -136,7 +132,7 @@ public class HelpMessagesServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFallbackToDescriptionOnCommandObject() {
|
||||
void shouldFallbackToDescriptionOnCommandObject() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(COMMANDS, "unregister");
|
||||
|
||||
|
@ -151,9 +147,7 @@ public class HelpMessagesServiceTest {
|
|||
Settings settings = mock(Settings.class);
|
||||
given(settings.getProperty(PluginSettings.MESSAGES_LANGUAGE)).willReturn("test");
|
||||
|
||||
HelpMessagesFileHandler messagesFileHandler = ReflectionTestUtils.newInstance(HelpMessagesFileHandler.class);
|
||||
ReflectionTestUtils.setField(AbstractMessageFileHandler.class, messagesFileHandler, "settings", settings);
|
||||
ReflectionTestUtils.setField(AbstractMessageFileHandler.class, messagesFileHandler, "dataFolder", dataFolder);
|
||||
HelpMessagesFileHandler messagesFileHandler = new HelpMessagesFileHandler(dataFolder, settings);
|
||||
ReflectionTestUtils.invokePostConstructMethods(messagesFileHandler);
|
||||
return messagesFileHandler;
|
||||
}
|
||||
|
|
|
@ -1,8 +1,5 @@
|
|||
package fr.xephi.authme.command.help;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.command.CommandDescription;
|
||||
import fr.xephi.authme.command.FoundCommandResult;
|
||||
import fr.xephi.authme.command.FoundResultStatus;
|
||||
|
@ -12,12 +9,14 @@ import fr.xephi.authme.permission.DefaultPermission;
|
|||
import fr.xephi.authme.permission.PermissionsManager;
|
||||
import org.bukkit.ChatColor;
|
||||
import org.bukkit.command.CommandSender;
|
||||
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.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.internal.stubbing.answers.ReturnsArgumentAt;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
|
@ -35,15 +34,16 @@ import static fr.xephi.authme.command.help.HelpProvider.SHOW_COMMAND;
|
|||
import static fr.xephi.authme.command.help.HelpProvider.SHOW_DESCRIPTION;
|
||||
import static fr.xephi.authme.command.help.HelpProvider.SHOW_LONG_DESCRIPTION;
|
||||
import static fr.xephi.authme.command.help.HelpProvider.SHOW_PERMISSIONS;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsString;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.atLeastOnce;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.never;
|
||||
import static org.mockito.Mockito.verify;
|
||||
|
@ -51,12 +51,11 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* Test for {@link HelpProvider}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class HelpProviderTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class HelpProviderTest {
|
||||
|
||||
private static Collection<CommandDescription> commands;
|
||||
|
||||
@InjectDelayed
|
||||
private HelpProvider helpProvider;
|
||||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
|
@ -65,18 +64,19 @@ public class HelpProviderTest {
|
|||
@Mock
|
||||
private CommandSender sender;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpCommands() {
|
||||
@BeforeAll
|
||||
static void setUpCommands() {
|
||||
commands = TestCommandsUtil.generateCommands();
|
||||
}
|
||||
|
||||
@BeforeInjecting
|
||||
public void setInitialSettings() {
|
||||
@BeforeEach
|
||||
void initializeHelpProvider() {
|
||||
setDefaultHelpMessages(helpMessagesService);
|
||||
helpProvider = new HelpProvider(permissionsManager, helpMessagesService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowLongDescription() {
|
||||
void shouldShowLongDescription() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "login");
|
||||
FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "login"));
|
||||
|
@ -95,7 +95,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowArguments() {
|
||||
void shouldShowArguments() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "reg"));
|
||||
|
@ -113,7 +113,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowSpecifyIfArgumentIsOptional() {
|
||||
void shouldShowSpecifyIfArgumentIsOptional() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "email");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("email"));
|
||||
|
@ -129,7 +129,7 @@ public class HelpProviderTest {
|
|||
|
||||
/** Verifies that the "Arguments:" line is not shown if the command has no arguments. */
|
||||
@Test
|
||||
public void shouldNotShowAnythingIfCommandHasNoArguments() {
|
||||
void shouldNotShowAnythingIfCommandHasNoArguments() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
|
||||
|
@ -143,7 +143,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowAndEvaluatePermissions() {
|
||||
void shouldShowAndEvaluatePermissions() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "unregister");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unreg"));
|
||||
|
@ -165,7 +165,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowAndEvaluateForbiddenPermissions() {
|
||||
void shouldShowAndEvaluateForbiddenPermissions() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "unregister");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unregister"));
|
||||
|
@ -187,7 +187,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotShowAnythingForEmptyPermissions() {
|
||||
void shouldNotShowAnythingForEmptyPermissions() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
|
||||
|
@ -201,7 +201,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotShowAnythingForNullPermissionsOnCommand() {
|
||||
void shouldNotShowAnythingForNullPermissionsOnCommand() {
|
||||
// given
|
||||
CommandDescription command = mock(CommandDescription.class);
|
||||
given(command.getPermission()).willReturn(null);
|
||||
|
@ -217,7 +217,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowAlternatives() {
|
||||
void shouldShowAlternatives() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "reg"));
|
||||
|
@ -234,7 +234,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotShowAnythingIfHasNoAlternatives() {
|
||||
void shouldNotShowAnythingIfHasNoAlternatives() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "login");
|
||||
FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "login"));
|
||||
|
@ -248,7 +248,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowChildren() {
|
||||
void shouldShowChildren() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
|
||||
|
@ -269,7 +269,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotShowCommandsTitleForCommandWithNoChildren() {
|
||||
void shouldNotShowCommandsTitleForCommandWithNoChildren() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("authme"));
|
||||
|
@ -283,7 +283,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleUnboundFoundCommandResult() {
|
||||
void shouldHandleUnboundFoundCommandResult() {
|
||||
// given
|
||||
FoundCommandResult result = new FoundCommandResult(null, Arrays.asList("authme", "test"),
|
||||
Collections.emptyList(), 0.0, FoundResultStatus.UNKNOWN_LABEL);
|
||||
|
@ -302,7 +302,7 @@ public class HelpProviderTest {
|
|||
* (e.g. suggest "register command" for /authme ragister), we need to check the labels and construct a correct list
|
||||
*/
|
||||
@Test
|
||||
public void shouldShowCommandSyntaxWithCorrectLabels() {
|
||||
void shouldShowCommandSyntaxWithCorrectLabels() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
FoundCommandResult result = newFoundResult(command, Arrays.asList("authme", "ragister"));
|
||||
|
@ -318,7 +318,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRetainCorrectLabels() {
|
||||
void shouldRetainCorrectLabels() {
|
||||
// given
|
||||
List<String> labels = Arrays.asList("authme", "reg");
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
|
@ -331,7 +331,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceIncorrectLabels() {
|
||||
void shouldReplaceIncorrectLabels() {
|
||||
// given
|
||||
List<String> labels = Arrays.asList("authme", "wrong");
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
|
@ -344,7 +344,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDisableSectionsWithEmptyTranslations() {
|
||||
void shouldDisableSectionsWithEmptyTranslations() {
|
||||
// given
|
||||
given(helpMessagesService.getMessage(HelpSection.DETAILED_DESCRIPTION)).willReturn("");
|
||||
given(helpMessagesService.getMessage(HelpSection.ALTERNATIVES)).willReturn("");
|
||||
|
@ -368,7 +368,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotReturnAnythingForAllDisabledSections() {
|
||||
void shouldNotReturnAnythingForAllDisabledSections() {
|
||||
// given
|
||||
given(helpMessagesService.getMessage(HelpSection.COMMAND)).willReturn("");
|
||||
given(helpMessagesService.getMessage(HelpSection.ALTERNATIVES)).willReturn("");
|
||||
|
@ -385,7 +385,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSkipEmptyHeader() {
|
||||
void shouldSkipEmptyHeader() {
|
||||
// given
|
||||
given(helpMessagesService.getMessage(HelpMessage.HEADER)).willReturn("");
|
||||
CommandDescription command = getCommandWithLabel(commands, "authme", "register");
|
||||
|
@ -401,7 +401,7 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldShowAlternativesForRootCommand() {
|
||||
void shouldShowAlternativesForRootCommand() {
|
||||
// given
|
||||
CommandDescription command = getCommandWithLabel(commands, "unregister");
|
||||
FoundCommandResult result = newFoundResult(command, Collections.singletonList("unreg"));
|
||||
|
@ -444,22 +444,22 @@ public class HelpProviderTest {
|
|||
}
|
||||
|
||||
private static void setDefaultHelpMessages(HelpMessagesService helpMessagesService) {
|
||||
given(helpMessagesService.buildLocalizedDescription(any(CommandDescription.class)))
|
||||
.willAnswer(new ReturnsArgumentAt(0));
|
||||
lenient().when(helpMessagesService.buildLocalizedDescription(any(CommandDescription.class)))
|
||||
.thenAnswer(new ReturnsArgumentAt(0));
|
||||
for (HelpMessage key : HelpMessage.values()) {
|
||||
String text = key.name().replace("_", " ").toLowerCase(Locale.ROOT);
|
||||
given(helpMessagesService.getMessage(key))
|
||||
.willReturn(text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1));
|
||||
lenient().when(helpMessagesService.getMessage(key))
|
||||
.thenReturn(text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1));
|
||||
}
|
||||
for (DefaultPermission permission : DefaultPermission.values()) {
|
||||
String text = permission.name().replace("_", " ").toLowerCase(Locale.ROOT);
|
||||
given(helpMessagesService.getMessage(permission))
|
||||
.willReturn(text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1));
|
||||
lenient().when(helpMessagesService.getMessage(permission))
|
||||
.thenReturn(text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1));
|
||||
}
|
||||
for (HelpSection section : HelpSection.values()) {
|
||||
String text = section.name().replace("_", " ").toLowerCase(Locale.ROOT);
|
||||
given(helpMessagesService.getMessage(section))
|
||||
.willReturn(text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1));
|
||||
lenient().when(helpMessagesService.getMessage(section))
|
||||
.thenReturn(text.substring(0, 1).toUpperCase(Locale.ROOT) + text.substring(1));
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -5,21 +5,21 @@ import fr.xephi.authme.permission.PlayerPermission;
|
|||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.ProtectionSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
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.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link QuickCommandsProtectionManager}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class QuickCommandsProtectionManagerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class QuickCommandsProtectionManagerTest {
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
|
@ -28,7 +28,7 @@ public class QuickCommandsProtectionManagerTest {
|
|||
private PermissionsManager permissionsManager;
|
||||
|
||||
@Test
|
||||
public void shouldAllowCommand() {
|
||||
void shouldAllowCommand() {
|
||||
// given
|
||||
String playername = "PlayerName";
|
||||
Player player = mockPlayerWithName(playername);
|
||||
|
@ -50,7 +50,7 @@ public class QuickCommandsProtectionManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDenyCommand() {
|
||||
void shouldDenyCommand() {
|
||||
// given
|
||||
String name = "TestName1";
|
||||
Player player = mockPlayerWithName(name);
|
||||
|
|
|
@ -9,11 +9,11 @@ import fr.xephi.authme.settings.Settings;
|
|||
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.runner.RunWith;
|
||||
import org.junit.jupiter.api.Test;
|
||||
import org.junit.jupiter.api.extension.ExtendWith;
|
||||
import org.mockito.ArgumentCaptor;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.MockitoJUnitRunner;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
|
@ -21,10 +21,10 @@ import java.util.HashMap;
|
|||
import java.util.Map;
|
||||
|
||||
import static fr.xephi.authme.service.BukkitServiceTestHelper.setBukkitServiceToScheduleSyncDelayedTask;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.lessThan;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
@ -34,8 +34,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link TempbanManager}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class TempbanManagerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class TempbanManagerTest {
|
||||
|
||||
private static final long DATE_TOLERANCE_MILLISECONDS = 200L;
|
||||
private static final long TEST_EXPIRATION_THRESHOLD = 120_000L;
|
||||
|
@ -47,7 +47,7 @@ public class TempbanManagerTest {
|
|||
private Messages messages;
|
||||
|
||||
@Test
|
||||
public void shouldAddCounts() {
|
||||
void shouldAddCounts() {
|
||||
// given
|
||||
Settings settings = mockSettings(3, 60, "");
|
||||
TempbanManager manager = new TempbanManager(bukkitService, messages, settings);
|
||||
|
@ -67,7 +67,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldIncreaseAndResetCount() {
|
||||
void shouldIncreaseAndResetCount() {
|
||||
// given
|
||||
String address = "192.168.1.2";
|
||||
Settings settings = mockSettings(3, 60, "");
|
||||
|
@ -91,7 +91,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotIncreaseCountForDisabledTempban() {
|
||||
void shouldNotIncreaseCountForDisabledTempban() {
|
||||
// given
|
||||
String address = "192.168.1.3";
|
||||
Settings settings = mockSettings(1, 5, "");
|
||||
|
@ -107,7 +107,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCheckCountIfTempbanIsDisabled() {
|
||||
void shouldNotCheckCountIfTempbanIsDisabled() {
|
||||
// given
|
||||
String address = "192.168.1.4";
|
||||
Settings settings = mockSettings(1, 5, "");
|
||||
|
@ -128,7 +128,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotIssueBanIfDisabled() {
|
||||
void shouldNotIssueBanIfDisabled() {
|
||||
// given
|
||||
Settings settings = mockSettings(0, 0, "");
|
||||
given(settings.getProperty(SecuritySettings.TEMPBAN_ON_MAX_LOGINS)).willReturn(false);
|
||||
|
@ -143,7 +143,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldBanPlayerIp() {
|
||||
void shouldBanPlayerIp() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String ip = "123.45.67.89";
|
||||
|
@ -170,7 +170,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldBanPlayerIpCustom() {
|
||||
void shouldBanPlayerIpCustom() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.getName()).willReturn("Bob");
|
||||
|
@ -189,7 +189,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldResetCountAfterBan() {
|
||||
void shouldResetCountAfterBan() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
String ip = "22.44.66.88";
|
||||
|
@ -212,7 +212,7 @@ public class TempbanManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformCleanup() {
|
||||
void shouldPerformCleanup() {
|
||||
// given
|
||||
Map<String, TimedCounter<String>> counts = new HashMap<>();
|
||||
TimedCounter<String> counter1 = mockCounter();
|
||||
|
|
|
@ -8,14 +8,14 @@ import fr.xephi.authme.permission.PlayerPermission;
|
|||
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.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.only;
|
||||
|
@ -25,8 +25,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* Test for {@link VerificationCodeManager}.
|
||||
*/
|
||||
@RunWith(MockitoJUnitRunner.class)
|
||||
public class VerificationCodeManagerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class VerificationCodeManagerTest {
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
|
@ -40,15 +40,15 @@ public class VerificationCodeManagerTest {
|
|||
@Mock
|
||||
private PermissionsManager permissionsManager;
|
||||
|
||||
@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"));
|
||||
|
@ -71,7 +71,7 @@ public class VerificationCodeManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRequireVerificationIfEmailSettingsAreIncomplete() {
|
||||
void shouldNotRequireVerificationIfEmailSettingsAreIncomplete() {
|
||||
// given
|
||||
given(emailService.hasAllInformation()).willReturn(false);
|
||||
VerificationCodeManager codeManager = createCodeManager();
|
||||
|
@ -86,8 +86,9 @@ public class VerificationCodeManagerTest {
|
|||
}
|
||||
|
||||
@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();
|
||||
|
@ -102,8 +103,9 @@ public class VerificationCodeManagerTest {
|
|||
}
|
||||
|
||||
@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));
|
||||
|
@ -121,8 +123,9 @@ public class VerificationCodeManagerTest {
|
|||
}
|
||||
|
||||
@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));
|
||||
|
@ -140,8 +143,9 @@ public class VerificationCodeManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldVerifyCode() {
|
||||
void shouldVerifyCode() {
|
||||
// given
|
||||
given(emailService.hasAllInformation()).willReturn(true);
|
||||
String player = "ILoveTests";
|
||||
String code = "193458";
|
||||
String email = "ilovetests@test.com";
|
||||
|
|
|
@ -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 class PlayerAuthTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldThrowForMissingName() {
|
||||
void shouldThrowForMissingName() {
|
||||
try {
|
||||
// given / when
|
||||
PlayerAuth.builder()
|
||||
|
@ -48,7 +48,7 @@ public class PlayerAuthTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreatePlayerAuthWithNullValues() {
|
||||
void shouldCreatePlayerAuthWithNullValues() {
|
||||
// given / when
|
||||
PlayerAuth auth = PlayerAuth.builder()
|
||||
.name("Charlie")
|
||||
|
|
|
@ -5,24 +5,24 @@ import fr.xephi.authme.settings.Settings;
|
|||
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.junit.Assert.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 class LoginCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateAndCheckCaptcha() {
|
||||
void shouldCreateAndCheckCaptcha() {
|
||||
// given
|
||||
String name = "Miner";
|
||||
Player player = mock(Player.class);
|
||||
|
@ -61,7 +61,7 @@ public class LoginCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateNewCodeOnFailure() {
|
||||
void shouldGenerateNewCodeOnFailure() {
|
||||
// given
|
||||
String name = "Tarheel";
|
||||
Player player = mock(Player.class);
|
||||
|
@ -80,7 +80,7 @@ public class LoginCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveSameCodeAfterGeneration() {
|
||||
void shouldHaveSameCodeAfterGeneration() {
|
||||
// given
|
||||
String player = "Tester";
|
||||
Settings settings = mockSettings(1, 5);
|
||||
|
@ -98,7 +98,7 @@ public class LoginCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldIncreaseAndResetCount() {
|
||||
void shouldIncreaseAndResetCount() {
|
||||
// given
|
||||
String player = "plaYer";
|
||||
Settings settings = mockSettings(2, 3);
|
||||
|
@ -121,7 +121,7 @@ public class LoginCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotIncreaseCountForDisabledCaptcha() {
|
||||
void shouldNotIncreaseCountForDisabledCaptcha() {
|
||||
// given
|
||||
String player = "someone_";
|
||||
Settings settings = mockSettings(1, 3);
|
||||
|
@ -137,7 +137,7 @@ public class LoginCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotCheckCountIfCaptchaIsDisabled() {
|
||||
void shouldNotCheckCountIfCaptchaIsDisabled() {
|
||||
// given
|
||||
String player = "Robert001";
|
||||
Settings settings = mockSettings(1, 5);
|
||||
|
|
|
@ -5,21 +5,21 @@ import fr.xephi.authme.settings.Settings;
|
|||
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.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
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 class RegistrationCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@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 class RegistrationCaptchaManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGenerateAndRetrieveCode() {
|
||||
void shouldGenerateAndRetrieveCode() {
|
||||
// given
|
||||
Settings settings = mock(Settings.class);
|
||||
given(settings.getProperty(SecuritySettings.ENABLE_CAPTCHA_FOR_REGISTRATION)).willReturn(true);
|
||||
|
|
|
@ -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 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* 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 class AllowFlightRestoreTypeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldEnableFlight() {
|
||||
void shouldEnableFlight() {
|
||||
// given
|
||||
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
|
||||
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
|
||||
|
@ -49,7 +49,7 @@ public class AllowFlightRestoreTypeTest {
|
|||
|
||||
|
||||
@Test
|
||||
public void shouldDisableFlight() {
|
||||
void shouldDisableFlight() {
|
||||
// given
|
||||
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
|
||||
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
|
||||
|
@ -66,7 +66,7 @@ public class AllowFlightRestoreTypeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotInteractWithPlayer() {
|
||||
void shouldNotInteractWithPlayer() {
|
||||
// given
|
||||
LimboPlayer limboWithFly = newLimboWithAllowFlight(true);
|
||||
LimboPlayer limboWithoutFly = newLimboWithAllowFlight(false);
|
||||
|
@ -82,7 +82,7 @@ public class AllowFlightRestoreTypeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveFlightExceptForNothingType() {
|
||||
void shouldRemoveFlightExceptForNothingType() {
|
||||
// given
|
||||
AllowFlightRestoreType noInteractionType = AllowFlightRestoreType.NOTHING;
|
||||
|
||||
|
|
|
@ -13,21 +13,21 @@ import fr.xephi.authme.task.MessageTask;
|
|||
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.junit.Assert.assertThat;
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
import static org.mockito.ArgumentMatchers.anyLong;
|
||||
import static org.mockito.ArgumentMatchers.eq;
|
||||
|
@ -39,8 +39,8 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* 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 class LimboPlayerTaskManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotScheduleTaskForZeroAsInterval() {
|
||||
void shouldNotScheduleTaskForZeroAsInterval() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
|
@ -101,7 +101,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCancelExistingMessageTask() {
|
||||
void shouldCancelExistingMessageTask() {
|
||||
// given
|
||||
String name = "rats";
|
||||
Player player = mock(Player.class);
|
||||
|
@ -124,7 +124,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeMessageTaskWithCaptchaMessage() {
|
||||
void shouldInitializeMessageTaskWithCaptchaMessage() {
|
||||
// given
|
||||
String name = "race";
|
||||
Player player = mock(Player.class);
|
||||
|
@ -145,7 +145,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRegisterTimeoutTask() {
|
||||
void shouldRegisterTimeoutTask() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
|
@ -163,7 +163,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldNotRegisterTimeoutTaskForZeroTimeout() {
|
||||
void shouldNotRegisterTimeoutTaskForZeroTimeout() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limboPlayer = mock(LimboPlayer.class);
|
||||
|
@ -177,7 +177,7 @@ public class LimboPlayerTaskManagerTest {
|
|||
}
|
||||
|
||||
@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);
|
||||
|
|
|
@ -2,18 +2,18 @@ package fr.xephi.authme.data.limbo;
|
|||
|
||||
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.junit.Assert.assertThat;
|
||||
import static org.mockito.Mockito.mock;
|
||||
import static org.mockito.Mockito.verifyNoInteractions;
|
||||
|
||||
|
@ -22,19 +22,19 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
* <p>
|
||||
* 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);
|
||||
|
@ -54,7 +54,7 @@ public class LimboServiceHelperTest {
|
|||
}
|
||||
|
||||
@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);
|
||||
|
@ -73,7 +73,7 @@ public class LimboServiceHelperTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleNullInputs() {
|
||||
void shouldHandleNullInputs() {
|
||||
// given
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
|
||||
|
|
|
@ -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.LimboSettings;
|
|||
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.junit.Assert.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 @@ import static org.mockito.Mockito.verifyNoInteractions;
|
|||
/**
|
||||
* 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
|
||||
public static void initLogger() {
|
||||
@BeforeAll
|
||||
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 class LimboServiceTest {
|
|||
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 class LimboServiceTest {
|
|||
}
|
||||
|
||||
@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 class LimboServiceTest {
|
|||
}
|
||||
|
||||
@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 class LimboServiceTest {
|
|||
}
|
||||
|
||||
@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);
|
||||
|
||||
|
@ -184,7 +187,7 @@ public class LimboServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingLimboPlayerWhileRestoring() {
|
||||
void shouldHandleMissingLimboPlayerWhileRestoring() {
|
||||
// given
|
||||
Player player = newPlayer("Test");
|
||||
|
||||
|
@ -197,7 +200,7 @@ public class LimboServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReplaceTasks() {
|
||||
void shouldReplaceTasks() {
|
||||
// given
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
getLimboMap().put("jeff", limbo);
|
||||
|
@ -214,7 +217,7 @@ public class LimboServiceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleMissingLimboForReplaceTasks() {
|
||||
void shouldHandleMissingLimboForReplaceTasks() {
|
||||
// given
|
||||
Player player = newPlayer("ghost");
|
||||
|
||||
|
@ -234,16 +237,16 @@ public class LimboServiceTest {
|
|||
|
||||
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<UserGroup> 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<String, LimboPlayer> getLimboMap() {
|
||||
|
|
|
@ -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 @@ import static org.mockito.Mockito.verify;
|
|||
/**
|
||||
* 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 class WalkFlySpeedRestoreTypeTest {
|
|||
verify(player).setWalkSpeed(parameters.expectedWalkSpeed);
|
||||
verify(player).setFlySpeed(parameters.expectedFlySpeed);
|
||||
}
|
||||
|
||||
@Parameterized.Parameters(name = "{0}")
|
||||
public static List<Object[]> buildParams() {
|
||||
List<TestParameters> parameters = Arrays.asList(
|
||||
|
||||
private static List<TestParameters> buildParams() {
|
||||
return Arrays.asList(
|
||||
create(RESTORE).withLimbo(0.1f, 0.4f).withPlayer(0.3f, 0.9f).expect(0.1f, 0.4f),
|
||||
create(RESTORE).withLimbo(0.9f, 0.2f).withPlayer(0.3f, 0.0f).expect(0.9f, 0.2f),
|
||||
create(MAX_RESTORE).withLimbo(0.3f, 0.8f).withPlayer(0.5f, 0.2f).expect(0.5f, 0.8f),
|
||||
|
@ -62,9 +53,6 @@ public class WalkFlySpeedRestoreTypeTest {
|
|||
create(RESTORE_NO_ZERO).withLimbo(0.0f, 0.005f).withPlayer(0.4f, 0.8f).expect(DEFAULT_WALK_SPEED, DEFAULT_FLY_SPEED),
|
||||
create(DEFAULT).withLimbo(0.1f, 0.7f).withPlayer(0.4f, 0.0f).expect(DEFAULT_WALK_SPEED, DEFAULT_FLY_SPEED)
|
||||
);
|
||||
|
||||
// Convert List<TestParameters> to List<Object[]>
|
||||
return parameters.stream().map(p -> new Object[]{p}).collect(Collectors.toList());
|
||||
}
|
||||
|
||||
private static TestParameters create(WalkFlySpeedRestoreType testedType) {
|
||||
|
|
|
@ -1,13 +1,9 @@
|
|||
package fr.xephi.authme.data.limbo.persistence;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import com.google.common.io.Files;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.data.limbo.UserGroup;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.LimboSettings;
|
||||
|
@ -15,12 +11,13 @@ import org.bukkit.Location;
|
|||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.hamcrest.Matcher;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
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.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -38,13 +35,14 @@ import static org.hamcrest.Matchers.equalTo;
|
|||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.mockito.ArgumentMatchers.anyString;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.lenient;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link DistributedFilesPersistenceHandler}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class DistributedFilesPersistenceHandlerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class DistributedFilesPersistenceHandlerTest {
|
||||
|
||||
/** Player is in seg32-10110 and should be migrated into seg16-f. */
|
||||
private static final UUID MIGRATED_UUID = fromString("f6a97c88-7c8f-c12e-4931-6206d4ca067d");
|
||||
|
@ -73,29 +71,24 @@ public class DistributedFilesPersistenceHandlerTest {
|
|||
private static final UUID UNKNOWN_UUID2 = fromString("84d1cc0b-8f12-d04a-e7ba-a067d05cdc39");
|
||||
|
||||
|
||||
@InjectDelayed
|
||||
private DistributedFilesPersistenceHandler persistenceHandler;
|
||||
|
||||
@Mock
|
||||
private Settings settings;
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
@DataFolder
|
||||
private File dataFolder;
|
||||
@TempDir
|
||||
File dataFolder;
|
||||
private File playerDataFolder;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@BeforeClass
|
||||
public static void initLogger() {
|
||||
@BeforeAll
|
||||
static void initLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@BeforeInjecting
|
||||
public void setUpClasses() throws IOException {
|
||||
@BeforeEach
|
||||
void setUpClasses() throws IOException {
|
||||
given(settings.getProperty(LimboSettings.DISTRIBUTION_SIZE)).willReturn(SegmentSize.SIXTEEN);
|
||||
dataFolder = temporaryFolder.newFolder();
|
||||
playerDataFolder = new File(dataFolder, "playerdata");
|
||||
playerDataFolder.mkdir();
|
||||
|
||||
|
@ -108,16 +101,18 @@ public class DistributedFilesPersistenceHandlerTest {
|
|||
given(bukkitService.getWorld(anyString()))
|
||||
.willAnswer(invocation -> {
|
||||
World world = mock(World.class);
|
||||
given(world.getName()).willReturn(invocation.getArgument(0));
|
||||
lenient().when(world.getName()).thenReturn(invocation.getArgument(0));
|
||||
return world;
|
||||
});
|
||||
|
||||
persistenceHandler = new DistributedFilesPersistenceHandler(dataFolder, bukkitService, settings);
|
||||
}
|
||||
|
||||
// Note ljacqu 20170314: These tests are a little slow to set up; therefore we sometimes
|
||||
// test things in one test that would traditionally belong into two separate tests
|
||||
|
||||
@Test
|
||||
public void shouldMigrateOldSegmentFilesOnStartup() {
|
||||
void shouldMigrateOldSegmentFilesOnStartup() {
|
||||
// Ensure that only the files of the current segmenting scheme remain
|
||||
assertThat(playerDataFolder.list(), arrayContainingInAnyOrder("seg16-8-limbo.json", "seg16-f-limbo.json"));
|
||||
|
||||
|
@ -133,7 +128,7 @@ public class DistributedFilesPersistenceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemovePlayer() {
|
||||
void shouldRemovePlayer() {
|
||||
// given
|
||||
Player playerToRemove = mockPlayerWithUuid(UUID_STAFF);
|
||||
Player unknownPlayerToRemove = mockPlayerWithUuid(UNKNOWN_UUID);
|
||||
|
@ -153,7 +148,7 @@ public class DistributedFilesPersistenceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldAddPlayer() {
|
||||
void shouldAddPlayer() {
|
||||
// given
|
||||
Player uuidToAdd1 = mockPlayerWithUuid(UNKNOWN_UUID);
|
||||
Location location1 = mockLocation("1world");
|
||||
|
@ -181,7 +176,7 @@ public class DistributedFilesPersistenceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleReadErrorGracefully() throws IOException {
|
||||
void shouldHandleReadErrorGracefully() throws IOException {
|
||||
// given
|
||||
// assumption
|
||||
File invalidFile = new File(playerDataFolder, "seg16-4-limbo.json");
|
||||
|
|
|
@ -1,22 +1,19 @@
|
|||
package fr.xephi.authme.data.limbo.persistence;
|
||||
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
import ch.jalu.injector.testing.DelayedInjectionRunner;
|
||||
import ch.jalu.injector.testing.InjectDelayed;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.limbo.LimboPlayer;
|
||||
import fr.xephi.authme.data.limbo.UserGroup;
|
||||
import fr.xephi.authme.initialization.DataFolder;
|
||||
import fr.xephi.authme.service.BukkitService;
|
||||
import fr.xephi.authme.util.FileUtils;
|
||||
import org.bukkit.Location;
|
||||
import org.bukkit.World;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.junit.Rule;
|
||||
import org.junit.Test;
|
||||
import org.junit.rules.TemporaryFolder;
|
||||
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.junit.jupiter.api.io.TempDir;
|
||||
import org.mockito.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
import java.io.File;
|
||||
import java.io.IOException;
|
||||
|
@ -24,48 +21,45 @@ import java.nio.file.Files;
|
|||
import java.util.Collections;
|
||||
import java.util.UUID;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.not;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link IndividualFilesPersistenceHandler}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class IndividualFilesPersistenceHandlerTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class IndividualFilesPersistenceHandlerTest {
|
||||
|
||||
private static final UUID SAMPLE_UUID = UUID.nameUUIDFromBytes("PersistenceTest".getBytes());
|
||||
private static final String SOURCE_FOLDER = TestHelper.PROJECT_ROOT + "data/backup/";
|
||||
|
||||
@InjectDelayed
|
||||
private IndividualFilesPersistenceHandler handler;
|
||||
|
||||
@Mock
|
||||
private BukkitService bukkitService;
|
||||
|
||||
@DataFolder
|
||||
private File dataFolder;
|
||||
@TempDir
|
||||
File dataFolder;
|
||||
|
||||
@Rule
|
||||
public TemporaryFolder temporaryFolder = new TemporaryFolder();
|
||||
|
||||
@BeforeInjecting
|
||||
public void copyTestFiles() throws IOException {
|
||||
dataFolder = temporaryFolder.newFolder();
|
||||
@BeforeEach
|
||||
void copyTestFilesAndInitHandler() throws IOException {
|
||||
File playerFolder = new File(dataFolder, FileUtils.makePath("playerdata", SAMPLE_UUID.toString()));
|
||||
if (!playerFolder.mkdirs()) {
|
||||
throw new IllegalStateException("Cannot create '" + playerFolder.getAbsolutePath() + "'");
|
||||
}
|
||||
Files.copy(TestHelper.getJarPath(FileUtils.makePath(SOURCE_FOLDER, "sample-folder", "data.json")),
|
||||
new File(playerFolder, "data.json").toPath());
|
||||
|
||||
handler = new IndividualFilesPersistenceHandler(dataFolder, bukkitService);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldReadDataFromFile() {
|
||||
void shouldReadDataFromFile() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.getUniqueId()).willReturn(SAMPLE_UUID);
|
||||
|
@ -92,7 +86,7 @@ public class IndividualFilesPersistenceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnNullForUnavailablePlayer() {
|
||||
void shouldReturnNullForUnavailablePlayer() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
given(player.getUniqueId()).willReturn(UUID.nameUUIDFromBytes("other-player".getBytes()));
|
||||
|
@ -105,7 +99,7 @@ public class IndividualFilesPersistenceHandlerTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSavePlayerData() {
|
||||
void shouldSavePlayerData() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
UUID uuid = UUID.nameUUIDFromBytes("New player".getBytes());
|
||||
|
|
|
@ -1,9 +1,6 @@
|
|||
package fr.xephi.authme.data.limbo.persistence;
|
||||
|
||||
import ch.jalu.injector.factory.Factory;
|
||||
import ch.jalu.injector.testing.BeforeInjecting;
|
||||
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.LimboPlayer;
|
||||
|
@ -11,13 +8,16 @@ import fr.xephi.authme.settings.Settings;
|
|||
import fr.xephi.authme.settings.properties.LimboSettings;
|
||||
import org.bukkit.entity.Player;
|
||||
import org.hamcrest.Matcher;
|
||||
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.Mock;
|
||||
import org.mockito.junit.jupiter.MockitoExtension;
|
||||
|
||||
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 +25,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;
|
||||
|
@ -37,10 +36,9 @@ import static org.mockito.hamcrest.MockitoHamcrest.argThat;
|
|||
/**
|
||||
* Test for {@link LimboPersistence}.
|
||||
*/
|
||||
@RunWith(DelayedInjectionRunner.class)
|
||||
public class LimboPersistenceTest {
|
||||
@ExtendWith(MockitoExtension.class)
|
||||
class LimboPersistenceTest {
|
||||
|
||||
@InjectDelayed
|
||||
private LimboPersistence limboPersistence;
|
||||
|
||||
@Mock
|
||||
|
@ -49,27 +47,28 @@ public class LimboPersistenceTest {
|
|||
@Mock
|
||||
private Settings settings;
|
||||
|
||||
@BeforeClass
|
||||
public static void setUpLogger() {
|
||||
@BeforeAll
|
||||
static void setUpLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
@BeforeInjecting
|
||||
@BeforeEach
|
||||
@SuppressWarnings("unchecked")
|
||||
public void setUpMocks() {
|
||||
void setUpMocksAndLimboPersistence() {
|
||||
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)));
|
||||
limboPersistence = new LimboPersistence(settings, handlerFactory);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldInitializeProperly() {
|
||||
void shouldInitializeProperly() {
|
||||
// given / when / then
|
||||
assertThat(getHandler(), instanceOf(NoOpPersistenceHandler.class));
|
||||
}
|
||||
|
||||
@Test
|
||||
public void shouldDelegateToHandler() {
|
||||
void shouldDelegateToHandler() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPersistenceHandler handler = getHandler();
|
||||
|
@ -89,7 +88,7 @@ public class LimboPersistenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReloadProperly() {
|
||||
void shouldReloadProperly() {
|
||||
// given
|
||||
given(settings.getProperty(LimboSettings.LIMBO_PERSISTENCE_TYPE))
|
||||
.willReturn(LimboPersistenceType.INDIVIDUAL_FILES);
|
||||
|
@ -102,7 +101,7 @@ public class LimboPersistenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionWhenGettingLimbo() {
|
||||
void shouldHandleExceptionWhenGettingLimbo() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
Logger logger = TestHelper.setupLogger();
|
||||
|
@ -118,7 +117,7 @@ public class LimboPersistenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionWhenSavingLimbo() {
|
||||
void shouldHandleExceptionWhenSavingLimbo() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
LimboPlayer limbo = mock(LimboPlayer.class);
|
||||
|
@ -134,7 +133,7 @@ public class LimboPersistenceTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHandleExceptionWhenRemovingLimbo() {
|
||||
void shouldHandleExceptionWhenRemovingLimbo() {
|
||||
// given
|
||||
Player player = mock(Player.class);
|
||||
Logger logger = TestHelper.setupLogger();
|
||||
|
|
|
@ -1,23 +1,23 @@
|
|||
package fr.xephi.authme.data.limbo.persistence;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
import static org.mockito.BDDMockito.given;
|
||||
import static org.mockito.Mockito.mock;
|
||||
|
||||
/**
|
||||
* Test for {@link LimboPersistenceType}.
|
||||
*/
|
||||
public class LimboPersistenceTypeTest {
|
||||
class LimboPersistenceTypeTest {
|
||||
|
||||
@Test
|
||||
public void shouldHaveUniqueImplementationClasses() {
|
||||
void shouldHaveUniqueImplementationClasses() {
|
||||
// given
|
||||
Set<Class<?>> classes = new HashSet<>();
|
||||
|
||||
|
@ -31,7 +31,7 @@ public class LimboPersistenceTypeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveTypeReturnedFromImplementationClass() {
|
||||
void shouldHaveTypeReturnedFromImplementationClass() {
|
||||
for (LimboPersistenceType persistenceType : LimboPersistenceType.values()) {
|
||||
// given
|
||||
LimboPersistenceHandler implementationMock = mock(persistenceType.getImplementationClass());
|
||||
|
|
|
@ -1,6 +1,6 @@
|
|||
package fr.xephi.authme.data.limbo.persistence;
|
||||
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -12,21 +12,21 @@ import static fr.xephi.authme.data.limbo.persistence.SegmentSize.SIXTEEN;
|
|||
import static fr.xephi.authme.data.limbo.persistence.SegmentSize.SIXTY_FOUR;
|
||||
import static fr.xephi.authme.data.limbo.persistence.SegmentSize.THIRTY_TWO;
|
||||
import static fr.xephi.authme.data.limbo.persistence.SegmentSize.TWO_FIFTY;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.junit.Assert.assertThat;
|
||||
|
||||
/**
|
||||
* Test for {@link SegmentNameBuilder}.
|
||||
*/
|
||||
public class SegmentNameBuilderTest {
|
||||
class SegmentNameBuilderTest {
|
||||
|
||||
/**
|
||||
* Checks that using a given segment size really produces as many segments as defined.
|
||||
* E.g. if we partition with {@link SegmentSize#EIGHT} we expect eight different buckets.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCreatePromisedSizeOfSegments() {
|
||||
void shouldCreatePromisedSizeOfSegments() {
|
||||
for (SegmentSize part : SegmentSize.values()) {
|
||||
// Perform this check only for `length` <= 5 because the test creates all hex numbers with `length` digits.
|
||||
if (part.getLength() <= 5) {
|
||||
|
@ -62,7 +62,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateOneSegment() {
|
||||
void shouldCreateOneSegment() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(ONE);
|
||||
|
||||
|
@ -73,7 +73,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateFourSegments() {
|
||||
void shouldCreateFourSegments() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(FOUR);
|
||||
|
||||
|
@ -84,7 +84,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateEightSegments() {
|
||||
void shouldCreateEightSegments() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(EIGHT);
|
||||
|
||||
|
@ -96,7 +96,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateSixteenSegments() {
|
||||
void shouldCreateSixteenSegments() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(SIXTEEN);
|
||||
|
||||
|
@ -107,7 +107,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateThirtyTwoSegments() {
|
||||
void shouldCreateThirtyTwoSegments() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(THIRTY_TWO);
|
||||
|
||||
|
@ -118,7 +118,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreateSixtyFourSegments() {
|
||||
void shouldCreateSixtyFourSegments() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(SIXTY_FOUR);
|
||||
|
||||
|
@ -129,7 +129,7 @@ public class SegmentNameBuilderTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCreate256Segments() {
|
||||
void shouldCreate256Segments() {
|
||||
// given
|
||||
SegmentNameBuilder nameBuilder = new SegmentNameBuilder(TWO_FIFTY);
|
||||
|
||||
|
|
|
@ -1,7 +1,7 @@
|
|||
package fr.xephi.authme.data.limbo.persistence;
|
||||
|
||||
import com.google.common.collect.ImmutableSet;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.HashSet;
|
||||
import java.util.Set;
|
||||
|
@ -9,15 +9,15 @@ import java.util.Set;
|
|||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.equalTo;
|
||||
import static org.hamcrest.Matchers.greaterThan;
|
||||
import static org.junit.Assert.fail;
|
||||
import static org.junit.jupiter.api.Assertions.fail;
|
||||
|
||||
/**
|
||||
* Test for {@link SegmentSize}.
|
||||
*/
|
||||
public class SegmentSizeTest {
|
||||
class SegmentSizeTest {
|
||||
|
||||
@Test
|
||||
public void shouldHaveDistributionThatIsPowerOf2() {
|
||||
void shouldHaveDistributionThatIsPowerOf2() {
|
||||
// given
|
||||
Set<Integer> allowedDistributions = ImmutableSet.of(1, 2, 4, 8, 16);
|
||||
|
||||
|
@ -30,7 +30,7 @@ public class SegmentSizeTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldHaveDifferentSegmentSizes() {
|
||||
void shouldHaveDifferentSegmentSizes() {
|
||||
// given
|
||||
Set<Integer> segmentTotals = new HashSet<>();
|
||||
|
||||
|
|
|
@ -5,7 +5,7 @@ import ch.jalu.datasourcecolumns.data.DataSourceValueImpl;
|
|||
import com.google.common.collect.Lists;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import org.junit.Test;
|
||||
import org.junit.jupiter.api.Test;
|
||||
|
||||
import java.util.Arrays;
|
||||
import java.util.HashSet;
|
||||
|
@ -17,6 +17,7 @@ import static fr.xephi.authme.AuthMeMatchers.equalToHash;
|
|||
import static fr.xephi.authme.AuthMeMatchers.hasAuthBasicData;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasAuthLocation;
|
||||
import static fr.xephi.authme.AuthMeMatchers.hasRegistrationInfo;
|
||||
import static org.hamcrest.MatcherAssert.assertThat;
|
||||
import static org.hamcrest.Matchers.contains;
|
||||
import static org.hamcrest.Matchers.containsInAnyOrder;
|
||||
import static org.hamcrest.Matchers.empty;
|
||||
|
@ -25,22 +26,20 @@ import static org.hamcrest.Matchers.hasItem;
|
|||
import static org.hamcrest.Matchers.hasSize;
|
||||
import static org.hamcrest.Matchers.is;
|
||||
import static org.hamcrest.Matchers.nullValue;
|
||||
import static org.junit.Assert.assertThat;
|
||||
import static org.junit.Assume.assumeThat;
|
||||
|
||||
/**
|
||||
* Abstract class for data source integration tests.
|
||||
*/
|
||||
public abstract class AbstractDataSourceIntegrationTest {
|
||||
|
||||
protected DataSource getDataSource() {
|
||||
private DataSource getDataSource() {
|
||||
return getDataSource("salt");
|
||||
}
|
||||
|
||||
protected abstract DataSource getDataSource(String saltColumn);
|
||||
|
||||
@Test
|
||||
public void shouldReturnIfAuthIsAvailableOrNot() {
|
||||
void shouldReturnIfAuthIsAvailableOrNot() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -56,7 +55,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnPassword() {
|
||||
void shouldReturnPassword() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -72,7 +71,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnPasswordWithEmptySaltColumn() {
|
||||
void shouldReturnPasswordWithEmptySaltColumn() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource("");
|
||||
|
||||
|
@ -88,7 +87,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetAuth() {
|
||||
void shouldGetAuth() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -116,7 +115,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCountAuthsByEmail() {
|
||||
void shouldCountAuthsByEmail() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -135,7 +134,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldReturnAllAuths() {
|
||||
void shouldReturnAllAuths() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -154,7 +153,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdatePassword() {
|
||||
void shouldUpdatePassword() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
HashedPassword newHash = new HashedPassword("new_hash");
|
||||
|
@ -170,7 +169,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdatePasswordWithNoSalt() {
|
||||
void shouldUpdatePasswordWithNoSalt() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource("");
|
||||
HashedPassword newHash = new HashedPassword("new_hash", "1241");
|
||||
|
@ -186,7 +185,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdatePasswordWithPlayerAuth() {
|
||||
void shouldUpdatePasswordWithPlayerAuth() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource("salt");
|
||||
PlayerAuth bobbyAuth = PlayerAuth.builder().name("bobby").password(new HashedPassword("tt", "cc")).build();
|
||||
|
@ -203,7 +202,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemovePlayerAuth() {
|
||||
void shouldRemovePlayerAuth() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -218,7 +217,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateSession() {
|
||||
void shouldUpdateSession() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
PlayerAuth bobby = PlayerAuth.builder()
|
||||
|
@ -236,7 +235,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateLastLoc() {
|
||||
void shouldUpdateLastLoc() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
PlayerAuth user = PlayerAuth.builder()
|
||||
|
@ -252,11 +251,11 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldDeletePlayers() {
|
||||
void shouldDeletePlayers() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
Set<String> playersToDelete = new HashSet<>(Arrays.asList("bobby", "doesNotExist"));
|
||||
assumeThat(dataSource.getAccountsRegistered(), equalTo(2));
|
||||
assertThat(dataSource.getAccountsRegistered(), equalTo(2)); // Make sure we start as expected
|
||||
|
||||
// when
|
||||
dataSource.purgeRecords(playersToDelete);
|
||||
|
@ -268,7 +267,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateEmail() {
|
||||
void shouldUpdateEmail() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
String email = "new-user@mail.tld";
|
||||
|
@ -286,7 +285,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldCountAuths() {
|
||||
void shouldCountAuths() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -303,7 +302,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetAllUsersByIp() {
|
||||
void shouldGetAllUsersByIp() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -327,7 +326,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldUpdateRealName() {
|
||||
void shouldUpdateRealName() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -342,7 +341,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetRecordsToPurge() {
|
||||
void shouldGetRecordsToPurge() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
// 1453242857 -> user, 1449136800 -> bobby
|
||||
|
@ -374,7 +373,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformOperationsOnIsLoggedColumnSuccessfully() {
|
||||
void shouldPerformOperationsOnIsLoggedColumnSuccessfully() {
|
||||
DataSource dataSource = getDataSource();
|
||||
// on startup no one should be marked as logged
|
||||
assertThat(dataSource.isLogged("user"), equalTo(false));
|
||||
|
@ -404,7 +403,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldPerformPurgeOperation() {
|
||||
void shouldPerformPurgeOperation() {
|
||||
// given
|
||||
List<String> names = Arrays.asList("Bobby", "USER", "DoesnotExist");
|
||||
DataSource dataSource = getDataSource();
|
||||
|
@ -417,7 +416,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldFetchEmail() {
|
||||
void shouldFetchEmail() {
|
||||
// given
|
||||
String user1 = "user";
|
||||
String user2 = "Bogus";
|
||||
|
@ -433,7 +432,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetLoggedPlayersWithoutEmail() {
|
||||
void shouldGetLoggedPlayersWithoutEmail() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
dataSource.setLogged("bobby");
|
||||
|
@ -447,7 +446,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGrantAndRetrieveSessionFlag() {
|
||||
void shouldGrantAndRetrieveSessionFlag() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
@ -462,7 +461,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRevokeSession() {
|
||||
void shouldRevokeSession() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
dataSource.grantSession("bobby");
|
||||
|
@ -479,7 +478,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldGetRecentlyLoggedInPlayers() {
|
||||
void shouldGetRecentlyLoggedInPlayers() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
String[] names = {"user3", "user8", "user2", "user4", "user7",
|
||||
|
@ -505,7 +504,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldSetTotpKey() {
|
||||
void shouldSetTotpKey() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
String newTotpKey = "My new TOTP key";
|
||||
|
@ -519,7 +518,7 @@ public abstract class AbstractDataSourceIntegrationTest {
|
|||
}
|
||||
|
||||
@Test
|
||||
public void shouldRemoveTotpKey() {
|
||||
void shouldRemoveTotpKey() {
|
||||
// given
|
||||
DataSource dataSource = getDataSource();
|
||||
|
||||
|
|
|
@ -5,10 +5,9 @@ import com.google.common.collect.ImmutableMap;
|
|||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.data.auth.PlayerAuth;
|
||||
import fr.xephi.authme.security.crypts.HashedPassword;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.Test;
|
||||
import org.junit.runner.RunWith;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.mockito.invocation.InvocationOnMock;
|
||||
import org.mockito.stubbing.Answer;
|
||||
|
||||
|
@ -44,36 +43,21 @@ import static org.mockito.Mockito.verify;
|
|||
* which is set to create additional mocks on demand for Statement and ResultSet objects.
|
||||
* This test ensures that all such objects that are created will be closed again by
|
||||
* keeping a list of mocks ({@link #closeables}) and then verifying that all have been
|
||||
* closed ({@link #verifyHaveMocksBeenClosed()}).
|
||||
* closed ({@link #verifyHaveMocksBeenClosed(Method)}).
|
||||
*/
|
||||
@RunWith(Parameterized.class)
|
||||
public abstract class AbstractResourceClosingTest {
|
||||
|
||||
/** Collection of values to use to call methods with the parameters they expect. */
|
||||
private static final Map<Class<?>, Object> PARAM_VALUES = getDefaultParameters();
|
||||
|
||||
/** The DataSource method to test. */
|
||||
private Method method;
|
||||
|
||||
/** Keeps track of the closeables which are created during the tested call. */
|
||||
private List<AutoCloseable> closeables = new ArrayList<>();
|
||||
|
||||
private boolean hasCreatedConnection = false;
|
||||
|
||||
/**
|
||||
* Constructor for the test instance verifying the given method.
|
||||
*
|
||||
* @param method The DataSource method to test
|
||||
* @param name The name of the method
|
||||
*/
|
||||
public AbstractResourceClosingTest(Method method, String name) {
|
||||
// Note ljacqu 20160227: The name parameter is necessary as we pass it from the @Parameters method;
|
||||
// we use the method name in the annotation to name the test sensibly
|
||||
this.method = method;
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeLogger() {
|
||||
@BeforeAll
|
||||
static void initializeLogger() {
|
||||
TestHelper.setupLogger();
|
||||
}
|
||||
|
||||
|
@ -81,10 +65,13 @@ public abstract class AbstractResourceClosingTest {
|
|||
* The actual test -- executes the method given through the constructor and then verifies that all
|
||||
* AutoCloseable mocks it constructed have been closed.
|
||||
*/
|
||||
@Test
|
||||
public void shouldCloseResources() throws IllegalAccessException, InvocationTargetException {
|
||||
@ParameterizedTest(name = "{1}")
|
||||
@MethodSource("createParameters")
|
||||
// Note ljacqu 20160227: The name parameter is necessary as we pass it from the arguments source method;
|
||||
// we use the method name in the annotation to name the test sensibly
|
||||
void shouldCloseResources(Method method, String name) throws IllegalAccessException, InvocationTargetException {
|
||||
method.invoke(getObjectUnderTest(), buildParamListForMethod(method));
|
||||
verifyHaveMocksBeenClosed();
|
||||
verifyHaveMocksBeenClosed(method);
|
||||
}
|
||||
|
||||
protected abstract Object getObjectUnderTest();
|
||||
|
@ -92,7 +79,7 @@ public abstract class AbstractResourceClosingTest {
|
|||
/**
|
||||
* Verify that all AutoCloseables that have been created during the method execution have been closed.
|
||||
*/
|
||||
private void verifyHaveMocksBeenClosed() {
|
||||
private void verifyHaveMocksBeenClosed(Method method) {
|
||||
if (closeables.isEmpty()) {
|
||||
System.out.println("Note: detected no AutoCloseables for method '" + method.getName() + "'");
|
||||
}
|
||||
|
@ -202,27 +189,21 @@ public abstract class AbstractResourceClosingTest {
|
|||
|
||||
/* Create Answer that returns a PreparedStatement mock. */
|
||||
private Answer<PreparedStatement> preparedStatementAnswer() {
|
||||
return new Answer<PreparedStatement>() {
|
||||
@Override
|
||||
public PreparedStatement answer(InvocationOnMock invocation) throws SQLException {
|
||||
PreparedStatement pst = mock(PreparedStatement.class);
|
||||
closeables.add(pst);
|
||||
given(pst.executeQuery()).willAnswer(resultSetAnswer());
|
||||
given(pst.executeQuery(anyString())).willAnswer(resultSetAnswer());
|
||||
return pst;
|
||||
}
|
||||
return invocation -> {
|
||||
PreparedStatement pst = mock(PreparedStatement.class);
|
||||
closeables.add(pst);
|
||||
given(pst.executeQuery()).willAnswer(resultSetAnswer());
|
||||
given(pst.executeQuery(anyString())).willAnswer(resultSetAnswer());
|
||||
return pst;
|
||||
};
|
||||
}
|
||||
|
||||
/* Create Answer that returns a ResultSet mock. */
|
||||
private Answer<ResultSet> resultSetAnswer() throws SQLException {
|
||||
return new Answer<ResultSet>() {
|
||||
@Override
|
||||
public ResultSet answer(InvocationOnMock invocation) throws Throwable {
|
||||
ResultSet rs = initResultSet();
|
||||
closeables.add(rs);
|
||||
return rs;
|
||||
}
|
||||
private Answer<ResultSet> resultSetAnswer() {
|
||||
return invocation -> {
|
||||
ResultSet rs = initResultSet();
|
||||
closeables.add(rs);
|
||||
return rs;
|
||||
};
|
||||
}
|
||||
|
||||
|
|
|
@ -3,8 +3,7 @@ package fr.xephi.authme.datasource;
|
|||
import com.google.common.collect.ImmutableSet;
|
||||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.runners.Parameterized;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
|
@ -27,12 +26,8 @@ public abstract class AbstractSqlDataSourceResourceClosingTest extends AbstractR
|
|||
|
||||
private static Settings settings;
|
||||
|
||||
AbstractSqlDataSourceResourceClosingTest(Method method, String name) {
|
||||
super(method, name);
|
||||
}
|
||||
|
||||
@BeforeClass
|
||||
public static void initializeSettings() {
|
||||
@BeforeAll
|
||||
static void initializeSettings() {
|
||||
settings = mock(Settings.class);
|
||||
TestHelper.returnDefaultsForAllProperties(settings);
|
||||
TestHelper.setupLogger();
|
||||
|
@ -54,8 +49,7 @@ public abstract class AbstractSqlDataSourceResourceClosingTest extends AbstractR
|
|||
*
|
||||
* @return Test parameters
|
||||
*/
|
||||
@Parameterized.Parameters(name = "{1}")
|
||||
public static Collection<Object[]> data() {
|
||||
public static Collection<Object[]> createParameters() {
|
||||
List<Method> methods = getDataSourceMethods();
|
||||
List<Object[]> data = new ArrayList<>();
|
||||
for (Method method : methods) {
|
||||
|
|
|
@ -6,9 +6,9 @@ import com.zaxxer.hikari.HikariDataSource;
|
|||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -23,7 +23,7 @@ import static org.mockito.Mockito.when;
|
|||
/**
|
||||
* Integration test for {@link MySQL}.
|
||||
*/
|
||||
public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
||||
class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
||||
|
||||
/** Mock of a settings instance. */
|
||||
private static Settings settings;
|
||||
|
@ -35,8 +35,8 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||
/**
|
||||
* Set up the settings mock to return specific values for database settings and load {@link #sqlInitialize}.
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void initializeSettings() throws IOException, ClassNotFoundException {
|
||||
@BeforeAll
|
||||
static void initializeSettings() throws IOException, ClassNotFoundException {
|
||||
// Check that we have an H2 driver
|
||||
Class.forName("org.h2.jdbcx.JdbcDataSource");
|
||||
|
||||
|
@ -50,8 +50,8 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||
sqlInitialize = new String(Files.readAllBytes(sqlInitFile));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void initializeConnectionAndTable() throws SQLException {
|
||||
@BeforeEach
|
||||
void initializeConnectionAndTable() throws SQLException {
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
|
||||
config.setConnectionTestQuery("VALUES 1");
|
||||
|
@ -70,8 +70,8 @@ public class MySqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
|||
hikariSource = ds;
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeConnection() {
|
||||
@AfterEach
|
||||
void closeConnection() {
|
||||
silentClose(hikariSource);
|
||||
}
|
||||
|
||||
|
|
|
@ -5,7 +5,6 @@ import fr.xephi.authme.datasource.mysqlextensions.MySqlExtension;
|
|||
import fr.xephi.authme.datasource.mysqlextensions.MySqlExtensionsFactory;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
|
||||
import java.lang.reflect.Method;
|
||||
import java.sql.Connection;
|
||||
|
||||
import static org.mockito.ArgumentMatchers.any;
|
||||
|
@ -15,11 +14,7 @@ import static org.mockito.Mockito.mock;
|
|||
/**
|
||||
* Resource closing test for {@link MySQL}.
|
||||
*/
|
||||
public class MySqlResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
|
||||
|
||||
public MySqlResourceClosingTest(Method method, String name) {
|
||||
super(method, name);
|
||||
}
|
||||
class MySqlResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
|
||||
|
||||
@Override
|
||||
protected DataSource createDataSource(Settings settings, Connection connection) throws Exception {
|
||||
|
|
|
@ -6,9 +6,9 @@ import com.zaxxer.hikari.HikariDataSource;
|
|||
import fr.xephi.authme.TestHelper;
|
||||
import fr.xephi.authme.settings.Settings;
|
||||
import fr.xephi.authme.settings.properties.DatabaseSettings;
|
||||
import org.junit.After;
|
||||
import org.junit.Before;
|
||||
import org.junit.BeforeClass;
|
||||
import org.junit.jupiter.api.AfterEach;
|
||||
import org.junit.jupiter.api.BeforeAll;
|
||||
import org.junit.jupiter.api.BeforeEach;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.nio.file.Files;
|
||||
|
@ -23,7 +23,7 @@ import static org.mockito.Mockito.when;
|
|||
/**
|
||||
* Integration test for {@link PostgreSqlDataSource}.
|
||||
*/
|
||||
public class PostgreSqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
||||
class PostgreSqlIntegrationTest extends AbstractDataSourceIntegrationTest {
|
||||
|
||||
/** Mock of a settings instance. */
|
||||
private static Settings settings;
|
||||
|
@ -35,8 +35,8 @@ public class PostgreSqlIntegrationTest extends AbstractDataSourceIntegrationTest
|
|||
/**
|
||||
* Set up the settings mock to return specific values for database settings and load {@link #sqlInitialize}.
|
||||
*/
|
||||
@BeforeClass
|
||||
public static void initializeSettings() throws IOException, ClassNotFoundException {
|
||||
@BeforeAll
|
||||
static void initializeSettings() throws IOException, ClassNotFoundException {
|
||||
// Check that we have an H2 driver
|
||||
Class.forName("org.h2.jdbcx.JdbcDataSource");
|
||||
|
||||
|
@ -50,8 +50,8 @@ public class PostgreSqlIntegrationTest extends AbstractDataSourceIntegrationTest
|
|||
sqlInitialize = new String(Files.readAllBytes(sqlInitFile));
|
||||
}
|
||||
|
||||
@Before
|
||||
public void initializeConnectionAndTable() throws SQLException {
|
||||
@BeforeEach
|
||||
void initializeConnectionAndTable() throws SQLException {
|
||||
HikariConfig config = new HikariConfig();
|
||||
config.setDataSourceClassName("org.h2.jdbcx.JdbcDataSource");
|
||||
config.setConnectionTestQuery("VALUES 1");
|
||||
|
@ -68,8 +68,8 @@ public class PostgreSqlIntegrationTest extends AbstractDataSourceIntegrationTest
|
|||
hikariSource = ds;
|
||||
}
|
||||
|
||||
@After
|
||||
public void closeConnection() {
|
||||
@AfterEach
|
||||
void closeConnection() {
|
||||
silentClose(hikariSource);
|
||||
}
|
||||
|
||||
|
|
Some files were not shown because too many files have changed in this diff Show More
Loading…
Reference in New Issue