Search in sources :

Example 1 with ValueAttribute

use of org.immutables.value.processor.meta.ValueAttribute in project immutables by immutables.

the class CriteriaModelProcessorTest method assertAttribute.

private void assertAttribute(String name, String expected) {
    ValueAttribute attribute = findAttribute(name);
    final Type element = attribute.criteria().matcher().matcherType();
    final UnaryOperator<String> stripFn = str -> str.replaceAll("\\s+", "");
    assertEquals(String.format("for attribute %s", name), stripFn.apply(expected), stripFn.apply(element.toString()));
}
Also used : Checkers(org.immutables.check.Checkers) TimeZone(java.util.TimeZone) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test) UnaryOperator(java.util.function.UnaryOperator) StringChecker(org.immutables.check.StringChecker) ProcessorRule(org.immutables.value.processor.meta.ProcessorRule) OptionalInt(java.util.OptionalInt) ValueAttribute(org.immutables.value.processor.meta.ValueAttribute) ValueType(org.immutables.value.processor.meta.ValueType) Type(org.immutables.value.processor.encode.Type) Objects(java.util.Objects) BigDecimal(java.math.BigDecimal) OptionalLong(java.util.OptionalLong) Criteria(org.immutables.criteria.Criteria) List(java.util.List) Rule(org.junit.Rule) Optional(java.util.Optional) BigInteger(java.math.BigInteger) NoSuchElementException(java.util.NoSuchElementException) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) Assert.assertEquals(org.junit.Assert.assertEquals) ValueType(org.immutables.value.processor.meta.ValueType) Type(org.immutables.value.processor.encode.Type) ValueAttribute(org.immutables.value.processor.meta.ValueAttribute)

Example 2 with ValueAttribute

use of org.immutables.value.processor.meta.ValueAttribute in project immutables by immutables.

the class CriteriaModelProcessorTest method checkCreator.

private StringChecker checkCreator(String name) {
    ValueAttribute attribute = findAttribute(name);
    final String creator = attribute.criteria().matcher().creator();
    final UnaryOperator<String> stripFn = str -> str.replaceAll("\\s+", "");
    return Checkers.check(stripFn.apply(creator));
}
Also used : Checkers(org.immutables.check.Checkers) TimeZone(java.util.TimeZone) OptionalDouble(java.util.OptionalDouble) Test(org.junit.Test) UnaryOperator(java.util.function.UnaryOperator) StringChecker(org.immutables.check.StringChecker) ProcessorRule(org.immutables.value.processor.meta.ProcessorRule) OptionalInt(java.util.OptionalInt) ValueAttribute(org.immutables.value.processor.meta.ValueAttribute) ValueType(org.immutables.value.processor.meta.ValueType) Type(org.immutables.value.processor.encode.Type) Objects(java.util.Objects) BigDecimal(java.math.BigDecimal) OptionalLong(java.util.OptionalLong) Criteria(org.immutables.criteria.Criteria) List(java.util.List) Rule(org.junit.Rule) Optional(java.util.Optional) BigInteger(java.math.BigInteger) NoSuchElementException(java.util.NoSuchElementException) Method(java.lang.reflect.Method) Nullable(javax.annotation.Nullable) Assert.assertEquals(org.junit.Assert.assertEquals) ValueAttribute(org.immutables.value.processor.meta.ValueAttribute)

Example 3 with ValueAttribute

use of org.immutables.value.processor.meta.ValueAttribute 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)

Example 4 with ValueAttribute

use of org.immutables.value.processor.meta.ValueAttribute in project immutables by immutables.

the class JavaBeanModelTest method nullable.

@Test
public void nullable() {
    ValueType valueType = rule.value(Model1.class);
    Function<String, ValueAttribute> findFn = name -> valueType.attributes.stream().filter(a -> a.name().equals(name)).findAny().get();
    check(findFn.apply("nullableDep").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)

Example 5 with ValueAttribute

use of org.immutables.value.processor.meta.ValueAttribute in project immutables by immutables.

the class JavaBeanModelTest method attributes.

@Test
public void attributes() {
    ValueType valueType = rule.value(Model1.class);
    Function<String, ValueAttribute> findFn = name -> valueType.attributes.stream().filter(a -> a.name().equals(name)).findAny().get();
    check(findFn.apply("foo").getType()).is("int");
    ValueAttribute dep = findFn.apply("dep");
    check(dep.hasCriteria());
    check(dep.criteria().matcher().creator()).contains("DepCriteria.creator()");
    check(dep.criteria().matcher().creator()).not().contains("DepCriteriaTemplate.creator()");
}
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

List (java.util.List)5 Nullable (javax.annotation.Nullable)5 Criteria (org.immutables.criteria.Criteria)5 ProcessorRule (org.immutables.value.processor.meta.ProcessorRule)5 ValueAttribute (org.immutables.value.processor.meta.ValueAttribute)5 ValueType (org.immutables.value.processor.meta.ValueType)5 Rule (org.junit.Rule)5 Test (org.junit.Test)5 Date (java.util.Date)3 Function (java.util.function.Function)3 Collectors (java.util.stream.Collectors)3 Checkers.check (org.immutables.check.Checkers.check)3 Method (java.lang.reflect.Method)2 BigDecimal (java.math.BigDecimal)2 BigInteger (java.math.BigInteger)2 NoSuchElementException (java.util.NoSuchElementException)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 OptionalDouble (java.util.OptionalDouble)2 OptionalInt (java.util.OptionalInt)2