Replace assumption/assertTrue imports from Junit4 and remove JUnit vintage!

- This commit ends the migration to JUnit 5 and removes the junit-vintage dependency
- Make some remaining tests & classes package-private
This commit is contained in:
ljacqu 2021-04-19 21:05:39 +02:00
parent cbfd884af7
commit 17d5691aef
44 changed files with 60 additions and 70 deletions

View File

@ -922,12 +922,6 @@
<scope>test</scope>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>org.junit.vintage</groupId>
<artifactId>junit-vintage-engine</artifactId>
<scope>test</scope>
<version>5.7.1</version>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-params</artifactId>

View File

@ -34,7 +34,7 @@ import java.util.stream.Collectors;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Contains consistency tests across all AuthMe classes.

View File

@ -11,7 +11,7 @@ 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.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Consistency test for the CodeClimate configuration file.

View File

@ -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.

View File

@ -514,7 +514,7 @@ class AuthMeApiTest {
}
@Test
public void shouldReturnAuthMePlayerInfo() {
void shouldReturnAuthMePlayerInfo() {
// given
PlayerAuth auth = PlayerAuth.builder()
.name("bobb")
@ -533,7 +533,7 @@ class AuthMeApiTest {
}
@Test
public void shouldReturnNullForNonExistentAuth() {
void shouldReturnNullForNonExistentAuth() {
// given / when
Optional<AuthMePlayer> result = api.getPlayerInfo("doesNotExist");

View File

@ -17,7 +17,7 @@ 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.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link CommandInitializer} to guarantee the integrity of the defined commands.

View File

@ -14,7 +14,7 @@ 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.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Consistency tests for {@link DebugSection} implementors.
@ -45,7 +45,7 @@ class DebugSectionConsistencyTest {
}
@Test
void shouldHaveDifferentSubcommandName() throws IllegalAccessException, InstantiationException {
void shouldHaveDifferentSubcommandName() {
Set<String> names = new HashSet<>();
for (DebugSection debugSection : debugSections) {
if (!names.add(debugSection.getName())) {

View File

@ -7,7 +7,7 @@ import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Consistency test for {@link MySqlDefaultChanger.Columns} enum.

View File

@ -8,7 +8,7 @@ import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for enums {@link HelpMessage} and {@link HelpSection}.

View File

@ -5,7 +5,7 @@ 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.

View File

@ -7,7 +7,7 @@ import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
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;

View File

@ -9,7 +9,7 @@ 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}.

View File

@ -26,7 +26,6 @@ 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.Assume.assumeThat;
/**
* Abstract class for data source integration tests.
@ -256,7 +255,7 @@ public abstract class AbstractDataSourceIntegrationTest {
// 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);

View File

@ -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;

View File

@ -14,7 +14,7 @@ import static org.mockito.Mockito.mock;
/**
* Resource closing test for {@link MySQL}.
*/
public class MySqlResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
class MySqlResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
@Override
protected DataSource createDataSource(Settings settings, Connection connection) throws Exception {

View File

@ -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;

View File

@ -14,7 +14,7 @@ import static org.mockito.Mockito.mock;
/**
* Resource closing test for {@link PostgreSqlDataSource}.
*/
public class PostgreSqlResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
class PostgreSqlResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
@Override
protected DataSource createDataSource(Settings settings, Connection connection) throws Exception {

View File

@ -7,7 +7,7 @@ import java.sql.Connection;
/**
* Resource closing test for {@link SQLite}.
*/
public class SQLiteResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
class SQLiteResourceClosingTest extends AbstractSqlDataSourceResourceClosingTest {
@Override
protected DataSource createDataSource(Settings settings, Connection connection) {

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.settings.Settings;
/**
* Resource closing test for {@link Ipb4Extension}.
*/
public class Ipb4ExtensionResourceClosingTest extends AbstractMySqlExtensionResourceClosingTest {
class Ipb4ExtensionResourceClosingTest extends AbstractMySqlExtensionResourceClosingTest {
@Override
protected MySqlExtension createExtension(Settings settings, Columns columns) {

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.settings.Settings;
/**
* Resource closing test for {@link PhpBbExtension}.
*/
public class PhpBbExtensionResourceClosingTest extends AbstractMySqlExtensionResourceClosingTest {
class PhpBbExtensionResourceClosingTest extends AbstractMySqlExtensionResourceClosingTest {
@Override
protected MySqlExtension createExtension(Settings settings, Columns columns) {

View File

@ -6,7 +6,7 @@ import fr.xephi.authme.settings.Settings;
/**
* Resource closing test for {@link WordpressExtension}.
*/
public class WordpressExtensionResourceClosingTest extends AbstractMySqlExtensionResourceClosingTest {
class WordpressExtensionResourceClosingTest extends AbstractMySqlExtensionResourceClosingTest {
@Override
protected MySqlExtension createExtension(Settings settings, Columns columns) {

View File

@ -18,7 +18,7 @@ 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.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for verifying that AuthMe listener methods are well-formed.

View File

@ -34,8 +34,8 @@ import java.util.List;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.fail;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;

View File

@ -16,7 +16,7 @@ import java.util.List;
import java.util.stream.Collectors;
import static fr.xephi.authme.message.MessagePathHelper.MESSAGES_FOLDER;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
import static tools.utils.FileIoUtils.listFilesOrThrow;
/**

View File

@ -9,7 +9,7 @@ import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.matchesPattern;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link MessageKey}.

View File

@ -10,7 +10,7 @@ import java.io.File;
import java.util.ArrayList;
import java.util.List;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests that the project's default language file contains a text for all message keys.

View File

@ -15,7 +15,7 @@ import java.util.List;
import java.util.function.Predicate;
import static fr.xephi.authme.message.MessagePathHelper.MESSAGES_FOLDER;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
import static tools.utils.FileIoUtils.listFilesOrThrow;
/**

View File

@ -9,7 +9,7 @@ import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link OldMessageKeysMigrater}.

View File

@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test;
import java.util.HashSet;
import java.util.Set;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Has common tests for enums implementing {@link PermissionNode}.

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission;
/**
* Test for {@link AdminPermission}.
*/
public class AdminPermissionTest extends AbstractPermissionsEnumTest {
class AdminPermissionTest extends AbstractPermissionsEnumTest {
@Override
protected PermissionNode[] getPermissionNodes() {

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission;
/**
* Test for {@link DebugSectionPermissions}.
*/
public class DebugSectionPermissionsTest extends AbstractPermissionsEnumTest {
class DebugSectionPermissionsTest extends AbstractPermissionsEnumTest {
@Override
protected PermissionNode[] getPermissionNodes() {

View File

@ -22,7 +22,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import static fr.xephi.authme.TestHelper.getJarFile;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests that the permissions listed in plugin.yml correspond to the ones in the code.

View File

@ -19,7 +19,6 @@ import org.bukkit.plugin.Plugin;
import org.bukkit.plugin.PluginManager;
import org.bukkit.plugin.RegisteredServiceProvider;
import org.bukkit.plugin.ServicesManager;
import org.junit.AssumptionViolatedException;
import org.junit.jupiter.api.BeforeAll;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.params.ParameterizedTest;
@ -41,6 +40,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
import static org.mockito.BDDMockito.given;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.only;
@ -159,7 +159,7 @@ class PermissionsManagerInitializationTest {
LuckPerms api = mock(LuckPerms.class);
ReflectionTestUtils.setField(LuckPermsProvider.class, null, "instance", api);
} else if (permissionsSystemType == PERMISSIONS_EX) {
throw new AssumptionViolatedException(
assumeTrue(false,
"PermissionsEx instance cannot be mocked because of missing dependencies -- skipping");
} else if (permissionsSystemType == Z_PERMISSIONS) {
ZPermissionsService zPermissionsService = mock(ZPermissionsService.class);

View File

@ -3,7 +3,7 @@ package fr.xephi.authme.permission;
/**
* Test for {@link PlayerPermission}.
*/
public class PlayerPermissionTest extends AbstractPermissionsEnumTest {
class PlayerPermissionTest extends AbstractPermissionsEnumTest {
@Override
protected PermissionNode[] getPermissionNodes() {

View File

@ -6,7 +6,7 @@ import java.util.Collection;
import java.util.Set;
import static com.google.common.collect.Sets.newHashSet;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link PlayerStatePermission}.

View File

@ -22,7 +22,7 @@ import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
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;

View File

@ -10,11 +10,9 @@ import org.junit.jupiter.api.Test;
import java.util.List;
import java.util.Map;
import static junit.framework.TestCase.assertFalse;
import static junit.framework.TestCase.assertTrue;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assume.assumeThat;
import static org.junit.jupiter.api.Assumptions.assumeFalse;
/**
* Test for implementations of {@link EncryptionMethod}.
@ -118,8 +116,8 @@ public abstract class AbstractEncryptionMethodTest {
// Test entries in GIVEN_PASSWORDS except the last one
for (int i = start; i < GIVEN_PASSWORDS.length - 1; ++i) {
String password = GIVEN_PASSWORDS[i];
assertTrue("Hash for password '" + password + "' should match",
doesGivenHashMatch(password, method));
assertThat("Hash for password '" + password + "' should match",
doesGivenHashMatch(password, method), equalTo(true));
}
// Note #375: Windows console seems to use its own character encoding (Windows-1252?) and it seems impossible to
@ -150,17 +148,17 @@ public abstract class AbstractEncryptionMethodTest {
hash, equalTo(method.computeHash(password, salt, USERNAME)));
}
assertTrue("Generated hash for '" + password + "' should match password (hash = '" + hash + "')",
method.comparePassword(password, hashedPassword, USERNAME));
assumeThat(SKIP_LONG_TESTS, equalTo(false));
assertThat("Generated hash for '" + password + "' should match password (hash = '" + hash + "')",
method.comparePassword(password, hashedPassword, USERNAME), equalTo(true));
assumeFalse(SKIP_LONG_TESTS);
if (!password.equals(password.toLowerCase())) {
assertFalse("Lower-case of '" + password + "' should not match generated hash '" + hash + "'",
method.comparePassword(password.toLowerCase(), hashedPassword, USERNAME));
assertThat("Lower-case of '" + password + "' should not match generated hash '" + hash + "'",
method.comparePassword(password.toLowerCase(), hashedPassword, USERNAME), equalTo(false));
}
if (!password.equals(password.toUpperCase())) {
assertFalse("Upper-case of '" + password + "' should not match generated hash '" + hash + "'",
method.comparePassword(password.toUpperCase(), hashedPassword, USERNAME));
assertThat("Upper-case of '" + password + "' should not match generated hash '" + hash + "'",
method.comparePassword(password.toUpperCase(), hashedPassword, USERNAME), equalTo(false));
}
}
}
@ -168,12 +166,12 @@ public abstract class AbstractEncryptionMethodTest {
/** Tests various strings to ensure that encryption methods don't rely on the hash's format too much. */
@Test
void testMalformedHashes() {
assumeThat(SKIP_LONG_TESTS, equalTo(false));
assumeFalse(SKIP_LONG_TESTS);
String salt = method.hasSeparateSalt() ? "testSalt" : null;
for (String bogusHash : BOGUS_HASHES) {
HashedPassword hashedPwd = new HashedPassword(bogusHash, salt);
assertFalse("Passing bogus hash '" + bogusHash + "' does not result in an error",
method.comparePassword("Password", hashedPwd, "player"));
assertThat("Passing bogus hash '" + bogusHash + "' does not result in an error",
method.comparePassword("Password", hashedPwd, "player"), equalTo(false));
}
}

View File

@ -1,7 +1,6 @@
package fr.xephi.authme.security.crypts;
import static org.hamcrest.Matchers.equalTo;
import static org.junit.Assume.assumeThat;
import static org.junit.jupiter.api.Assumptions.assumeTrue;
/**
* Test for {@link Argon2}.
@ -17,8 +16,7 @@ class Argon2Test extends AbstractEncryptionMethodTest {
"$argon2i$v=19$m=65536,t=2,p=1$58v7dWNn9/bpD00QLzSebw$7cMC7p0qceE3Mgf2yQp4X7c+UkO9oyJwQ7S6XTBubNs", // &^%te$t?Pw@_
"$argon2i$v=19$m=65536,t=2,p=1$93OSU71DgBOzpmhti7+6rQ$sSSI6QQQdoG9DlGwLjYz576kTek89nwr9CyNpy6bsL0"); // âË_3(íù*
assumeThat("Argon2 library is not loaded - skipping test",
IS_LIBRARY_LOADED, equalTo(true));
assumeTrue(IS_LIBRARY_LOADED, "Argon2 library is not loaded - skipping test");
}
@Override

View File

@ -6,7 +6,7 @@ import static fr.xephi.authme.AuthMeMatchers.stringWithLength;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.startsWith;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link Ipb4}.

View File

@ -5,7 +5,7 @@ import org.junit.jupiter.api.Test;
import java.util.Map;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link PhpBB}.

View File

@ -29,7 +29,7 @@ import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
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;
import static org.mockito.BDDMockito.given;
/**

View File

@ -10,7 +10,7 @@ import java.io.File;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.instanceOf;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link YamlFileResourceProvider}.

View File

@ -18,7 +18,7 @@ import java.util.Set;
import java.util.stream.Collectors;
import static fr.xephi.authme.ReflectionTestUtils.getFieldValue;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Tests the consistency of the settings configuration.

View File

@ -19,7 +19,7 @@ import java.util.Set;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.equalTo;
import static org.hamcrest.Matchers.hasSize;
import static org.junit.Assert.fail;
import static org.junit.jupiter.api.Assertions.fail;
/**
* Test for {@link SettingsHolder} implementations.