@Override public SimpleCommentedConfigurationNode getNode(Object... path) { return (SimpleCommentedConfigurationNode)super.getNode(path); }
@NonNull @Override public SimpleAttributedConfigurationNode getNode(@NonNull Object... path) { return (SimpleAttributedConfigurationNode) super.getNode(path); }
@NonNull @Override public SimpleCommentedConfigurationNode getNode(@NonNull Object... path) { return (SimpleCommentedConfigurationNode) super.getNode(path); }
@NonNull @Override public SimpleAttributedConfigurationNode getNode(@NonNull Object... path) { return (SimpleAttributedConfigurationNode) super.getNode(path); }
@NonNull @Override public SimpleCommentedConfigurationNode getNode(@NonNull Object... path) { return (SimpleCommentedConfigurationNode) super.getNode(path); }
@Test public void testBooleanSerializer() throws ObjectMappingException { final TypeToken<Boolean> booleanType = TypeToken.of(Boolean.class); final TypeSerializer<Boolean> booleanSerializer = SERIALIZERS.get(booleanType); SimpleConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("direct").setValue(true); node.getNode("fromstring").setValue("true"); assertEquals(true, booleanSerializer.deserialize(booleanType, node.getNode("direct"))); assertEquals(true, booleanSerializer.deserialize(booleanType, node.getNode("fromstring"))); }
@Test public void testEnumValueSerializer() throws ObjectMappingException { final TypeToken<TestEnum> enumType = TypeToken.of(TestEnum.class); final TypeSerializer<TestEnum> enumSerializer = SERIALIZERS.get(enumType); SimpleConfigurationNode node = SimpleConfigurationNode.root(); node.getNode("present_val").setValue("first"); node.getNode("another_present_val").setValue("SECOND"); node.getNode(("casematters_val")).setValue("tHiRd"); node.getNode(("casematters_val_lowercase")).setValue("third"); node.getNode("invalid_val").setValue("3rd"); assertEquals(TestEnum.FIRST, enumSerializer.deserialize(enumType, node.getNode("present_val"))); assertEquals(TestEnum.SECOND, enumSerializer.deserialize(enumType, node.getNode("another_present_val"))); assertEquals(TestEnum.Third, enumSerializer.deserialize(enumType, node.getNode("casematters_val"))); assertEquals(TestEnum.third, enumSerializer.deserialize(enumType, node.getNode("casematters_val_lowercase"))); Assertions.assertThrows(ObjectMappingException.class, () -> { enumSerializer.deserialize(enumType, node.getNode("invalid_val")); }); }
@Test public void testTraversingNodeCreation() { SimpleConfigurationNode config = SimpleConfigurationNode.root(); SimpleConfigurationNode nodeOne = config.getNode("uncreated", "step", "node"); SimpleConfigurationNode nodeTwo = config.getNode("uncreated", "step", "color"); nodeOne.setValue("one"); nodeTwo.setValue("lilac"); ConfigurationNode attachedParent = config.getNode("uncreated", "step"); assertEquals(attachedParent, nodeOne.getParentEnsureAttached()); assertEquals(attachedParent, nodeTwo.getParentEnsureAttached()); }
@Test public void testMergeValues() { SimpleConfigurationNode first = SimpleConfigurationNode.root(); SimpleConfigurationNode second = SimpleConfigurationNode.root(); first.getNode("scalar").setValue("one"); first.getNode("absent").setValue("butmerged"); second.getNode("scalar").setValue("two"); ConfigurationNode firstAbsentMap = first.getNode("absent-map"); firstAbsentMap.getNode("a").setValue("one"); firstAbsentMap.getNode("b").setValue("two"); ConfigurationNode firstMergedMap = first.getNode("merged-map"); ConfigurationNode secondMergedMap = second.getNode("merged-map"); firstMergedMap.getNode("source").setValue("first"); secondMergedMap.getNode("source").setValue("second"); firstMergedMap.getNode("first-only").setValue("yeah"); secondMergedMap.getNode("second-only").setValue("yeah"); second.mergeValuesFrom(first); assertEquals("two", second.getNode("scalar").getString()); assertEquals("butmerged", second.getNode("absent").getString()); assertEquals("one", second.getNode("absent-map", "a").getString()); assertEquals("two", second.getNode("absent-map", "b").getString()); assertEquals("second", second.getNode("merged-map", "source").getString()); assertEquals("yeah", second.getNode("merged-map", "first-only").getString()); assertEquals("yeah", second.getNode("merged-map", "second-only").getString()); }