{"record":{"id":"b832ec5b1f5d7201","repo":"OpenFeign/feign","slug":"do-not-wanted-s-but-was-invoked","errorCode":null,"errorMessage":"Do not wanted: '%s' but was invoked!","messagePattern":"Do not wanted: '(.+?)' but was invoked!","errorType":"exception","errorClass":"VerificationAssertionError","httpStatus":null,"severity":"error","filePath":"mock/src/main/java/feign/mock/MockClient.java","lineNumber":304,"sourceCode":"    }\n    if (result == null) {\n      throw new VerificationAssertionError(\n          \"Wanted: '%s' but never invoked! Got: %s\", requestKey, requests.keySet());\n    }\n\n    if (result.size() != times) {\n      throw new VerificationAssertionError(\n          \"Wanted: '%s' to be invoked: '%s' times but got: '%s'!\",\n          requestKey, times, result.size());\n    }\n\n    return result;\n  }\n\n  public void verifyNever(HttpMethod method, String url) {\n    RequestKey requestKey = RequestKey.builder(method, url).build();\n    if (requests.containsKey(requestKey)) {\n      throw new VerificationAssertionError(\"Do not wanted: '%s' but was invoked!\", requestKey);\n    }\n  }\n\n  public void verifyNever(RequestKey requestKey) {\n    for (RequestKey recorderRequestKey : requests.keySet()) {\n      if (recorderRequestKey.equalsExtended(requestKey)) {\n        throw new VerificationAssertionError(\"Do not wanted: '%s' but was invoked!\", requestKey);\n      }\n    }\n  }\n\n  /**\n   * To be called in an &#64;After method:\n   *\n   * <pre>\n   * &#64;After\n   * public void tearDown() {\n   *   mockClient.verifyStatus();","sourceCodeStart":286,"sourceCodeEnd":322,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/mock/src/main/java/feign/mock/MockClient.java#L286-L322","documentation":"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.","triggerScenarios":"mockClient.verifyNever(method, url) (directly, or via verifyTimes(method, url, 0)) where requests.containsKey(builtKey) is true.","commonSituations":"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().","solutions":["Remove or gate the unexpected call in the code under test","Update the test expectation if the endpoint legitimately should be called (switch to verifyTimes/verifyOne)","Call resetRequests() in setup/teardown so previous invocations do not leak in"],"exampleFix":"// before\nmockClient.verifyNever(HttpMethod.DELETE, \"/users/1\"); // delete was invoked\n// after\nmockClient.verifyTimes(HttpMethod.DELETE, \"/users/1\", 1); // reflect actual behavior","handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"try {\n  mockClient.verifyNever(HttpMethod.DELETE, \"/users/1\");\n} catch (VerificationAssertionError e) {\n  throw new AssertionError(\"Unexpected invocation: \" + e.getMessage(), e);\n}","preventionTips":["Exercise only the code paths intended for the scenario","resetRequests() in setup/teardown to avoid leaked invocations","Keep negative expectations in sync with behavior changes"],"tags":["mock","test","verification","negative-expectation"],"backgroundTag":"unexpected-api-response-shape","analyzedSha":"e2a1e27560a1e68840c34f031afca88b36096e30","analyzedAt":"2026-09-10T12:37:37.238Z","contentChangedAt":"2026-09-10T12:37:37.238Z","schemaVersion":2},"datasetVersion":"2026-09-16T09:17:16.951Z"}