diff --git a/src/test/java/fr/xephi/authme/TestHelper.java b/src/test/java/fr/xephi/authme/TestHelper.java index 9e846d0f..baab8ca6 100644 --- a/src/test/java/fr/xephi/authme/TestHelper.java +++ b/src/test/java/fr/xephi/authme/TestHelper.java @@ -6,9 +6,6 @@ import org.bukkit.entity.Player; import org.mockito.Mockito; import java.io.File; -import java.lang.reflect.Constructor; -import java.lang.reflect.InvocationTargetException; -import java.lang.reflect.Modifier; import java.net.InetAddress; import java.net.InetSocketAddress; import java.net.URI; @@ -95,33 +92,6 @@ public final class TestHelper { return logger; } - /** - * Check that a class only has a hidden, zero-argument constructor, preventing the - * instantiation of such classes (utility classes). Invokes the hidden constructor - * as to register the code coverage. - * - * @param clazz The class to validate - */ - public static void validateHasOnlyPrivateEmptyConstructor(Class clazz) { - Constructor[] constructors = clazz.getDeclaredConstructors(); - if (constructors.length > 1) { - throw new IllegalStateException("Class " + clazz.getSimpleName() + " has more than one constructor"); - } else if (constructors[0].getParameterTypes().length != 0) { - throw new IllegalStateException("Constructor of " + clazz + " does not have empty parameter list"); - } else if (!Modifier.isPrivate(constructors[0].getModifiers())) { - throw new IllegalStateException("Constructor of " + clazz + " is not private"); - } - - // Ugly hack to get coverage on the private constructors - // http://stackoverflow.com/questions/14077842/how-to-test-a-private-constructor-in-java-application - try { - constructors[0].setAccessible(true); - constructors[0].newInstance(); - } catch (InvocationTargetException | InstantiationException | IllegalAccessException e) { - throw new UnsupportedOperationException(e); - } - } - /** * Configures the player mock to return the given IP address. * diff --git a/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java b/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java index 9d1f757e..be17f6cf 100644 --- a/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java +++ b/src/test/java/fr/xephi/authme/command/CommandUtilsTest.java @@ -1,6 +1,5 @@ package fr.xephi.authme.command; -import fr.xephi.authme.TestHelper; import org.bukkit.ChatColor; import org.junit.BeforeClass; import org.junit.Test; @@ -83,12 +82,6 @@ public class CommandUtilsTest { checkArgumentCount(command, 1, 3); } - @Test - public void shouldHaveHiddenConstructor() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandUtils.class); - } - @Test public void shouldFormatSimpleArgument() { // given diff --git a/src/test/java/fr/xephi/authme/command/executable/authme/debug/DebugSectionUtilsTest.java b/src/test/java/fr/xephi/authme/command/executable/authme/debug/DebugSectionUtilsTest.java index aadcfa40..1157663b 100644 --- a/src/test/java/fr/xephi/authme/command/executable/authme/debug/DebugSectionUtilsTest.java +++ b/src/test/java/fr/xephi/authme/command/executable/authme/debug/DebugSectionUtilsTest.java @@ -58,11 +58,6 @@ public class DebugSectionUtilsTest { assertThat(DebugSectionUtils.formatLocation(null), equalTo("null")); } - @Test - public void shouldHaveHiddenConstructor() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(DebugSectionUtils.class); - } - @Test public void shouldFetchMapInLimboService() { // given diff --git a/src/test/java/fr/xephi/authme/datasource/SqlDataSourceUtilsTest.java b/src/test/java/fr/xephi/authme/datasource/SqlDataSourceUtilsTest.java index e196fabd..ae297408 100644 --- a/src/test/java/fr/xephi/authme/datasource/SqlDataSourceUtilsTest.java +++ b/src/test/java/fr/xephi/authme/datasource/SqlDataSourceUtilsTest.java @@ -30,11 +30,6 @@ public class SqlDataSourceUtilsTest { logger = TestHelper.setupLogger(); } - @Test - public void shouldHaveHiddenConstructor() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(SqlDataSourceUtils.class); - } - @Test public void shouldLogException() { // given diff --git a/src/test/java/fr/xephi/authme/process/register/executors/PlayerAuthBuilderHelperTest.java b/src/test/java/fr/xephi/authme/process/register/executors/PlayerAuthBuilderHelperTest.java index a5d583df..607ba8a4 100644 --- a/src/test/java/fr/xephi/authme/process/register/executors/PlayerAuthBuilderHelperTest.java +++ b/src/test/java/fr/xephi/authme/process/register/executors/PlayerAuthBuilderHelperTest.java @@ -38,10 +38,4 @@ public class PlayerAuthBuilderHelperTest { assertThat(Math.abs(auth.getRegistrationDate() - System.currentTimeMillis()), lessThan(1000L)); assertThat(auth.getPassword(), equalToHash("myHash0001")); } - - @Test - public void shouldHaveHiddenConstructor() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(PlayerAuthBuilderHelper.class); - } - } diff --git a/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java b/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java index c62b0b40..e1579710 100644 --- a/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java +++ b/src/test/java/fr/xephi/authme/service/MigrationServiceTest.java @@ -12,9 +12,7 @@ import org.junit.BeforeClass; import org.junit.Test; import org.junit.runner.RunWith; import org.mockito.Mock; -import org.mockito.invocation.InvocationOnMock; import org.mockito.junit.MockitoJUnitRunner; -import org.mockito.stubbing.Answer; import java.util.Arrays; @@ -110,11 +108,6 @@ public class MigrationServiceTest { verifyNoMoreInteractions(settings, dataSource, sha256); } - @Test - public void shouldHaveHiddenEmptyConstructorOnly() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(MigrationService.class); - } - private static PlayerAuth authWithNickAndHash(String nick, String hash) { return PlayerAuth.builder() .name(nick) @@ -123,12 +116,9 @@ public class MigrationServiceTest { } private static void setSha256MockToUppercase(Sha256 sha256) { - given(sha256.computeHash(anyString(), anyString())).willAnswer(new Answer() { - @Override - public HashedPassword answer(InvocationOnMock invocation) { - String plainPassword = invocation.getArgument(0); - return new HashedPassword(plainPassword.toUpperCase(), null); - } + given(sha256.computeHash(anyString(), anyString())).willAnswer(invocation -> { + String plainPassword = invocation.getArgument(0); + return new HashedPassword(plainPassword.toUpperCase(), null); }); } } diff --git a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java index 9c585aed..a42a83a3 100644 --- a/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java +++ b/src/test/java/fr/xephi/authme/settings/commandconfig/CommandManagerTest.java @@ -294,12 +294,6 @@ public class CommandManagerTest { verify(bukkitService).dispatchConsoleCommand("msg Bobby sad to see you go!"); } - @Test - public void shouldHaveHiddenConstructorInSettingsHolderClass() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(CommandSettingsHolder.class); - } - private void initManager() { manager = new CommandManager(testFolder, bukkitService, geoIpService, commandMigrationService); } diff --git a/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java b/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java index 1860480f..35ab9627 100644 --- a/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java +++ b/src/test/java/fr/xephi/authme/settings/properties/AuthMeSettingsRetrieverTest.java @@ -1,7 +1,6 @@ package fr.xephi.authme.settings.properties; import ch.jalu.configme.configurationdata.ConfigurationData; -import fr.xephi.authme.TestHelper; import org.junit.Test; import static org.hamcrest.Matchers.closeTo; @@ -24,9 +23,4 @@ public class AuthMeSettingsRetrieverTest { assertThat((double) configurationData.getProperties().size(), closeTo(182, 10)); } - - @Test - public void shouldHaveHiddenConstructor() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(AuthMeSettingsRetriever.class); - } } diff --git a/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java index d0d74135..178576bc 100644 --- a/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/properties/SettingsClassConsistencyTest.java @@ -98,13 +98,6 @@ public class SettingsClassConsistencyTest { configData.getProperties(), hasSize((int) totalProperties)); } - @Test - public void shouldHaveHiddenEmptyConstructorOnly() { - for (Class clazz : classes) { - TestHelper.validateHasOnlyPrivateEmptyConstructor(clazz); - } - } - private static boolean isValidConstantField(Field field) { int modifiers = field.getModifiers(); return Modifier.isPublic(modifiers) && Modifier.isStatic(modifiers) && Modifier.isFinal(modifiers); diff --git a/src/test/java/fr/xephi/authme/util/ExceptionUtilsTest.java b/src/test/java/fr/xephi/authme/util/ExceptionUtilsTest.java index 9f60c53a..e6931b08 100644 --- a/src/test/java/fr/xephi/authme/util/ExceptionUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/ExceptionUtilsTest.java @@ -1,7 +1,6 @@ package fr.xephi.authme.util; import fr.xephi.authme.ReflectionTestUtils; -import fr.xephi.authme.TestHelper; import org.junit.Test; import java.net.MalformedURLException; @@ -55,12 +54,6 @@ public class ExceptionUtilsTest { assertThat(resultUoe, sameInstance(uoe)); } - @Test - public void shouldHaveHiddenConstructor() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(ExceptionUtils.class); - } - @Test public void shouldFormatException() { // given diff --git a/src/test/java/fr/xephi/authme/util/FileUtilsTest.java b/src/test/java/fr/xephi/authme/util/FileUtilsTest.java index 91145cc8..36af6724 100644 --- a/src/test/java/fr/xephi/authme/util/FileUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/FileUtilsTest.java @@ -185,12 +185,6 @@ public class FileUtilsTest { assertThat(dirAsFile.isFile(), equalTo(true)); } - @Test - public void shouldHaveHiddenConstructor() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(FileUtils.class); - } - - @Test public void shouldCreateCurrentTimestampString() { // given / when diff --git a/src/test/java/fr/xephi/authme/util/InternetProtocolUtilsTest.java b/src/test/java/fr/xephi/authme/util/InternetProtocolUtilsTest.java index 02d8872a..54bc7dcb 100644 --- a/src/test/java/fr/xephi/authme/util/InternetProtocolUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/InternetProtocolUtilsTest.java @@ -1,6 +1,5 @@ package fr.xephi.authme.util; -import fr.xephi.authme.TestHelper; import org.junit.Test; import static org.hamcrest.Matchers.equalTo; @@ -50,10 +49,4 @@ public class InternetProtocolUtilsTest { assertThat(InternetProtocolUtils.isLoopbackAddress("127.0.0.1"), equalTo(true)); assertThat(InternetProtocolUtils.isLoopbackAddress("::1"), equalTo(true)); } - - @Test - public void shouldHavePrivateConstructor() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(InternetProtocolUtils.class); - } } diff --git a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java index 767276e2..124011c7 100644 --- a/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/PlayerUtilsTest.java @@ -5,11 +5,9 @@ import org.bukkit.entity.Player; import org.junit.BeforeClass; import org.junit.Test; -import java.util.UUID; import static org.hamcrest.Matchers.equalTo; import static org.junit.Assert.assertThat; import static org.mockito.BDDMockito.given; -import static org.mockito.Mockito.doThrow; import static org.mockito.Mockito.mock; /** @@ -36,12 +34,6 @@ public class PlayerUtilsTest { assertThat(result, equalTo(ip)); } - @Test - public void shouldHaveHiddenConstructor() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(PlayerUtils.class); - } - @Test public void shouldCheckIfIsNpc() { // given diff --git a/src/test/java/fr/xephi/authme/util/RandomStringUtilsTest.java b/src/test/java/fr/xephi/authme/util/RandomStringUtilsTest.java index 1af9851a..a89b4922 100644 --- a/src/test/java/fr/xephi/authme/util/RandomStringUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/RandomStringUtilsTest.java @@ -1,6 +1,5 @@ package fr.xephi.authme.util; -import fr.xephi.authme.TestHelper; import org.junit.Test; import java.util.regex.Pattern; @@ -84,11 +83,4 @@ public class RandomStringUtilsTest { // then - throw exception } - - @Test - public void shouldHaveHiddenConstructor() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(RandomStringUtils.class); - } - } diff --git a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java index 76e7ae75..39a3eb93 100644 --- a/src/test/java/fr/xephi/authme/util/StringUtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/StringUtilsTest.java @@ -1,6 +1,5 @@ package fr.xephi.authme.util; -import fr.xephi.authme.TestHelper; import org.junit.Test; import static java.util.Arrays.asList; @@ -77,11 +76,6 @@ public class StringUtilsTest { assertThat(StringUtils.getDifference("test", "something"), greaterThan(0.88)); } - @Test - public void shouldHaveHiddenConstructor() { - TestHelper.validateHasOnlyPrivateEmptyConstructor(StringUtils.class); - } - @Test public void shouldCheckIfHasNeedleInWord() { // given/when/then diff --git a/src/test/java/fr/xephi/authme/util/UtilsTest.java b/src/test/java/fr/xephi/authme/util/UtilsTest.java index 1b106487..37d52163 100644 --- a/src/test/java/fr/xephi/authme/util/UtilsTest.java +++ b/src/test/java/fr/xephi/authme/util/UtilsTest.java @@ -55,12 +55,6 @@ public class UtilsTest { assertThat(result.toString(), equalTo(".*?")); } - @Test - public void shouldHavePrivateConstructorOnly() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(Utils.class); - } - @Test public void shouldLogAndSendMessage() { // given diff --git a/src/test/java/fr/xephi/authme/util/lazytags/TagBuilderTest.java b/src/test/java/fr/xephi/authme/util/lazytags/TagBuilderTest.java index 60b5b68e..53362b5f 100644 --- a/src/test/java/fr/xephi/authme/util/lazytags/TagBuilderTest.java +++ b/src/test/java/fr/xephi/authme/util/lazytags/TagBuilderTest.java @@ -1,6 +1,5 @@ package fr.xephi.authme.util.lazytags; -import fr.xephi.authme.TestHelper; import org.junit.Test; import java.util.function.Function; @@ -40,11 +39,4 @@ public class TagBuilderTest { assertThat(tag, instanceOf(DependentTag.class)); assertThat(tag.getValue(24d), equalTo("26.4")); } - - @Test - public void shouldHaveHiddenConstructor() { - // given / when / then - TestHelper.validateHasOnlyPrivateEmptyConstructor(TagBuilder.class); - } - }