NumericConstraints { public static <N extends Number & Comparable<N>> PropertyConstraint<N> inRange(final N minInclusive, final N maxInclusive) { return ConstraintFactory.fromPredicate( new Predicate<N>() { @Override public boolean test(N t) { return minInclusive.compareTo(t) <= 0 && maxInclusive.compareTo(t) >= 0; } }, "Should be between " + minInclusive + " and " + maxInclusive ); } private  NumericConstraints(); static PropertyConstraint<N> inRange(final N minInclusive, final N maxInclusive); static PropertyConstraint<N> positive();  }
@Test public void testInRangeInteger() { PropertyConstraint<Integer> constraint = NumericConstraints.inRange(1, 10); Assert.assertTrue(constraint.test(1)); Assert.assertTrue(constraint.test(5)); Assert.assertTrue(constraint.test(10)); Assert.assertFalse(constraint.test(0)); Assert.assertFalse(constraint.test(-1)); Assert.assertFalse(constraint.test(11)); Assert.assertFalse(constraint.test(100)); }
@Test public void testInRangeDouble() { PropertyConstraint<Double> constraint = NumericConstraints.inRange(1.0, 10.0); Assert.assertTrue(constraint.test(1.0)); Assert.assertTrue(constraint.test(5.5)); Assert.assertTrue(constraint.test(10.0)); Assert.assertFalse(constraint.test(0.0)); Assert.assertFalse(constraint.test(-1.0)); Assert.assertFalse(constraint.test(11.1)); Assert.assertFalse(constraint.test(100.0)); }