NumberPredicate implements Predicate { @Override public boolean evaluate(Object candidate) { boolean match = candidate instanceof Number; if (match) { BigDecimal dec1 = new BigDecimal(candidate.toString()); BigDecimal dec2 = new BigDecimal(element.toString()); match = dec1.equals(dec2); } return match; } NumberPredicate(Number element); @Override boolean evaluate(Object candidate);  }
@Test public void shouldReturnTrueIfCandidateIsEqual() throws Exception { assertTrue(predicate.evaluate(100L)); assertTrue(predicate.evaluate((byte) 100)); assertTrue(predicate.evaluate(new BigDecimal("100"))); }
@Test public void shouldReturnFalseIfCandidateIsDifferentOrIsNotNumber() throws Exception { assertFalse(predicate.evaluate(new Object())); assertFalse(predicate.evaluate(200)); }