FragmentAnnotations { public static void iterateFields(@NonNull final FieldProcessor processor, @NonNull final Class<?> ofClass, @Nullable final Class<?> maxSuperClass) { final Field[] fields = ofClass.getDeclaredFields(); if (fields.length > 0) { for (final Field field : fields) { processor.onProcessField(field, field.getName()); } } if (maxSuperClass != null) { final Class<?> parent = ofClass.getSuperclass(); if (parent != null && !parent.equals(maxSuperClass)) { iterateFields(processor, parent, maxSuperClass); } } } private  FragmentAnnotations(); static void setEnabled(final boolean enabled); static boolean isEnabled(); static void checkIfEnabledOrThrow(); @Nullable static A obtainAnnotationFrom(
			@NonNull final Class<A> classOfAnnotation,
			@NonNull final Class<?> fromClass,
			@Nullable final Class<?> maxSuperClass
	); static void iterateFields(@NonNull final FieldProcessor processor, @NonNull final Class<?> ofClass, @Nullable final Class<?> maxSuperClass);  }
@Test public void testIterateFields() { final FragmentAnnotations.FieldProcessor mockProcessor = mock(FragmentAnnotations.FieldProcessor.class); FragmentAnnotations.iterateFields(mockProcessor, AnnotatedComponent.class, null); final Field[] fields = AnnotatedComponent.class.getDeclaredFields(); for (final Field field : fields) { verify(mockProcessor).onProcessField(field, field.getName()); } verifyNoMoreInteractions(mockProcessor); }
@Test public void testIterateFieldsWithMaxSuperClass() { final FragmentAnnotations.FieldProcessor mockProcessor = mock(FragmentAnnotations.FieldProcessor.class); FragmentAnnotations.iterateFields(mockProcessor, ChildAnnotatedComponent.class, BaseComponent.class); for (final Field field : AnnotatedComponent.class.getDeclaredFields()) { verify(mockProcessor).onProcessField(field, field.getName()); } for (final Field field : ChildAnnotatedComponent.class.getDeclaredFields()) { verify(mockProcessor).onProcessField(field, field.getName()); } verifyNoMoreInteractions(mockProcessor); }
@Test public void testIterateFieldsWithMaxSuperClassForClassWithoutSuper() { final FragmentAnnotations.FieldProcessor mockProcessor = mock(FragmentAnnotations.FieldProcessor.class); FragmentAnnotations.iterateFields(mockProcessor, Object.class, BaseComponent.class); }
@Ignore("Fails when running coverage report.") @Test public void testIterateFieldsOfComponentWithoutFields() { final FragmentAnnotations.FieldProcessor mockProcessor = mock(FragmentAnnotations.FieldProcessor.class); FragmentAnnotations.iterateFields(mockProcessor, Component.class, null); verifyZeroInteractions(mockProcessor); }