Field { public boolean isNullable() { return annotations.contains(Annotation.NULLABLE) || !(isNonnull() || isNonnegative()); } Field(@Nonnull final String name, @Nonnull final Type type, @Nonnull final Visibility visibility,
			@Nonnull final Final finalModifier, @Nonnull final Static staticModifier, @Nonnull final List<Annotation> annotations,
			@Nonnull final String value, @Nonnull final AccessorPrefix accessorPrefix); @Override boolean equals(final Object obj); String getAccessorMethodName(); @Nonnull AccessorPrefix getAccessorPrefix(); @Nonnull List<Annotation> getAnnotations(); @Nonnull Final getFinal(); String getMutatorMethodName(); @Nonnull String getName(); @Nonnull Static getStatic(); @Nonnull Type getType(); @Nonnull String getValue(); @Nonnull Visibility getVisibility(); @Override int hashCode(); boolean isNonnegative(); boolean isNonnull(); boolean isNullable(); @Override String toString(); static final String WITHOUT_VALUE; }
@Test(expected = IllegalEmptyArgumentException.class) public void construct_name_isEmpty() { final String name = ""; final Type type = Type.of(String.class); final Visibility visibility = Visibility.PUBLIC; final Final finalModifier = Final.UNDEFINED; final Static staticModifier = Static.UNDEFINED; final List<Annotation> annotations = ImmutableList.of(Annotation.of(Nullable.class)); final String value = ""; final AccessorPrefix accessorPrefix = AccessorPrefix.GET; new Field(name, type, visibility, finalModifier, staticModifier, annotations, value, accessorPrefix).isNullable(); }
@Test(expected = IllegalNullArgumentException.class) public void construct_name_isNull() { final String name = null; final Type type = Type.of(String.class); final Visibility visibility = Visibility.PUBLIC; final Final finalModifier = Final.UNDEFINED; final Static staticModifier = Static.UNDEFINED; final List<Annotation> annotations = ImmutableList.of(Annotation.of(Nullable.class)); final String value = ""; final AccessorPrefix accessorPrefix = AccessorPrefix.GET; new Field(name, type, visibility, finalModifier, staticModifier, annotations, value, accessorPrefix).isNullable(); }
@Test public void isNullable() { final String name = "field"; final Type type = Type.of(String.class); final Visibility visibility = Visibility.PUBLIC; final Final finalMod = Final.UNDEFINED; final Static staticMod = Static.UNDEFINED; final String value = ""; final AccessorPrefix prefix = AccessorPrefix.GET; final List<Annotation> annotationsEmpty = ImmutableList.of(); final List<Annotation> annotationsWithNullable = ImmutableList.of(Annotation.of(Nullable.class)); final List<Annotation> annotationsWithNonnegative = ImmutableList.of(Annotation.of(Nonnegative.class)); final List<Annotation> annotationsWithNonnull = ImmutableList.of(Annotation.of(Nonnull.class)); assertTrue(new Field(name, type, visibility, finalMod, staticMod, annotationsEmpty, value, prefix).isNullable()); assertTrue(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNullable, value, prefix).isNullable()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNonnegative, value, prefix).isNullable()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNonnull, value, prefix).isNullable()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsEmpty, value, prefix).isNonnegative()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNullable, value, prefix).isNonnegative()); assertTrue(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNonnegative, value, prefix).isNonnegative()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNonnull, value, prefix).isNonnegative()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsEmpty, value, prefix).isNonnull()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNullable, value, prefix).isNonnull()); assertFalse(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNonnegative, value, prefix).isNonnull()); assertTrue(new Field(name, type, visibility, finalMod, staticMod, annotationsWithNonnull, value, prefix).isNonnull()); }