@Test void forOptionalFieldWithUnprefixedGetterThatIsNull() { Function<GetterTestClass,Optional<Integer>> fieldWithNoGetter = Getter.forField(GetterTestClass.class, Integer.class, getDeclaredField(GetterTestClass.class, "optionalFieldWithUnprefixedGetter")); GetterTestClass mock = mock(GetterTestClass.class); when(mock.optionalFieldWithUnprefixedGetter()).thenReturn(null); Optional<Integer> result = fieldWithNoGetter.apply(mock); assertThat(result, is(Optional.empty())); verify(mock).optionalFieldWithUnprefixedGetter(); verifyNoMoreInteractions(mock); }
@NotNull public static <T, V> Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field) { return forField(TypeToken.of(targetClass), argType, field); }
Getter extends UtilityClass { @NotNull public static <T, V> Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field) { return forField(TypeToken.of(targetClass), argType, field); } }
Getter extends UtilityClass { @NotNull public static <T, V> Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field) { return forField(TypeToken.of(targetClass), argType, field); }  }
Getter extends UtilityClass { @NotNull public static <T, V> Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field) { return forField(TypeToken.of(targetClass), argType, field); }  @NotNull static Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field); @NotNull static FunctionOptional1<T,V> forField(TypeToken<T> targetType, Class<V> argType, Field field); static boolean isGetter(Method method, Field forField); static Stream<String> possibleFieldNames(String name); }
Getter extends UtilityClass { @NotNull public static <T, V> Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field) { return forField(TypeToken.of(targetClass), argType, field); }  @NotNull static Function<T,Optional<V>> forField(Class<T> targetClass, Class<V> argType, Field field); @NotNull static FunctionOptional1<T,V> forField(TypeToken<T> targetType, Class<V> argType, Field field); static boolean isGetter(Method method, Field forField); static Stream<String> possibleFieldNames(String name);  }