#1467 Rearrange old keys migration so no entries get lost

- 'error' was an old entry but now we have multiple entries under 'error' (which is now a section), so we need to ensure that we migrate the old 'error' entry before the migration sets anything under that path
This commit is contained in:
ljacqu
2018-02-02 18:53:08 +01:00
parent f44353ed4c
commit 1d6d9eb764
34 changed files with 154 additions and 105 deletions
@@ -108,7 +108,7 @@ public class MessageUpdaterTest {
.collect(Collectors.toSet());
// when
Set<String> messageKeysFromConfigData = MessageUpdater.CONFIGURATION_DATA.getProperties().stream()
Set<String> messageKeysFromConfigData = MessageUpdater.getConfigurationData().getProperties().stream()
.map(Property::getPath)
.collect(Collectors.toSet());
@@ -125,7 +125,7 @@ public class MessageUpdaterTest {
// when
Map<String, String[]> comments = ReflectionTestUtils.getFieldValue(
ConfigurationData.class, MessageUpdater.CONFIGURATION_DATA, "sectionComments");
ConfigurationData.class, MessageUpdater.getConfigurationData(), "sectionComments");
// then
assertThat(comments.keySet(), equalTo(rootPaths));
@@ -0,0 +1,41 @@
package fr.xephi.authme.message.updater;
import fr.xephi.authme.message.MessageKey;
import org.junit.Test;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import static org.junit.Assert.fail;
/**
* Test for {@link OldMessageKeysMigrater}.
*/
public class OldMessageKeysMigraterTest {
@Test
public void shouldHasOldKeysThatAreNewParentsFirstInMap() {
// given
Set<String> parentPaths = collectParentPathsFromMessageKeys();
Set<String> encounteredParents = new HashSet<>();
// when / then
for (Map.Entry<MessageKey, String> entry : OldMessageKeysMigrater.KEYS_TO_OLD_PATH.entrySet()) {
if (parentPaths.contains(entry.getValue()) && encounteredParents.contains(entry.getValue())) {
fail("Entry migrating old path '" + entry.getValue()
+ "' should come before any new paths with it as parent");
}
String parent = entry.getKey().getKey().split("\\.")[0];
encounteredParents.add(parent);
}
}
private Set<String> collectParentPathsFromMessageKeys() {
return Arrays.stream(MessageKey.values())
.map(mk -> mk.getKey().split("\\.")[0])
.collect(Collectors.toSet());
}
}