Search in sources :

Example 1 with Criteria

use of org.immutables.criteria.Criteria in project immutables by immutables.

the class JavaBeanModelTest method nullableByDefault.

/**
 * JavaBean(s) have nullable types by default (except for primitives / optionals / iterables)
 */
@Test
public void nullableByDefault() {
    ValueType valueType = rule.value(Model1.class);
    Function<String, ValueAttribute> findFn = name -> valueType.attributes.stream().filter(a -> a.name().equals(name)).findAny().get();
    // TODO: generate optional version of criteria ?
    check(findFn.apply("dep").isNullable());
    // boxed versions are nullable
    check(findFn.apply("boxedInteger").isNullable());
    // base is string (and can be null)
    check(findFn.apply("base").isNullable());
    // exclude nullable property from primitives / collections and optionals
    // foo is int (primitive)
    check(!findFn.apply("foo").isNullable());
    // set is boolean
    check(!findFn.apply("set").isNullable());
    // deps is collection
    check(!findFn.apply("deps").isNullable());
}
Also used : Criteria(org.immutables.criteria.Criteria) List(java.util.List) Rule(org.junit.Rule) Checkers.check(org.immutables.check.Checkers.check) Date(java.util.Date) Test(org.junit.Test) ProcessorRule(org.immutables.value.processor.meta.ProcessorRule) Function(java.util.function.Function) Collectors(java.util.stream.Collectors) Nullable(javax.annotation.Nullable) ValueAttribute(org.immutables.value.processor.meta.ValueAttribute) ValueType(org.immutables.value.processor.meta.ValueType) ValueType(org.immutables.value.processor.meta.ValueType) ValueAttribute(org.immutables.value.processor.meta.ValueAttribute) Test(org.junit.Test)

Aggregations

Date (java.util.Date)1 List (java.util.List)1 Function (java.util.function.Function)1 Collectors (java.util.stream.Collectors)1 Nullable (javax.annotation.Nullable)1 Checkers.check (org.immutables.check.Checkers.check)1 Criteria (org.immutables.criteria.Criteria)1 ProcessorRule (org.immutables.value.processor.meta.ProcessorRule)1 ValueAttribute (org.immutables.value.processor.meta.ValueAttribute)1 ValueType (org.immutables.value.processor.meta.ValueType)1 Rule (org.junit.Rule)1 Test (org.junit.Test)1