Search in sources :

Example 6 with ImmutablePerson

use of org.immutables.criteria.personmodel.ImmutablePerson in project immutables by immutables.

the class ExpressionInterpreterTest method reflection.

@Test
public void reflection() {
    final PersonCriteria crit = PersonCriteria.person;
    final ImmutablePerson person = example.withFullName("John");
    check(!evaluate(crit.age.is(11), person));
    check(evaluate(crit.age.isNot(11), person));
    check(evaluate(crit.age.is(11), person.withAge(11)));
    check(evaluate(crit.age.is(22).fullName.is("John"), person));
    check(!evaluate(crit.age.is(22).fullName.is("Mary"), person));
    check(!evaluate(crit.age.in(1, 2, 3), person));
    check(evaluate(crit.age.notIn(1, 2, 3), person));
    check(evaluate(crit.age.in(22, 23, 24), person));
    check(!evaluate(crit.age.notIn(22, 23, 24), person));
    check(!evaluate(crit.isActive.isTrue(), person));
    check(evaluate(crit.isActive.isFalse(), person));
    check(evaluate(crit.isActive.isTrue().or().isActive.isFalse(), person));
    check(evaluate(crit.isActive.isFalse().or().isActive.isTrue().nickName.isAbsent(), person));
    check(!evaluate(crit.age.atLeast(23), person));
    check(evaluate(crit.age.atMost(22), person));
    check(!evaluate(crit.age.lessThan(22), person));
    check(!evaluate(crit.age.greaterThan(22), person));
    check(!evaluate(crit.age.atLeast(23), person));
    // optionals
    check(evaluate(crit.nickName.isPresent(), person));
    check(!evaluate(crit.nickName.isAbsent(), person));
    check(!evaluate(crit.nickName.isPresent(), person.withNickName(Optional.empty())));
    check(evaluate(crit.nickName.isAbsent(), person.withNickName(Optional.empty())));
    // == value().$expr
    check(!evaluate(crit.nickName.isNot("Smith"), person.withNickName("Smith")));
    check(evaluate(crit.nickName.in("Smith", "Nobody"), person.withNickName("Smith")));
    check(!evaluate(crit.nickName.in("Nobody", "Sky"), person.withNickName("Smith")));
    check(evaluate(crit.nickName.notIn("Nobody", "Sky"), person.withNickName("Smith")));
    // == value($expr)
    check(evaluate(crit.nickName.with(v -> v.is("Smith")), person.withNickName("Smith")));
    check(!evaluate(crit.nickName.with(v -> v.isNot("Smith")), person.withNickName("Smith")));
    check(evaluate(crit.nickName.with(v -> v.in("Smith", "Nobody")), person.withNickName("Smith")));
    check(!evaluate(crit.nickName.with(v -> v.in("Nobody", "Sky")), person.withNickName("Smith")));
    check(evaluate(crit.nickName.with(v -> v.notIn("Nobody", "Sky")), person.withNickName("Smith")));
}
Also used : Test(org.junit.jupiter.api.Test) ImmutableAddress(org.immutables.criteria.personmodel.ImmutableAddress) Person(org.immutables.criteria.personmodel.Person) Checkers.check(org.immutables.check.Checkers.check) Address(org.immutables.criteria.personmodel.Address) LocalDate(java.time.LocalDate) PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) Criterias(org.immutables.criteria.Criterias) Optional(java.util.Optional) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) PersonCriteria(org.immutables.criteria.personmodel.PersonCriteria) ImmutablePerson(org.immutables.criteria.personmodel.ImmutablePerson) Test(org.junit.jupiter.api.Test)

Aggregations

ImmutablePerson (org.immutables.criteria.personmodel.ImmutablePerson)6 Test (org.junit.jupiter.api.Test)5 Person (org.immutables.criteria.personmodel.Person)2 PersonCriteria (org.immutables.criteria.personmodel.PersonCriteria)2 PersonGenerator (org.immutables.criteria.personmodel.PersonGenerator)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)1 Member (java.lang.reflect.Member)1 LocalDate (java.time.LocalDate)1 Optional (java.util.Optional)1 Checkers.check (org.immutables.check.Checkers.check)1 Criterias (org.immutables.criteria.Criterias)1 Address (org.immutables.criteria.personmodel.Address)1 ImmutableAddress (org.immutables.criteria.personmodel.ImmutableAddress)1 ParameterizedTest (org.junit.jupiter.params.ParameterizedTest)1 MethodSource (org.junit.jupiter.params.provider.MethodSource)1