Skip to content

Commit 95a831d

Browse files
committed
Another test
1 parent 54437c3 commit 95a831d

File tree

1 file changed

+30
-0
lines changed
  • commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test

1 file changed

+30
-0
lines changed

commandapi-platforms/commandapi-bukkit/commandapi-bukkit-test/commandapi-bukkit-test-tests/src/test/java/dev/jorel/commandapi/test/ConfigGenerationTests.java

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -6,13 +6,15 @@
66
import dev.jorel.commandapi.config.ConfigGenerator;
77
import dev.jorel.commandapi.config.ConfigurationAdapter;
88
import dev.jorel.commandapi.config.DefaultBukkitConfig;
9+
import org.bukkit.configuration.ConfigurationSection;
910
import org.bukkit.configuration.file.YamlConfiguration;
1011
import org.junit.jupiter.api.AfterEach;
1112
import org.junit.jupiter.api.BeforeEach;
1213
import org.junit.jupiter.api.Test;
1314

1415
import java.util.Arrays;
1516
import java.util.LinkedHashMap;
17+
import java.util.List;
1618
import java.util.Map;
1719
import java.util.Set;
1820

@@ -143,6 +145,17 @@ public void testConfigOptionCommentUpdate() {
143145
), updatedAdapter);
144146
}
145147

148+
@Test
149+
public void testNestedSections() {
150+
CommentedConfigOption<Boolean> subSubOption = new CommentedConfigOption<>(new String[0], false);
151+
152+
bukkitConfig.getAllOptions().put("root.nested.option", subSubOption);
153+
generator = ConfigGenerator.createNew(bukkitConfig);
154+
BukkitConfigurationAdapter updatedAdapter = (BukkitConfigurationAdapter) generator.generate(adapter);
155+
156+
validateSections(List.of("root", "nested"), "option", updatedAdapter.config());
157+
}
158+
146159
// Test methods
147160
public void validateConfigOptions(Set<String> options, BukkitConfigurationAdapter adapter) {
148161
boolean containsAll;
@@ -175,4 +188,21 @@ public void validateConfigOptionsAbsent(Set<String> options, BukkitConfiguration
175188
}
176189
}
177190

191+
public void validateSections(List<String> sections, String expectedOption, YamlConfiguration config) {
192+
ConfigurationSection root = config.getConfigurationSection(sections.get(0));
193+
if (root == null) {
194+
throw new IllegalStateException("Section '" + sections.get(0) + "' does not exist!");
195+
}
196+
for (int i = 1; i < sections.size(); i++) {
197+
root = root.getConfigurationSection(sections.get(i));
198+
if (root == null) {
199+
throw new IllegalStateException("Section '" + sections.get(i) + "' does not exist!");
200+
}
201+
}
202+
Object expectedValue = root.get(expectedOption);
203+
if (expectedValue == null) {
204+
throw new IllegalStateException("Expected option '" + expectedOption + "' was not found in section '" + root.getName() + "'!");
205+
}
206+
}
207+
178208
}

0 commit comments

Comments
 (0)