Update to ConfigMe 1.1.0

- Squash of PR #1764
This commit is contained in:
ljacqu 2019-03-01 20:22:38 +01:00
parent ffb957ff19
commit c856191659
4 changed files with 28 additions and 7 deletions

View File

@ -560,7 +560,7 @@
<dependency>
<groupId>ch.jalu</groupId>
<artifactId>configme</artifactId>
<version>1.0.1</version>
<version>1.1.0</version>
<optional>true</optional>
<exclusions>
<exclusion>

View File

@ -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")

View File

@ -120,7 +120,9 @@ public class SettingsConsistencyTest {
*/
private static Class<? extends Enum<?>> 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");
}

View File

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