Skip to content

Commit

Permalink
Try to find server registration error, did not.
Browse files Browse the repository at this point in the history
  • Loading branch information
AuroraLS3 committed May 26, 2022
1 parent 24e955e commit c153768
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 7 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -92,7 +92,7 @@ public void save(Server server) {
if (!prepared) prepare();

server.getId().ifPresent(id -> set("Server.ID", id));
set("Server.UUID", server.getUuid());
set("Server.UUID", server.getUuid().toString());
set("Server.Web_address", server.getWebAddress());

save();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -303,7 +303,7 @@ public Map<String, String> getStringMap(boolean fullKeys) {
* @return List of config keys
*/
public List<String> getConfigPaths() {
Stack<ConfigNode> dfs = new Stack<>();
ArrayDeque<ConfigNode> dfs = new ArrayDeque<>();
dfs.push(this);

List<String> configPaths = new ArrayList<>();
Expand Down Expand Up @@ -345,7 +345,9 @@ public void copyMissing(ConfigNode from) {
}

// Override value conditionally
if (value == null || value.isEmpty() && from.value != null) {
boolean currentValueIsMissing = value == null || value.isEmpty();
boolean otherNodeHasValue = from.value != null && !from.value.isEmpty();
if (currentValueIsMissing && otherNodeHasValue) {
value = from.value;
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,12 +17,12 @@
package com.djrapitops.plan.settings.config;

import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.DynamicTest;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.TestFactory;

import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Optional;
import java.util.*;
import java.util.stream.Collectors;

import static org.junit.jupiter.api.Assertions.*;

Expand Down Expand Up @@ -371,4 +371,26 @@ void copyDefaultAddsProperValues() {
copied = testTree.getString("Test." + SECOND_LEVEL + "." + THIRD_LEVEL);
assertEquals("ORIGINAL", copied);
}

@TestFactory
Collection<DynamicTest> copyMissingCorrectnessTests() {
return Arrays.stream(new String[][]{
new String[]{"", "Value"},
new String[]{null, "Value"},
new String[]{"Value", ""},
new String[]{"Value", null}
}).map(valuePair -> {
String previousValue = valuePair[0];
String overridingValue = valuePair[1];
return DynamicTest.dynamicTest("ConfigNode#copyMissing sets 'Value' correctly '" + previousValue + "', '" + overridingValue + "'",
() -> {
ConfigNode underTest = new ConfigNode("Test", null, previousValue);
ConfigNode copyFrom = new ConfigNode("Test", null, overridingValue);

underTest.copyMissing(copyFrom);

assertEquals("Value", underTest.getString());
});
}).collect(Collectors.toList());
}
}

0 comments on commit c153768

Please sign in to comment.