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();
  }
Exemple #2
0
  TestedField(
      @Nonnull InjectionState injectionState, @Nonnull Field field, @Nonnull Tested metadata) {
    this.injectionState = injectionState;
    testedField = field;
    this.metadata = metadata;
    fullInjection = metadata.fullyInitialized() ? new FullInjection(injectionState) : null;

    Class<?> fieldType = field.getType();

    if (fieldType.isInterface()) {
      testedObjectCreation = null;
    } else {
      testedObjectCreation = new TestedObjectCreation(injectionState, fullInjection, field);
      injectionState.lifecycleMethods.findLifecycleMethods(fieldType);
    }
  }
  private Method findPublicVoidMethod(Class<?> aClass, String methodName) {
    for (Method method : aClass.getDeclaredMethods()) {
      if (isPublic(method.getModifiers())
          && method.getReturnType() == void.class
          && methodName.equals(method.getName())) {
        return method;
      }
    }

    return null;
  }