diff --git a/src/main/java/fr/xephi/authme/datasource/SQLite.java b/src/main/java/fr/xephi/authme/datasource/SQLite.java index ff72a8018..93b7f48a6 100644 --- a/src/main/java/fr/xephi/authme/datasource/SQLite.java +++ b/src/main/java/fr/xephi/authme/datasource/SQLite.java @@ -182,7 +182,11 @@ public class SQLite extends AbstractSqlDataSource { ConsoleLogger.info("SQLite Setup finished"); } - protected void migrateIfNeeded() throws SQLException { + /** + * Migrates the database if necessary. See {@link SqLiteMigrater} for details. + */ + @VisibleForTesting + void migrateIfNeeded() throws SQLException { DatabaseMetaData metaData = con.getMetaData(); if (SqLiteMigrater.isMigrationRequired(metaData, tableName, col)) { new SqLiteMigrater(settings, dataFolder).performMigration(this); diff --git a/src/main/java/fr/xephi/authme/datasource/mysqlextensions/XfBcryptExtension.java b/src/main/java/fr/xephi/authme/datasource/mysqlextensions/XfBcryptExtension.java index 84ab4c953..8d2a1ee94 100644 --- a/src/main/java/fr/xephi/authme/datasource/mysqlextensions/XfBcryptExtension.java +++ b/src/main/java/fr/xephi/authme/datasource/mysqlextensions/XfBcryptExtension.java @@ -35,7 +35,14 @@ class XfBcryptExtension extends MySqlExtension { updateXenforoTablesOnSave(auth, authId.getAsInt(), con); } } - + + /** + * Updates the xenforo tables after a player auth has been saved. + * + * @param auth the player auth which was saved + * @param id the account id + * @param con connection to the database + */ private void updateXenforoTablesOnSave(PlayerAuth auth, int id, Connection con) throws SQLException { // Insert player password, salt in xf_user_authenticate String sql = "INSERT INTO " + xfPrefix + "user_authenticate (user_id, scheme_class, data) VALUES (?,?,?)"; diff --git a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java index 43d6fed47..c6acd03ef 100644 --- a/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java +++ b/src/main/java/fr/xephi/authme/listener/protocollib/ProtocolLibService.java @@ -79,6 +79,9 @@ public class ProtocolLibService implements SettingsDependent { this.isEnabled = true; } + /** + * Stops all features based on ProtocolLib. + */ public void disable() { isEnabled = false; diff --git a/src/main/java/fr/xephi/authme/security/crypts/MyBB.java b/src/main/java/fr/xephi/authme/security/crypts/MyBB.java index 1abbe72ca..3ff0ee5e0 100644 --- a/src/main/java/fr/xephi/authme/security/crypts/MyBB.java +++ b/src/main/java/fr/xephi/authme/security/crypts/MyBB.java @@ -10,6 +10,7 @@ import static fr.xephi.authme.security.HashUtils.md5; @Recommendation(Usage.ACCEPTABLE) @HasSalt(value = SaltType.TEXT, length = 8) +@SuppressWarnings({"checkstyle:AbbreviationAsWordInName"}) public class MyBB extends SeparateSaltMethod { @Override diff --git a/src/main/java/fr/xephi/authme/service/BackupService.java b/src/main/java/fr/xephi/authme/service/BackupService.java index b85002eaa..6ae65a061 100644 --- a/src/main/java/fr/xephi/authme/service/BackupService.java +++ b/src/main/java/fr/xephi/authme/service/BackupService.java @@ -97,6 +97,11 @@ public class BackupService { return false; } + /** + * Performs a backup for the MySQL data source. + * + * @return true if successful, false otherwise + */ private boolean performMySqlBackup() { FileUtils.createDirectory(backupFolder); File sqlBackupFile = constructBackupFile("sql"); diff --git a/src/main/java/fr/xephi/authme/service/GeoIpService.java b/src/main/java/fr/xephi/authme/service/GeoIpService.java index 924e09351..804b82a15 100644 --- a/src/main/java/fr/xephi/authme/service/GeoIpService.java +++ b/src/main/java/fr/xephi/authme/service/GeoIpService.java @@ -226,8 +226,8 @@ public class GeoIpService { HashCode actualHash = function.hashBytes(Files.readAllBytes(file)); HashCode expectedHash = HashCode.fromString(expectedChecksum); if (!Objects.equals(actualHash, expectedHash)) { - throw new IOException("GEO IP Checksum verification failed. " + - "Expected: " + expectedChecksum + "Actual:" + actualHash); + throw new IOException("GEO IP Checksum verification failed. " + + "Expected: " + expectedChecksum + "Actual:" + actualHash); } } @@ -267,10 +267,10 @@ public class GeoIpService { * * @param ip textual IP address to lookup. * @return two-character ISO 3166-1 alpha code for the country, "LOCALHOST" for local addresses - * or "--" if it cannot be fetched. + * or "--" if it cannot be fetched. */ public String getCountryCode(String ip) { - if(InternetProtocolUtils.isLocalAddress(ip)) { + if (InternetProtocolUtils.isLocalAddress(ip)) { return "LOCALHOST"; } return getCountry(ip).map(Country::getIsoCode).orElse("--"); @@ -283,7 +283,7 @@ public class GeoIpService { * @return The name of the country, "LocalHost" for local addresses, or "N/A" if it cannot be fetched. */ public String getCountryName(String ip) { - if(InternetProtocolUtils.isLocalAddress(ip)) { + if (InternetProtocolUtils.isLocalAddress(ip)) { return "LocalHost"; } return getCountry(ip).map(Country::getName).orElse("N/A"); diff --git a/src/main/java/fr/xephi/authme/service/PluginHookService.java b/src/main/java/fr/xephi/authme/service/PluginHookService.java index 0a204aa0e..ab344fac3 100644 --- a/src/main/java/fr/xephi/authme/service/PluginHookService.java +++ b/src/main/java/fr/xephi/authme/service/PluginHookService.java @@ -69,7 +69,7 @@ public class PluginHookService { */ public File getCmiDataFolder() { Plugin plugin = pluginManager.getPlugin("CMI"); - if(plugin == null) { + if (plugin == null) { return null; } return plugin.getDataFolder(); diff --git a/src/test/java/fr/xephi/authme/IsEqualByReflectionMatcher.java b/src/test/java/fr/xephi/authme/IsEqualByReflectionMatcher.java index 55df85579..2acf5ee70 100644 --- a/src/test/java/fr/xephi/authme/IsEqualByReflectionMatcher.java +++ b/src/test/java/fr/xephi/authme/IsEqualByReflectionMatcher.java @@ -45,6 +45,13 @@ public final class IsEqualByReflectionMatcher extends TypeSafeMatcher { description.appendText("parameters " + expected); } + /** + * Checks that all fields of the given {@code item} are equal to the {@link #expected} object. Both objects must + * be exactly of the same type. + * + * @param item the object to check + * @return true if all fields are equal, false otherwise + */ private boolean assertAreFieldsEqual(T item) { if (expected.getClass() != item.getClass()) { fail("Classes don't match, got " + expected.getClass().getSimpleName() diff --git a/src/test/java/fr/xephi/authme/ReflectionTestUtils.java b/src/test/java/fr/xephi/authme/ReflectionTestUtils.java index 963fbf71d..69a1e1d99 100644 --- a/src/test/java/fr/xephi/authme/ReflectionTestUtils.java +++ b/src/test/java/fr/xephi/authme/ReflectionTestUtils.java @@ -25,13 +25,14 @@ public final class ReflectionTestUtils { * @param instance the instance to modify (pass null for static fields) * @param fieldName the field name * @param value the value to set the field to + * @param the instance type */ public static void setField(Class clazz, T instance, String fieldName, Object value) { try { Field field = getField(clazz, fieldName); field.set(instance, value); } catch (IllegalAccessException e) { - throw new UnsupportedOperationException( + throw new IllegalStateException( format("Could not set value to field '%s' for instance '%s' of class '%s'", fieldName, instance, clazz.getName()), e); } @@ -55,7 +56,7 @@ public final class ReflectionTestUtils { field.setAccessible(true); return field; } catch (NoSuchFieldException e) { - throw new UnsupportedOperationException(format("Could not get field '%s' from class '%s'", + throw new IllegalStateException(format("Could not get field '%s' from class '%s'", fieldName, clazz.getName()), e); } } @@ -66,13 +67,21 @@ public final class ReflectionTestUtils { return getFieldValue(field, instance); } + /** + * Returns the value of the field on the given instance. Wraps exceptions into a runtime exception. + * + * @param field the field to read + * @param instance the instance to get the value from, null if field is static + * @param type of the field + * @return value of the field + */ @SuppressWarnings("unchecked") public static V getFieldValue(Field field, Object instance) { field.setAccessible(true); try { return (V) field.get(instance); } catch (IllegalAccessException e) { - throw new UnsupportedOperationException("Could not get value of field '" + field.getName() + "'", e); + throw new IllegalStateException("Could not get value of field '" + field.getName() + "'", e); } } @@ -90,7 +99,7 @@ public final class ReflectionTestUtils { method.setAccessible(true); return method; } catch (NoSuchMethodException e) { - throw new UnsupportedOperationException("Could not retrieve method '" + methodName + "' from class '" + throw new IllegalStateException("Could not retrieve method '" + methodName + "' from class '" + clazz.getName() + "'"); } } @@ -110,7 +119,7 @@ public final class ReflectionTestUtils { try { return (V) method.invoke(instance, parameters); } catch (InvocationTargetException | IllegalAccessException e) { - throw new UnsupportedOperationException("Could not invoke method '" + method + "'", e); + throw new IllegalStateException("Could not invoke method '" + method + "'", e); } } @@ -138,7 +147,7 @@ public final class ReflectionTestUtils { constructor.setAccessible(true); return constructor.newInstance(); } catch (ReflectiveOperationException e) { - throw new UnsupportedOperationException("Could not invoke no-args constructor of class " + clazz, e); + throw new IllegalStateException("Could not invoke no-args constructor of class " + clazz, e); } } } diff --git a/src/test/java/fr/xephi/authme/command/TestCommandsUtil.java b/src/test/java/fr/xephi/authme/command/TestCommandsUtil.java index 111eb088d..c7a2d1d3f 100644 --- a/src/test/java/fr/xephi/authme/command/TestCommandsUtil.java +++ b/src/test/java/fr/xephi/authme/command/TestCommandsUtil.java @@ -84,7 +84,8 @@ public final class TestCommandsUtil { /* Shortcut command to initialize a new test command. */ private static CommandDescription createCommand(PermissionNode permission, CommandDescription parent, - List labels, Class commandClass, + List labels, + Class commandClass, CommandArgumentDescription... arguments) { CommandDescription.CommandBuilder command = CommandDescription.builder() .labels(labels) diff --git a/src/test/java/tools/docs/translations/TranslationPageGenerator.java b/src/test/java/tools/docs/translations/TranslationPageGenerator.java index dd87973d3..806819879 100644 --- a/src/test/java/tools/docs/translations/TranslationPageGenerator.java +++ b/src/test/java/tools/docs/translations/TranslationPageGenerator.java @@ -20,7 +20,8 @@ import static com.google.common.base.MoreObjects.firstNonNull; public class TranslationPageGenerator implements AutoToolTask { private static final String DOCS_PAGE = ToolsConstants.DOCS_FOLDER + "translations.md"; - private static final String TEMPLATE_FILE = ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md"; + private static final String TEMPLATE_FILE = + ToolsConstants.TOOLS_SOURCE_ROOT + "docs/translations/translations.tpl.md"; private static final Map LANGUAGE_NAMES = buildLanguageNames(); // Color configuration for the bars shown next to translation percentage diff --git a/src/test/java/tools/messages/MessageFileVerifier.java b/src/test/java/tools/messages/MessageFileVerifier.java index dd33e487a..650c9ff77 100644 --- a/src/test/java/tools/messages/MessageFileVerifier.java +++ b/src/test/java/tools/messages/MessageFileVerifier.java @@ -70,6 +70,10 @@ public class MessageFileVerifier { return !missingKeys.isEmpty() || !missingTags.isEmpty() || !unknownKeys.isEmpty(); } + /** + * Performs the actual verification for the given file and collects all found issues into this + * instance's fields. + */ private void verifyKeys() { FileConfiguration configuration = YamlConfiguration.loadConfiguration(messagesFile); diff --git a/src/test/java/tools/utils/TagReplacer.java b/src/test/java/tools/utils/TagReplacer.java index 32c744526..df3f5bdb5 100644 --- a/src/test/java/tools/utils/TagReplacer.java +++ b/src/test/java/tools/utils/TagReplacer.java @@ -18,7 +18,7 @@ import java.util.regex.Pattern; * version (in case the page is viewed on a fork) * */ -public class TagReplacer { +public final class TagReplacer { private TagReplacer() { } diff --git a/src/test/java/tools/utils/TagValueHolder.java b/src/test/java/tools/utils/TagValueHolder.java index 838628307..f6c9ec557 100644 --- a/src/test/java/tools/utils/TagValueHolder.java +++ b/src/test/java/tools/utils/TagValueHolder.java @@ -6,7 +6,7 @@ import java.util.HashMap; import java.util.Map; -public class TagValueHolder { +public final class TagValueHolder { private Map> values;