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()));
}
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));
}
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());
}
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());
}
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()");
}
Aggregations