SimpleStringPredicate extends PropertyPredicate<T> { @Override public boolean test(T t) { if (t == null) { return false; } Object v = ClassUtils.getFieldValue(t, getProperty()); if (v == null || !v.getClass().isAssignableFrom(String.class)) { return false; } String value = caseSensitive ? v.toString() : v.toString().toLowerCase(); String match = caseSensitive ? getValue().toString() : getValue().toString().toLowerCase(); if (onlyMatchPrefix) { return value.startsWith(match); } else { return value.contains(match); } } SimpleStringPredicate(String property, String value, boolean onlyMatchPrefix, boolean caseSensitive); @Override boolean test(T t); boolean isOnlyMatchPrefix(); boolean isCaseSensitive();  }
@Test public void testPrefixCaseSensitive() { SimpleStringPredicate<TestEntity> p1 = new SimpleStringPredicate<>("name", "evi", true, true); assertFalse(p1.test(null)); TestEntity t1 = new TestEntity(); t1.setName("Kevin"); assertFalse(p1.test(t1)); t1.setName("evin"); assertTrue(p1.test(t1)); t1.setName("Evin"); assertFalse(p1.test(t1)); }
@Test public void testPrefixCaseInsensitive() { SimpleStringPredicate<TestEntity> p1 = new SimpleStringPredicate<>("name", "evi", true, false); assertFalse(p1.test(null)); TestEntity t1 = new TestEntity(); t1.setName("Kevin"); assertFalse(p1.test(t1)); t1.setName("evin"); assertTrue(p1.test(t1)); t1.setName("Evin"); assertTrue(p1.test(t1)); }
@Test public void testAnyWhereCaseSensitive() { SimpleStringPredicate<TestEntity> p1 = new SimpleStringPredicate<>("name", "evi", false, true); assertFalse(p1.test(null)); TestEntity t1 = new TestEntity(); t1.setName("Kevin"); assertTrue(p1.test(t1)); t1.setName("evin"); assertTrue(p1.test(t1)); t1.setName("Evin"); assertFalse(p1.test(t1)); }
@Test public void testAnyWhereCaseInsensitive() { SimpleStringPredicate<TestEntity> p1 = new SimpleStringPredicate<>("name", "evi", false, false); assertFalse(p1.test(null)); TestEntity t1 = new TestEntity(); t1.setName("Kevin"); assertTrue(p1.test(t1)); t1.setName("evin"); assertTrue(p1.test(t1)); t1.setName("Evin"); assertTrue(p1.test(t1)); }