LikePredicate 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 pattern = getValue().toString().replace("%", ".*"); if (isCaseSensitive()) { return ((String) v).matches(pattern); } return ((String) v).toUpperCase().matches(pattern.toUpperCase()); } LikePredicate(String property, String value, boolean caseSensitive); @Override boolean test(T t); boolean isCaseSensitive();  }
@Test public void testCaseInsensitive() { LikePredicate<TestEntity> like = new LikePredicate<>("name", "%evi%", false); assertFalse(like.test(null)); TestEntity t1 = new TestEntity(); t1.setName("Kevin"); assertTrue(like.test(t1)); t1.setName("KEVIN"); assertTrue(like.test(t1)); t1.setName("Kevon"); assertFalse(like.test(t1)); }
@Test public void testCaseSensitive() { LikePredicate<TestEntity> like = new LikePredicate<>("name", "%evi%", true); assertFalse(like.test(null)); TestEntity t1 = new TestEntity(); t1.setName("Kevin"); assertTrue(like.test(t1)); t1.setName("KEVIN"); assertFalse(like.test(t1)); t1.setName("Kevon"); assertFalse(like.test(t1)); }