|
@@ -1,15 +1,17 @@
|
|
|
package org.leumasjaffe.json.schema.tester;
|
|
package org.leumasjaffe.json.schema.tester;
|
|
|
|
|
|
|
|
-import static org.hamcrest.core.Is.is;
|
|
|
|
|
import static org.junit.Assert.assertThat;
|
|
import static org.junit.Assert.assertThat;
|
|
|
import static org.junit.Assert.fail;
|
|
import static org.junit.Assert.fail;
|
|
|
import static org.leumasjaffe.json.schema.matcher.AcceptedTypes.acceptsTypes;
|
|
import static org.leumasjaffe.json.schema.matcher.AcceptedTypes.acceptsTypes;
|
|
|
import static org.leumasjaffe.json.schema.matcher.Accepts.accepts;
|
|
import static org.leumasjaffe.json.schema.matcher.Accepts.accepts;
|
|
|
|
|
+import static org.leumasjaffe.json.schema.matcher.JsonPath.jsonPath;
|
|
|
import static org.leumasjaffe.json.schema.matcher.Not.not;
|
|
import static org.leumasjaffe.json.schema.matcher.Not.not;
|
|
|
|
|
|
|
|
import java.util.function.DoublePredicate;
|
|
import java.util.function.DoublePredicate;
|
|
|
|
|
|
|
|
|
|
+import org.junit.Rule;
|
|
|
import org.junit.Test;
|
|
import org.junit.Test;
|
|
|
|
|
+import org.junit.rules.ExpectedException;
|
|
|
import org.leumasjaffe.json.schema.ValidationException;
|
|
import org.leumasjaffe.json.schema.ValidationException;
|
|
|
|
|
|
|
|
import com.fasterxml.jackson.databind.node.DoubleNode;
|
|
import com.fasterxml.jackson.databind.node.DoubleNode;
|
|
@@ -17,6 +19,7 @@ import com.fasterxml.jackson.databind.node.JsonNodeType;
|
|
|
import com.fasterxml.jackson.databind.node.NullNode;
|
|
import com.fasterxml.jackson.databind.node.NullNode;
|
|
|
|
|
|
|
|
public class NumberTesterTest {
|
|
public class NumberTesterTest {
|
|
|
|
|
+ @Rule public ExpectedException thrown = ExpectedException.none();
|
|
|
DoublePredicate nonZero = d -> d != 0;
|
|
DoublePredicate nonZero = d -> d != 0;
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
@@ -98,52 +101,37 @@ public class NumberTesterTest {
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testValidationPathIsMinimum() {
|
|
public void testValidationPathIsMinimum() {
|
|
|
- try {
|
|
|
|
|
- NumberTester.minimum(1.0).validate(new DoubleNode(0.5));
|
|
|
|
|
- fail("No exception was thrown...");
|
|
|
|
|
- } catch (ValidationException ve) {
|
|
|
|
|
- assertThat(ve.getPath(), is("#/minimum"));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ thrown.expect(ValidationException.class);
|
|
|
|
|
+ thrown.expect(jsonPath("#/minimum"));
|
|
|
|
|
+ NumberTester.minimum(1.0).validate(new DoubleNode(0.5));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testValidationPathIsExclusiveMinimum() {
|
|
public void testValidationPathIsExclusiveMinimum() {
|
|
|
- try {
|
|
|
|
|
- NumberTester.exclusiveMinimum(1.0).validate(new DoubleNode(0.5));
|
|
|
|
|
- fail("No exception was thrown...");
|
|
|
|
|
- } catch (ValidationException ve) {
|
|
|
|
|
- assertThat(ve.getPath(), is("#/exclusiveMinimum"));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ thrown.expect(ValidationException.class);
|
|
|
|
|
+ thrown.expect(jsonPath("#/exclusiveMinimum"));
|
|
|
|
|
+ NumberTester.exclusiveMinimum(1.0).validate(new DoubleNode(0.5));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testValidationPathIsMaximum() {
|
|
public void testValidationPathIsMaximum() {
|
|
|
- try {
|
|
|
|
|
- NumberTester.maximum(1.0).validate(new DoubleNode(1.5));
|
|
|
|
|
- fail("No exception was thrown...");
|
|
|
|
|
- } catch (ValidationException ve) {
|
|
|
|
|
- assertThat(ve.getPath(), is("#/maximum"));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ thrown.expect(ValidationException.class);
|
|
|
|
|
+ thrown.expect(jsonPath("#/maximum"));
|
|
|
|
|
+ NumberTester.maximum(1.0).validate(new DoubleNode(1.5));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testValidationPathIsExclusiveMaximum() {
|
|
public void testValidationPathIsExclusiveMaximum() {
|
|
|
- try {
|
|
|
|
|
- NumberTester.exclusiveMaximum(1.0).validate(new DoubleNode(1.5));
|
|
|
|
|
- fail("No exception was thrown...");
|
|
|
|
|
- } catch (ValidationException ve) {
|
|
|
|
|
- assertThat(ve.getPath(), is("#/exclusiveMaximum"));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ thrown.expect(ValidationException.class);
|
|
|
|
|
+ thrown.expect(jsonPath("#/exclusiveMaximum"));
|
|
|
|
|
+ NumberTester.exclusiveMaximum(1.0).validate(new DoubleNode(1.5));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@Test
|
|
@Test
|
|
|
public void testValidationPathIsMultipleOf() {
|
|
public void testValidationPathIsMultipleOf() {
|
|
|
- try {
|
|
|
|
|
- NumberTester.multipleOf(1.0).validate(new DoubleNode(0.5));
|
|
|
|
|
- fail("No exception was thrown...");
|
|
|
|
|
- } catch (ValidationException ve) {
|
|
|
|
|
- assertThat(ve.getPath(), is("#/multipleOf"));
|
|
|
|
|
- }
|
|
|
|
|
|
|
+ thrown.expect(ValidationException.class);
|
|
|
|
|
+ thrown.expect(jsonPath("#/multipleOf"));
|
|
|
|
|
+ NumberTester.multipleOf(1.0).validate(new DoubleNode(0.5));
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
}
|
|
}
|