コード例 #1
0
 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);
     }
   }
 }
コード例 #2
0
  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();
  }
コード例 #3
0
  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;
      }
    }
  }