OpenFeign/feign · error · VerificationAssertionError

Do not wanted: ' ' but was invoked!

Error message

Do not wanted: '%s' but was invoked!

What it means

verifyNever(HttpMethod, String) builds a RequestKey from method and url and checks the recorded requests map. If any request with that exact method and url was invoked, a VerificationAssertionError is thrown stating the request should not have been invoked. It is the negative-expectation counterpart of verifyTimes.

Solutions

  1. Remove or gate the unexpected call in the code under test
  2. Update the test expectation if the endpoint legitimately should be called (switch to verifyTimes/verifyOne)
  3. Call resetRequests() in setup/teardown so previous invocations do not leak in

Example fix

// before
mockClient.verifyNever(HttpMethod.DELETE, "/users/1"); // delete was invoked
// after
mockClient.verifyTimes(HttpMethod.DELETE, "/users/1", 1); // reflect actual behavior
Defensive patterns

Strategy: try-catch

Try / catch

try {
  mockClient.verifyNever(HttpMethod.DELETE, "/users/1");
} catch (VerificationAssertionError e) {
  throw new AssertionError("Unexpected invocation: " + e.getMessage(), e);
}

Prevention

When it happens

Trigger: mockClient.verifyNever(method, url) (directly, or via verifyTimes(method, url, 0)) where requests.containsKey(builtKey) is true.

Common situations: Code under test unexpectedly calls the endpoint (fallback path taken, feature flag on); assertion left in place after behavior changed; stale requests from a previous test without resetRequests().

Understand the failure class

Background: "invalid response format", "malformed payload", "missing data field": when an API returns 200 but the response shape is wrong — this error's family across 23 libraries.

Related errors


AI-assisted analysis of OpenFeign/feign@e2a1e27560 (2026-09-10). Data as JSON: /api/errors/b832ec5b1f5d7201. Report an issue: GitHub.

Appendix: source

Thrown at mock/src/main/java/feign/mock/MockClient.java:304

    }
    if (result == null) {
      throw new VerificationAssertionError(
          "Wanted: '%s' but never invoked! Got: %s", requestKey, requests.keySet());
    }

    if (result.size() != times) {
      throw new VerificationAssertionError(
          "Wanted: '%s' to be invoked: '%s' times but got: '%s'!",
          requestKey, times, result.size());
    }

    return result;
  }

  public void verifyNever(HttpMethod method, String url) {
    RequestKey requestKey = RequestKey.builder(method, url).build();
    if (requests.containsKey(requestKey)) {
      throw new VerificationAssertionError("Do not wanted: '%s' but was invoked!", requestKey);
    }
  }

  public void verifyNever(RequestKey requestKey) {
    for (RequestKey recorderRequestKey : requests.keySet()) {
      if (recorderRequestKey.equalsExtended(requestKey)) {
        throw new VerificationAssertionError("Do not wanted: '%s' but was invoked!", requestKey);
      }
    }
  }

  /**
   * To be called in an @After method:
   *
   * <pre>
   * &#64;After
   * public void tearDown() {
   *   mockClient.verifyStatus();

View on GitHub (pinned to e2a1e27560)