class ErrorCollector {

  public static final String FIELD_NAME = "errorCollector";

  private static final String INTERCEPT_METHOD_NAME = "intercept";
  private static final String CLASS_NAME = ErrorCollector.class.getName();

  private AssertionErrorCollector assertionErrorCollector;

  ErrorCollector(AssertionErrorCollector collector) {
    this.assertionErrorCollector = collector;
  }

  /**
   * @param errorCollector the {@link ErrorCollector} to gather assertions error for the assertion instance
   * @param assertion The instance of the method, the this reference.
   * @param proxy A proxy to invoke the original method.
   * @param method A reference to the original method.
   * @param stub A default value for the return type. null for reference type and 0 for the corresponding primitive types.
   * @return the assertion result
   * @throws Exception may be thrown from the assertion proxy call
   */
  @RuntimeType
  public static Object intercept(@FieldValue(FIELD_NAME) ErrorCollector errorCollector,
                                 @This Object assertion,
                                 @SuperCall Callable<?> proxy,
                                 @SuperMethod(nullIfImpossible = true) Method method,
                                 @StubValue Object stub) throws Exception {<FILL_FUNCTION_BODY>}

  private void addError(AssertionError error) {
    assertionErrorCollector.collectAssertionError(error);
  }

  private void succeeded() {
    assertionErrorCollector.succeeded();
  }

  private static boolean isNestedErrorCollectorProxyCall() {
    return countErrorCollectorProxyCalls() > 1;
  }

  private static long countErrorCollectorProxyCalls() {
    return Arrays.stream(Thread.currentThread().getStackTrace())
                 .filter(stackTraceElement -> CLASS_NAME.equals(stackTraceElement.getClassName())
                                              && stackTraceElement.getMethodName().startsWith(INTERCEPT_METHOD_NAME))
                 .count();
  }
}

    try {
      Object result = proxy.call();
      errorCollector.succeeded();
      return result;
    } catch (AssertionError assertionError) {
      if (isNestedErrorCollectorProxyCall()) {
        // let the most outer call handle the assertion error
        throw assertionError;
      }
      errorCollector.addError(assertionError);
    }
    if (method != null && !method.getReturnType().isInstance(assertion)) {
      // In case the object is not an instance of the return type, just default value for the return type:
      // null for reference type and 0 for the corresponding primitive types.
      return stub;
    }
    return assertion;
  
<no_super_class>