NumberSchema extends Schema { public static Builder builder() { return new Builder(); } NumberSchema();  NumberSchema(final Builder builder); static Builder builder(); Number getMaximum(); Number getMinimum(); Number getMultipleOf(); boolean isExclusiveMaximum(); boolean isExclusiveMinimum(); boolean requiresInteger(); boolean isRequiresNumber(); Number getExclusiveMinimumLimit(); Number getExclusiveMaximumLimit(); @Override boolean equals(Object o); @Override int hashCode();  }
@Test public void exclusiveMinimum() { NumberSchema subject = buildWithLocation(NumberSchema.builder().minimum(10.0).exclusiveMinimum(true)); TestSupport.failureOf(subject) .expectedKeyword("exclusiveMinimum") .input(10) .expect(); }
@Test public void maximum() { NumberSchema subject = buildWithLocation(NumberSchema.builder().maximum(20.0)); TestSupport.failureOf(subject) .expectedKeyword("maximum") .input(21) .expect(); }
@Test public void exclusiveMaximum() { NumberSchema subject = buildWithLocation(NumberSchema.builder().maximum(20.0).exclusiveMaximum(true)); TestSupport.failureOf(subject) .expectedKeyword("exclusiveMaximum") .input(20) .expect(); }
@Test public void minimumFailure() { NumberSchema subject = buildWithLocation(NumberSchema.builder().minimum(10.0)); TestSupport.failureOf(subject) .expectedKeyword("minimum") .input(9) .expect(); }
@Test public void exclusiveMinimumLimit() { TestSupport.failureOf(NumberSchema.builder().exclusiveMinimum(10)) .expectedKeyword("exclusiveMinimum") .expectedMessageFragment("10 is not greater than 10") .input(10) .expect(); }
@Test public void exclusiveMaximumLimit() { TestSupport.failureOf(NumberSchema.builder().exclusiveMaximum(10)) .expectedKeyword("exclusiveMaximum") .expectedMessageFragment("10 is not less than 10") .input(10) .expect(); }
@Test public void exclusiveLimitsSuccess() { NumberSchema.builder() .exclusiveMinimum(5) .exclusiveMaximum(10) .build() .validate(6); }
@Test public void multipleOfFailure() { NumberSchema subject = buildWithLocation(NumberSchema.builder().multipleOf(10)); TestSupport.failureOf(subject) .expectedKeyword("multipleOf") .input(15) .expect(); }
@Test public void shouldListAllViolationsWhenThereIsMoreThanOne() { try { NumberSchema.builder() .multipleOf(10).minimum(10.0).maximum(15.0) .build() .validate(3); } catch (ValidationException ve) { assertEquals(2, ve.getViolationCount()); assertEquals("minimum", ve.getCausingExceptions().get(0).getKeyword()); assertEquals("multipleOf", ve.getCausingExceptions().get(1).getKeyword()); } }
@Test public void notRequiresNumber() { NumberSchema.builder().requiresNumber(false).build().validate("foo"); }
@Test public void smallMultipleOf() { NumberSchema.builder() .multipleOf(0.0001) .build().validate(0.0075); }
@Test public void success() { NumberSchema.builder() .minimum(10.0) .maximum(11.0) .exclusiveMaximum(true) .multipleOf(10) .build().validate(10.0); }
@Test public void typeFailure() { TestSupport.failureOf(NumberSchema.builder()) .expectedKeyword("type") .input(null) .expect(); }
@Test public void toStringExclusiveKeywordClash() { NumberSchema subject = NumberSchema.builder() .requiresNumber(true) .minimum(0).maximum(10) .multipleOf(5) .exclusiveMinimum(true) .exclusiveMaximum(true) .exclusiveMinimum(5) .exclusiveMaximum(10) .build(); try { subject.toString(); fail(); } catch (IllegalStateException e) { assertEquals("overloaded use of exclusiveMinimum or exclusiveMaximum keyword", e.getMessage()); } }
@Test public void exclusiveMinimumDoubleBoundary() { NumberSchema.Builder subject = NumberSchema.builder().requiresNumber(true) .exclusiveMinimum(3.0); TestSupport.failureOf(subject) .input(3.0) .expectedMessageFragment("3.0 is not greater than") .expect(); }
@Test public void requiresNumber_nullable() { NumberSchema subject = NumberSchema.builder().requiresNumber(true).nullable(true).build(); subject.validate(JSONObject.NULL); }