|
6 | 6 | import dev.jorel.commandapi.config.ConfigGenerator; |
7 | 7 | import dev.jorel.commandapi.config.ConfigurationAdapter; |
8 | 8 | import dev.jorel.commandapi.config.DefaultBukkitConfig; |
| 9 | +import org.bukkit.configuration.ConfigurationSection; |
9 | 10 | import org.bukkit.configuration.file.YamlConfiguration; |
10 | 11 | import org.junit.jupiter.api.AfterEach; |
11 | 12 | import org.junit.jupiter.api.BeforeEach; |
12 | 13 | import org.junit.jupiter.api.Test; |
13 | 14 |
|
14 | 15 | import java.util.Arrays; |
15 | 16 | import java.util.LinkedHashMap; |
| 17 | +import java.util.List; |
16 | 18 | import java.util.Map; |
17 | 19 | import java.util.Set; |
18 | 20 |
|
@@ -143,6 +145,17 @@ public void testConfigOptionCommentUpdate() { |
143 | 145 | ), updatedAdapter); |
144 | 146 | } |
145 | 147 |
|
| 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 | + |
146 | 159 | // Test methods |
147 | 160 | public void validateConfigOptions(Set<String> options, BukkitConfigurationAdapter adapter) { |
148 | 161 | boolean containsAll; |
@@ -175,4 +188,21 @@ public void validateConfigOptionsAbsent(Set<String> options, BukkitConfiguration |
175 | 188 | } |
176 | 189 | } |
177 | 190 |
|
| 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 | + |
178 | 208 | } |
0 commit comments