diff --git a/pom.xml b/pom.xml index ec210eba8..7166f6640 100644 --- a/pom.xml +++ b/pom.xml @@ -560,7 +560,7 @@ ch.jalu configme - 1.0.1 + 1.1.0 true diff --git a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java index 887bf6d09..55485de0b 100644 --- a/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java +++ b/src/test/java/fr/xephi/authme/AuthMeInitializationTest.java @@ -1,5 +1,6 @@ package fr.xephi.authme; +import ch.jalu.configme.resource.PropertyReader; import ch.jalu.configme.resource.PropertyResource; import ch.jalu.injector.Injector; import ch.jalu.injector.InjectorBuilder; @@ -34,12 +35,14 @@ import org.mockito.junit.MockitoJUnitRunner; import java.io.File; import java.io.IOException; +import java.util.Collections; import java.util.logging.Logger; import static fr.xephi.authme.settings.properties.AuthMeSettingsRetriever.buildConfigurationData; 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; import static org.mockito.Mockito.mock; @@ -91,8 +94,12 @@ public class AuthMeInitializationTest { @Test public void shouldInitializeAllServices() { // given - Settings settings = - new Settings(dataFolder, mock(PropertyResource.class, RETURNS_DEEP_STUBS), null, buildConfigurationData()); + PropertyReader reader = mock(PropertyReader.class, RETURNS_DEEP_STUBS); + given(reader.getList(anyString())).willReturn(Collections.emptyList()); + PropertyResource resource = mock(PropertyResource.class); + given(resource.createReader()).willReturn(reader); + + Settings settings = new Settings(dataFolder, resource, null, buildConfigurationData()); Injector injector = new InjectorBuilder() .addDefaultHandlers("fr.xephi.authme") diff --git a/src/test/java/fr/xephi/authme/settings/SettingsConsistencyTest.java b/src/test/java/fr/xephi/authme/settings/SettingsConsistencyTest.java index 5a1de0e6e..f589e6c33 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsConsistencyTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsConsistencyTest.java @@ -120,7 +120,9 @@ public class SettingsConsistencyTest { */ private static Class> getEnumClass(Property property) { if (property instanceof EnumProperty) { - return getFieldValue(EnumProperty.class, (EnumProperty) property, "clazz"); + Class clazz = property.getDefaultValue().getClass(); + // Check if is anonymous class in case enum implements methods, e.g. AllowFlightRestoreType + return clazz.isAnonymousClass() ? clazz.getEnclosingClass() : clazz; } else if (property instanceof EnumSetProperty) { return getFieldValue(EnumSetProperty.class, (EnumSetProperty) property, "enumClass"); } diff --git a/src/test/java/fr/xephi/authme/settings/SettingsTest.java b/src/test/java/fr/xephi/authme/settings/SettingsTest.java index 93934b1ab..73d3cc8d6 100644 --- a/src/test/java/fr/xephi/authme/settings/SettingsTest.java +++ b/src/test/java/fr/xephi/authme/settings/SettingsTest.java @@ -2,6 +2,7 @@ package fr.xephi.authme.settings; import ch.jalu.configme.configurationdata.ConfigurationData; import ch.jalu.configme.configurationdata.ConfigurationDataBuilder; +import ch.jalu.configme.resource.PropertyReader; import ch.jalu.configme.resource.PropertyResource; import fr.xephi.authme.TestHelper; import fr.xephi.authme.settings.properties.TestConfiguration; @@ -14,9 +15,12 @@ import org.junit.rules.TemporaryFolder; import java.io.File; import java.io.IOException; import java.nio.file.Files; +import java.util.Collections; 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.RETURNS_DEEP_STUBS; import static org.mockito.Mockito.mock; @@ -50,7 +54,7 @@ public class SettingsTest { createFile(emailFile); Files.write(emailFile.toPath(), emailMessage.getBytes()); - PropertyResource resource = mock(PropertyResource.class, RETURNS_DEEP_STUBS); + PropertyResource resource = mockPropertyResourceAndReader(); Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA); // when @@ -68,7 +72,7 @@ public class SettingsTest { createFile(emailFile); Files.write(emailFile.toPath(), emailMessage.getBytes()); - PropertyResource resource = mock(PropertyResource.class, RETURNS_DEEP_STUBS); + PropertyResource resource = mockPropertyResourceAndReader(); Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA); // when @@ -86,7 +90,7 @@ public class SettingsTest { createFile(emailFile); Files.write(emailFile.toPath(), emailMessage.getBytes()); - PropertyResource resource = mock(PropertyResource.class, RETURNS_DEEP_STUBS); + PropertyResource resource = mockPropertyResourceAndReader(); Settings settings = new Settings(testPluginFolder, resource, null, CONFIG_DATA); // when @@ -96,6 +100,14 @@ public class SettingsTest { assertThat(result, equalTo(emailMessage)); } + private static PropertyResource mockPropertyResourceAndReader() { + PropertyReader reader = mock(PropertyReader.class, RETURNS_DEEP_STUBS); + given(reader.getList(anyString())).willReturn(Collections.emptyList()); + PropertyResource resource = mock(PropertyResource.class); + given(resource.createReader()).willReturn(reader); + return resource; + } + private static void createFile(File file) { try { file.getParentFile().mkdirs();