RangeBand implements Predicate<T> { public boolean contains(T item) { checkNotNull(item, "item cannot be null"); if (low == null) { return item.compareTo(high) <= 0; } if (high == null) { return item.compareTo(low) >= 0; } return item.compareTo(high) <= 0 && item.compareTo(low) >= 0; } RangeBand(T low, T high); boolean contains(T item); @Override boolean test(T t); T getLow(); T getHigh(); @Override boolean equals(Object o); @Override int hashCode(); @Override String toString();  }
@Test public void containsReturnsTrueIfWithinRange() { assertTrue(range10_20.contains(15)); }
@Test public void containsReturnsTrueIfOnUpperBound() { assertTrue(range10_20.contains(20)); }
@Test public void containsReturnsTrueIfOnLowerBound() { assertTrue(range10_20.contains(10)); }
@Test public void containsReturnsFalseIfBelowLowBound() { assertFalse(range10_20.contains(9)); }
@Test public void containsReturnsFalseIfAboveHighBound() { assertFalse(range10_20.contains(21)); }
@Test public void ifNoLowerBoundSpecifiedAssumeNoLowerLimit() { RangeBand<Integer> noLowBound = new RangeBand<>(null, 10); assertTrue(noLowBound.contains(-10)); assertTrue(noLowBound.contains(10)); assertFalse(noLowBound.contains(11)); }
@Test public void ifNoHighBoundSpecifiedAssumeNoUpperLimit() { RangeBand<Integer> noHighBound = new RangeBand<>(0, null); assertTrue(noHighBound.contains(100000)); assertTrue(noHighBound.contains(0)); assertFalse(noHighBound.contains(-1)); }