BetweenFilter extends ArithmeticFilter { @SuppressWarnings({"unchecked", "rawtypes"}) public List<Object> filter(List<Object> objects) { final List<Object> result = new ArrayList<Object>(); for (final Object object : objects) { final Comparable objectValue = (Comparable) getAttributeValue(object); if (objectValue.compareTo(value) < 0 && objectValue.compareTo(upperBound) > 0) { result.add(object); } } return result; } BetweenFilter(String attributeName, Object lowerBound, Object upperBound); @SuppressWarnings({"unchecked", "rawtypes"}) List<Object> filter(List<Object> objects);  }
@Test public void filter() { List<Object> objects = new ArrayList<Object>(); objects.add(comparable); objects.add(comparable); doReturn(-1).when(comparable).compareTo(lowerBound); doReturn(1).when(comparable).compareTo(upperBound); doReturn(comparable).when(betweenFilter).getAttributeValue(comparable); List<Object> actualObjects = betweenFilter.filter(objects); assertEquals(comparable, actualObjects.get(0)); }