From 204a564a9ab9397a4872dda6bc5d18de68f8f82d Mon Sep 17 00:00:00 2001 From: ljacqu Date: Tue, 5 Jan 2016 21:59:08 +0100 Subject: [PATCH] Move new configuration packages and add test for PropertyMap --- .../settings/custom/ConverterSettings.java | 12 ++--- .../settings/custom/DatabaseSettings.java | 12 ++--- .../authme/settings/custom/EmailSettings.java | 16 +++--- .../authme/settings/custom/HooksSettings.java | 10 ++-- .../authme/settings/custom/NewSetting.java | 8 +-- .../settings/custom/ProtectionSettings.java | 14 ++--- .../authme/settings/custom/PurgeSettings.java | 14 ++--- .../settings/custom/SecuritySettings.java | 12 ++--- .../settings/{custom => }/domain/Comment.java | 2 +- .../{custom => }/domain/Property.java | 2 +- .../{custom => }/domain/PropertyType.java | 2 +- .../{custom => }/domain/SettingsClass.java | 2 +- .../{custom => }/propertymap/Node.java | 2 +- .../{custom => }/propertymap/PropertyMap.java | 4 +- .../propertymap/PropertyMapComparator.java | 4 +- .../settings/custom/NewSettingTest.java | 6 +-- .../settings/propertymap/PropertyMapTest.java | 53 +++++++++++++++++++ 17 files changed, 114 insertions(+), 61 deletions(-) rename src/main/java/fr/xephi/authme/settings/{custom => }/domain/Comment.java (88%) rename src/main/java/fr/xephi/authme/settings/{custom => }/domain/Property.java (98%) rename src/main/java/fr/xephi/authme/settings/{custom => }/domain/PropertyType.java (99%) rename src/main/java/fr/xephi/authme/settings/{custom => }/domain/SettingsClass.java (68%) rename src/main/java/fr/xephi/authme/settings/{custom => }/propertymap/Node.java (98%) rename src/main/java/fr/xephi/authme/settings/{custom => }/propertymap/PropertyMap.java (90%) rename src/main/java/fr/xephi/authme/settings/{custom => }/propertymap/PropertyMapComparator.java (91%) create mode 100644 src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java diff --git a/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java b/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java index c9f1ba99..f208727b 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/ConverterSettings.java @@ -1,12 +1,12 @@ package fr.xephi.authme.settings.custom; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; -import static fr.xephi.authme.settings.custom.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.custom.domain.PropertyType.STRING; +import static fr.xephi.authme.settings.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; +import static fr.xephi.authme.settings.domain.PropertyType.STRING; public class ConverterSettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java b/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java index d8c5d991..d638fd8f 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/DatabaseSettings.java @@ -1,13 +1,13 @@ package fr.xephi.authme.settings.custom; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; -import static fr.xephi.authme.settings.custom.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.custom.domain.PropertyType.STRING; +import static fr.xephi.authme.settings.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; +import static fr.xephi.authme.settings.domain.PropertyType.STRING; public class DatabaseSettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java b/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java index f53d9549..dcde5019 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/EmailSettings.java @@ -1,16 +1,16 @@ package fr.xephi.authme.settings.custom; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; import java.util.List; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; -import static fr.xephi.authme.settings.custom.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.custom.domain.PropertyType.INTEGER; -import static fr.xephi.authme.settings.custom.domain.PropertyType.STRING; -import static fr.xephi.authme.settings.custom.domain.PropertyType.STRING_LIST; +import static fr.xephi.authme.settings.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; +import static fr.xephi.authme.settings.domain.PropertyType.INTEGER; +import static fr.xephi.authme.settings.domain.PropertyType.STRING; +import static fr.xephi.authme.settings.domain.PropertyType.STRING_LIST; public class EmailSettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java b/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java index 6f75eb24..6e23c739 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/HooksSettings.java @@ -1,11 +1,11 @@ package fr.xephi.authme.settings.custom; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.PropertyType; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.PropertyType; +import fr.xephi.authme.settings.domain.SettingsClass; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.Property.newProperty; public class HooksSettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java b/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java index 1b56cd0f..138c37d3 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java +++ b/src/main/java/fr/xephi/authme/settings/custom/NewSetting.java @@ -1,10 +1,10 @@ package fr.xephi.authme.settings.custom; import fr.xephi.authme.ConsoleLogger; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; -import fr.xephi.authme.settings.custom.propertymap.PropertyMap; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; +import fr.xephi.authme.settings.propertymap.PropertyMap; import fr.xephi.authme.util.CollectionUtils; import fr.xephi.authme.util.StringUtils; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java b/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java index 9f5daf95..b71a9589 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/ProtectionSettings.java @@ -1,15 +1,15 @@ package fr.xephi.authme.settings.custom; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; import java.util.List; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; -import static fr.xephi.authme.settings.custom.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.custom.domain.PropertyType.INTEGER; -import static fr.xephi.authme.settings.custom.domain.PropertyType.STRING_LIST; +import static fr.xephi.authme.settings.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; +import static fr.xephi.authme.settings.domain.PropertyType.INTEGER; +import static fr.xephi.authme.settings.domain.PropertyType.STRING_LIST; public class ProtectionSettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java b/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java index c46e8648..e2e1c029 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/PurgeSettings.java @@ -1,13 +1,13 @@ package fr.xephi.authme.settings.custom; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; -import static fr.xephi.authme.settings.custom.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.custom.domain.PropertyType.INTEGER; -import static fr.xephi.authme.settings.custom.domain.PropertyType.STRING; +import static fr.xephi.authme.settings.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; +import static fr.xephi.authme.settings.domain.PropertyType.INTEGER; +import static fr.xephi.authme.settings.domain.PropertyType.STRING; public class PurgeSettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java b/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java index 4b4638b3..c18e7e7c 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java +++ b/src/main/java/fr/xephi/authme/settings/custom/SecuritySettings.java @@ -1,12 +1,12 @@ package fr.xephi.authme.settings.custom; -import fr.xephi.authme.settings.custom.domain.Comment; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.SettingsClass; +import fr.xephi.authme.settings.domain.Comment; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.SettingsClass; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; -import static fr.xephi.authme.settings.custom.domain.PropertyType.BOOLEAN; -import static fr.xephi.authme.settings.custom.domain.PropertyType.INTEGER; +import static fr.xephi.authme.settings.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.PropertyType.BOOLEAN; +import static fr.xephi.authme.settings.domain.PropertyType.INTEGER; public class SecuritySettings implements SettingsClass { diff --git a/src/main/java/fr/xephi/authme/settings/custom/domain/Comment.java b/src/main/java/fr/xephi/authme/settings/domain/Comment.java similarity index 88% rename from src/main/java/fr/xephi/authme/settings/custom/domain/Comment.java rename to src/main/java/fr/xephi/authme/settings/domain/Comment.java index f664e424..92713aee 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/domain/Comment.java +++ b/src/main/java/fr/xephi/authme/settings/domain/Comment.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings.custom.domain; +package fr.xephi.authme.settings.domain; import java.lang.annotation.ElementType; import java.lang.annotation.Retention; diff --git a/src/main/java/fr/xephi/authme/settings/custom/domain/Property.java b/src/main/java/fr/xephi/authme/settings/domain/Property.java similarity index 98% rename from src/main/java/fr/xephi/authme/settings/custom/domain/Property.java rename to src/main/java/fr/xephi/authme/settings/domain/Property.java index 89b9f942..71e11164 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/domain/Property.java +++ b/src/main/java/fr/xephi/authme/settings/domain/Property.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings.custom.domain; +package fr.xephi.authme.settings.domain; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/fr/xephi/authme/settings/custom/domain/PropertyType.java b/src/main/java/fr/xephi/authme/settings/domain/PropertyType.java similarity index 99% rename from src/main/java/fr/xephi/authme/settings/custom/domain/PropertyType.java rename to src/main/java/fr/xephi/authme/settings/domain/PropertyType.java index ac6d3d69..dba0e971 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/domain/PropertyType.java +++ b/src/main/java/fr/xephi/authme/settings/domain/PropertyType.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings.custom.domain; +package fr.xephi.authme.settings.domain; import org.bukkit.configuration.file.YamlConfiguration; diff --git a/src/main/java/fr/xephi/authme/settings/custom/domain/SettingsClass.java b/src/main/java/fr/xephi/authme/settings/domain/SettingsClass.java similarity index 68% rename from src/main/java/fr/xephi/authme/settings/custom/domain/SettingsClass.java rename to src/main/java/fr/xephi/authme/settings/domain/SettingsClass.java index 6820e12e..796505ad 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/domain/SettingsClass.java +++ b/src/main/java/fr/xephi/authme/settings/domain/SettingsClass.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings.custom.domain; +package fr.xephi.authme.settings.domain; /** * Marker for classes that define {@link Property} fields. diff --git a/src/main/java/fr/xephi/authme/settings/custom/propertymap/Node.java b/src/main/java/fr/xephi/authme/settings/propertymap/Node.java similarity index 98% rename from src/main/java/fr/xephi/authme/settings/custom/propertymap/Node.java rename to src/main/java/fr/xephi/authme/settings/propertymap/Node.java index 4e621617..70d8ce23 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/propertymap/Node.java +++ b/src/main/java/fr/xephi/authme/settings/propertymap/Node.java @@ -1,4 +1,4 @@ -package fr.xephi.authme.settings.custom.propertymap; +package fr.xephi.authme.settings.propertymap; import java.util.ArrayList; import java.util.List; diff --git a/src/main/java/fr/xephi/authme/settings/custom/propertymap/PropertyMap.java b/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMap.java similarity index 90% rename from src/main/java/fr/xephi/authme/settings/custom/propertymap/PropertyMap.java rename to src/main/java/fr/xephi/authme/settings/propertymap/PropertyMap.java index e539db7a..934245a0 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/propertymap/PropertyMap.java +++ b/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMap.java @@ -1,6 +1,6 @@ -package fr.xephi.authme.settings.custom.propertymap; +package fr.xephi.authme.settings.propertymap; -import fr.xephi.authme.settings.custom.domain.Property; +import fr.xephi.authme.settings.domain.Property; import java.util.Map; import java.util.Set; diff --git a/src/main/java/fr/xephi/authme/settings/custom/propertymap/PropertyMapComparator.java b/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMapComparator.java similarity index 91% rename from src/main/java/fr/xephi/authme/settings/custom/propertymap/PropertyMapComparator.java rename to src/main/java/fr/xephi/authme/settings/propertymap/PropertyMapComparator.java index 9b07070b..e646fb61 100644 --- a/src/main/java/fr/xephi/authme/settings/custom/propertymap/PropertyMapComparator.java +++ b/src/main/java/fr/xephi/authme/settings/propertymap/PropertyMapComparator.java @@ -1,6 +1,6 @@ -package fr.xephi.authme.settings.custom.propertymap; +package fr.xephi.authme.settings.propertymap; -import fr.xephi.authme.settings.custom.domain.Property; +import fr.xephi.authme.settings.domain.Property; import java.util.Comparator; diff --git a/src/test/java/fr/xephi/authme/settings/custom/NewSettingTest.java b/src/test/java/fr/xephi/authme/settings/custom/NewSettingTest.java index 585f128e..419d5917 100644 --- a/src/test/java/fr/xephi/authme/settings/custom/NewSettingTest.java +++ b/src/test/java/fr/xephi/authme/settings/custom/NewSettingTest.java @@ -1,8 +1,8 @@ package fr.xephi.authme.settings.custom; import fr.xephi.authme.datasource.DataSource; -import fr.xephi.authme.settings.custom.domain.Property; -import fr.xephi.authme.settings.custom.domain.PropertyType; +import fr.xephi.authme.settings.domain.Property; +import fr.xephi.authme.settings.domain.PropertyType; import org.bukkit.configuration.file.YamlConfiguration; import org.junit.Test; import org.mockito.invocation.InvocationOnMock; @@ -12,7 +12,7 @@ import java.io.File; import java.net.URL; import java.util.List; -import static fr.xephi.authme.settings.custom.domain.Property.newProperty; +import static fr.xephi.authme.settings.domain.Property.newProperty; import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.contains; import static org.hamcrest.Matchers.equalTo; diff --git a/src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java b/src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java new file mode 100644 index 00000000..895b12e1 --- /dev/null +++ b/src/test/java/fr/xephi/authme/settings/propertymap/PropertyMapTest.java @@ -0,0 +1,53 @@ +package fr.xephi.authme.settings.propertymap; + +import fr.xephi.authme.settings.domain.Property; +import org.junit.Assert; +import org.junit.Test; + +import java.util.ArrayList; +import java.util.Arrays; +import java.util.List; +import java.util.Map; +import java.util.Set; + + +import static org.hamcrest.Matchers.contains; +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +/** + * Test for {@link PropertyMap}. + */ +public class PropertyMapTest { + + @Test + public void shouldKeepEntriesByInsertionAndGroup() { + // given + List paths = Arrays.asList("japan", "indonesia.jakarta", "japan.tokyo", "china.shanghai", "egypt.cairo", + "china.shenzhen", "china", "indonesia.jakarta.tugu", "egypt", "japan.nagoya", "japan.tokyo.taito"); + PropertyMap map = new PropertyMap(); + + // when + for (String path : paths) { + Property property = createPropertyWithPath(path); + map.put(property, new String[0]); + } + + // then + Set> entrySet = map.entrySet(); + List resultPaths = new ArrayList<>(entrySet.size()); + for (Map.Entry entry : entrySet) { + resultPaths.add(entry.getKey().getPath()); + } + + Assert.assertThat(resultPaths, contains("japan", "japan.tokyo", "japan.tokyo.taito", "japan.nagoya", + "indonesia.jakarta", "indonesia.jakarta.tugu", "china", "china.shanghai", "china.shenzhen", + "egypt", "egypt.cairo")); + } + + private static Property createPropertyWithPath(String path) { + Property property = mock(Property.class); + when(property.getPath()).thenReturn(path); + return property; + } +}