use of com.yahoo.elide.core.filter.predicates.PrefixPredicate in project elide by yahoo.
the class InMemoryFilterExecutorTest method prefixAndPostfixAndInfixPredicateTest.
@Test
public void prefixAndPostfixAndInfixPredicateTest() throws Exception {
author = new Author();
author.setId(1L);
author.setName("AuthorForTest");
// When prefix, infix, postfix are correctly matched
expression = new PrefixPredicate(authorNameElement, "Author");
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new InfixPredicate(authorNameElement, "For");
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new PostfixPredicate(authorNameElement, "Test");
fn = expression.accept(visitor);
assertTrue(fn.test(author));
// When prefix, infix, postfix are correctly matched if case-insensitive
expression = new PrefixPredicate(authorNameElement, "author");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new InfixPredicate(authorNameElement, "for");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new PostfixPredicate(authorNameElement, "test");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
// When prefix, infix, postfix are correctly matched if case-insensitive
expression = new PrefixInsensitivePredicate(authorNameElement, "author");
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new InfixInsensitivePredicate(authorNameElement, "for");
fn = expression.accept(visitor);
assertTrue(fn.test(author));
expression = new PostfixInsensitivePredicate(authorNameElement, "test");
fn = expression.accept(visitor);
assertTrue(fn.test(author));
// When prefix, infix, postfix are not matched
expression = new PrefixPredicate(authorNameElement, "error");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new InfixPredicate(authorNameElement, "error");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new PostfixPredicate(authorNameElement, "error");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
// When values is null
author.setName(null);
expression = new PrefixPredicate(authorNameElement, "Author");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new InfixPredicate(authorNameElement, "For");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
expression = new PostfixPredicate(authorNameElement, "Test");
fn = expression.accept(visitor);
assertFalse(fn.test(author));
}
Aggregations