|
|
@@ -0,0 +1,34 @@
|
|
|
+package org.leumasjaffe.json.schema;
|
|
|
+
|
|
|
+import static org.hamcrest.collection.IsIterableContainingInOrder.contains;
|
|
|
+import static org.junit.Assert.assertThat;
|
|
|
+import static org.leumasjaffe.json.schema.matcher.CausingExceptions.causedBy;
|
|
|
+import static org.leumasjaffe.json.schema.matcher.JsonPath.jsonPath;
|
|
|
+
|
|
|
+import org.junit.Test;
|
|
|
+
|
|
|
+public class ValidationExceptionTest {
|
|
|
+
|
|
|
+ @Test
|
|
|
+ public void testPathComesFromKey() {
|
|
|
+ assertThat(new ValidationException("test", ""), jsonPath("#/test"));
|
|
|
+ assertThat(new ValidationException(5, ""), jsonPath("#/5"));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test @SuppressWarnings("unchecked")
|
|
|
+ public void causedExceptionsPrependParentPathForKey() {
|
|
|
+ ValidationException ex = new ValidationException("test", "",
|
|
|
+ new ValidationException(0, ""),
|
|
|
+ new ValidationException(1, ""));
|
|
|
+ assertThat(ex, causedBy(contains(jsonPath("#/test/0"), jsonPath("#/test/1"))));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test @SuppressWarnings("unchecked")
|
|
|
+ public void causedExceptionsPrependParentPathForIndex() {
|
|
|
+ ValidationException ex = new ValidationException(0, "",
|
|
|
+ new ValidationException("B", ""),
|
|
|
+ new ValidationException("A", ""));
|
|
|
+ assertThat(ex, causedBy(contains(jsonPath("#/0/B"), jsonPath("#/0/A"))));
|
|
|
+ }
|
|
|
+
|
|
|
+}
|