Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,11 @@ private void applySingleAction(final ConfigurationNode start, final Object[] pat
// No children
return;
}

if (thrown != null) {
throw thrown;
}

return;
} else {
node = node.node(path[i]);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,6 +18,7 @@

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.spongepowered.configurate.NodePath.path;

Expand Down Expand Up @@ -264,4 +265,136 @@ void testVersionedTransformationMoveChildToRoot() throws ConfigurateException {
assertEquals(transformed, original);
}

private void assertConfigurateEx(final ConfigurationNode root, final ConfigurationTransformation transformation, final int suppressedAmount) {
final ConfigurateException ex = assertThrows(ConfigurateException.class, () -> transformation.apply(root));
assertEquals(ex.rawMessage(), "test exception");

final Throwable[] suppressedArr = ex.getSuppressed();
assertEquals(suppressedArr.length, suppressedAmount);

for (final Throwable throwable : suppressedArr) {
assertEquals(throwable.getClass(), ConfigurateException.class);
final ConfigurateException suppressedEx = (ConfigurateException) throwable;
assertEquals(suppressedEx.rawMessage(), "test suppressed exception");
}
}

@Test
void testSingleTransformationThrowsConfigurateException() throws ConfigurateException {
final BasicConfigurationNode root = BasicConfigurationNode.root(b -> {
b.node("test-key").raw("test-value");
b.node("zzz").raw("zzz");
b.node("zzzz").raw("zzzz");
});

final ConfigurationTransformation transformation = ConfigurationTransformation.builder()
.addAction(path("test-key"), (path, value) -> {
throw new ConfigurateException("test exception");
})
.addAction(path("zzz"), (path, value) -> {
throw new ConfigurateException("test suppressed exception");
})
.addAction(path("zzzz"), (path, value) -> {
throw new ConfigurateException("test suppressed exception");
})
.build();

this.assertConfigurateEx(root, transformation, 2);
}

private ConfigurationTransformation createWildcardTransformation() {
return ConfigurationTransformation.builder()
.addAction(path("test", ConfigurationTransformation.WILDCARD_OBJECT), (path, value) -> {
if (value.getString().equals("value1")) {
throw new ConfigurateException("test exception");
} else {
throw new ConfigurateException("test suppressed exception");
}
})
.build();
}

@Test
void testSingleTransformationWildcardMapThrowsConfigurateException() throws ConfigurateException {
final BasicConfigurationNode root = BasicConfigurationNode.root(b -> {
b.node("test").act(t -> {
t.node("child1").raw("value1");
t.node("child2").raw("value2");
t.node("child3").raw("value3");
});
});

final ConfigurationTransformation transformation = this.createWildcardTransformation();

this.assertConfigurateEx(root, transformation, 2);
}

@Test
void testSingleTransformationWildcardListThrowsConfigurateException() throws ConfigurateException {
final BasicConfigurationNode root = BasicConfigurationNode.root(b -> {
b.node("test").setList(String.class, Arrays.asList("value1", "value2", "value3"));
});

final ConfigurationTransformation transformation = this.createWildcardTransformation();

this.assertConfigurateEx(root, transformation, 2);
}

@Test
void testVersionedTransformationThrowsConfigurateException() throws ConfigurateException {
final BasicConfigurationNode root = BasicConfigurationNode.root(b -> {
b.node("test").raw("test value");
b.node("zzz").raw("zzz");
b.node("zzzz").raw("zzzz");
});

final ConfigurationTransformation.Versioned transformation = ConfigurationTransformation.versionedBuilder()
.makeVersion(0, (version) -> {
version.addAction(path("test"), (path, value) -> null);
})
.makeVersion(1, (version) -> {
version.addAction(path("test"), (path, value) -> {
throw new ConfigurateException("test exception");
});
version.addAction(path("zzz"), (path, value) -> {
throw new ConfigurateException("test suppressed exception");
});
version.addAction(path("zzzz"), (path, value) -> {
throw new ConfigurateException("test suppressed exception");
});
})
.build();

this.assertConfigurateEx(root, transformation, 2);
}

@Test
void testChainedTransformationThrowsConfigurateException() throws ConfigurateException {
final BasicConfigurationNode root = BasicConfigurationNode.root(b -> {
b.node("test").raw("test");
b.node("zzz").raw("zzz");
b.node("zzzz").raw("zzzz");
});

final ConfigurationTransformation transformation = ConfigurationTransformation.chain(
ConfigurationTransformation.builder()
.addAction(path("test"), (path, value) -> {
throw new ConfigurateException("test exception");
})
.build(),
ConfigurationTransformation.builder()
.addAction(path("zzz"), (path, value) -> {
throw new ConfigurateException("test suppressed exception");
})
.build(),
ConfigurationTransformation.builder()
.addAction(path("zzzz"), (path, value) -> {
throw new ConfigurateException("test suppressed exception");
})
.build()
);

this.assertConfigurateEx(root, transformation, 2);
}

}