private void findTestedAndInjectableFields(@NotNull Field[] fieldsDeclaredInTestClass) { for (Field field : fieldsDeclaredInTestClass) { if (field.isAnnotationPresent(Injectable.class)) { MockedType mockedType = new MockedType(field); injectableFields.add(mockedType); } else { addAsTestedFieldIfApplicable(field); } } }
private boolean findAllTestedAndInjectableFieldsInTestClassHierarchy( @NotNull Class<?> testClass) { Class<?> classWithFields = testClass; do { Field[] fields = classWithFields.getDeclaredFields(); findTestedAndInjectableFields(fields); classWithFields = classWithFields.getSuperclass(); } while (classWithFields.getClassLoader() != null); return !testedFields.isEmpty(); }
private void addAsTestedFieldIfApplicable(@NotNull Field fieldFromTestClass) { for (Annotation fieldAnnotation : fieldFromTestClass.getDeclaredAnnotations()) { Tested testedMetadata; if (fieldAnnotation instanceof Tested) { testedMetadata = (Tested) fieldAnnotation; } else { testedMetadata = fieldAnnotation.annotationType().getAnnotation(Tested.class); } if (testedMetadata != null) { TestedField testedField = new TestedField(injectionState, fieldFromTestClass, testedMetadata); testedFields.add(testedField); break; } } }