ElementFilter extends TupleAdaptedPredicateComposite<String> { public boolean test(final Element element) { elementTuple.setElement(element); return test(elementTuple); }  boolean test(final Element element); ValidationResult testWithValidationResult(final Element element); @Override List<TupleAdaptedPredicate<String, ?>> getComponents(); void lock(); @Override boolean equals(final Object obj); @Override int hashCode(); @Override String toString();  }
@Test public void shouldTestElementOnInlinePredicate() { final ElementFilter filter = new ElementFilter.Builder() .select(TestPropertyNames.PROP_1) .execute("value"::equals) .build(); final Entity element1 = makeEntity("value"); final Entity element2 = makeEntity(1); final boolean result1 = filter.test(element1); final boolean result2 = filter.test(element2); assertTrue(result1); assertFalse(result2); }
@Test public void shouldTestElementOnLambdaPredicate() { final Predicate<Object> predicate = p -> null == p || String.class.isAssignableFrom(p.getClass()); final ElementFilter filter = new ElementFilter.Builder() .select(TestPropertyNames.PROP_1) .execute(predicate) .build(); final Entity element1 = makeEntity("value"); final Entity element2 = makeEntity(1); final boolean result1 = filter.test(element1); final boolean result2 = filter.test(element2); assertTrue(result1); assertFalse(result2); }
@Test public void shouldTestElementOnComplexLambdaPredicate() { final Predicate<Object> predicate1 = p -> Integer.class.isAssignableFrom(p.getClass()); final Predicate<Object> predicate2 = "value"::equals; final ElementFilter filter = new ElementFilter.Builder() .select(TestPropertyNames.PROP_1) .execute(predicate1.negate().and(predicate2)) .build(); final Entity element1 = makeEntity("value"); final Entity element2 = makeEntity(1); final boolean result1 = filter.test(element1); final boolean result2 = filter.test(element2); assertTrue(result1); assertFalse(result2); }
@Test public void shouldExecuteOrPredicates() { final ElementFilter filter = new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new Or.Builder<>() .select(0) .execute(new IsMoreThan(2)) .select(1) .execute(new IsEqual("some value")) .build()) .build(); final Entity element1 = makeEntity(3, "some value"); final Entity element2 = makeEntity(1, "some value"); final Entity element3 = makeEntity(3, "some invalid value"); final Entity element4 = makeEntity(1, "some invalid value"); final boolean result1 = filter.test(element1); final boolean result2 = filter.test(element2); final boolean result3 = filter.test(element3); final boolean result4 = filter.test(element4); assertTrue(result1); assertTrue(result2); assertTrue(result3); assertFalse(result4); }
@Test public void shouldExecuteNotPredicates() { final ElementFilter filter = new ElementFilter.Builder() .select(TestPropertyNames.PROP_1, TestPropertyNames.PROP_2) .execute(new Not<>(new Or.Builder<>() .select(0) .execute(new IsMoreThan(2)) .select(1) .execute(new IsEqual("some value")) .build())) .build(); final Entity element1 = makeEntity(3, "some value"); final Entity element2 = makeEntity(1, "some value"); final Entity element3 = makeEntity(3, "some invalid value"); final Entity element4 = makeEntity(1, "some invalid value"); final boolean result1 = filter.test(element1); final boolean result2 = filter.test(element2); final boolean result3 = filter.test(element3); final boolean result4 = filter.test(element4); assertFalse(result1); assertFalse(result2); assertFalse(result3); assertTrue(result4); }