{"record":{"id":"c0151b55fb052fed","repo":"OpenFeign/feign","slug":"expected-s-but-was-s","errorCode":null,"errorMessage":"Expected: \n%s,\nbut was: \n%s","messagePattern":"Expected: \n(.+?),\nbut was: \n(.+?)","errorType":"exception","errorClass":"VerificationAssertionError","httpStatus":null,"severity":"error","filePath":"mock/src/main/java/feign/mock/MockClient.java","lineNumber":97,"sourceCode":"      responseBuilder = executeAny(request, requestKey);\n    }\n    responseBuilder.protocolVersion(ProtocolVersion.MOCK);\n\n    return CompletableFuture.completedFuture(responseBuilder.request(request).build());\n  }\n\n  private Response.Builder executeSequential(RequestKey requestKey) {\n    Response.Builder responseBuilder;\n    if (responseIterator == null) {\n      responseIterator = responses.iterator();\n    }\n    if (!responseIterator.hasNext()) {\n      throw new VerificationAssertionError(\"Received excessive request %s\", requestKey);\n    }\n\n    RequestResponse expectedRequestResponse = responseIterator.next();\n    if (!expectedRequestResponse.requestKey.equalsExtended(requestKey)) {\n      throw new VerificationAssertionError(\n          \"Expected: \\n%s,\\nbut was: \\n%s\", expectedRequestResponse.requestKey, requestKey);\n    }\n\n    responseBuilder = expectedRequestResponse.responseBuilder;\n    return responseBuilder;\n  }\n\n  private Response.Builder executeAny(Request request, RequestKey requestKey) {\n    Response.Builder responseBuilder;\n    if (requests.containsKey(requestKey)) {\n      requests.get(requestKey).add(request);\n    } else {\n      requests.put(requestKey, new ArrayList<>(Arrays.asList(request)));\n    }\n\n    responseBuilder = getResponseBuilder(request, requestKey);\n    return responseBuilder;\n  }","sourceCodeStart":79,"sourceCodeEnd":115,"githubUrl":"https://github.com/OpenFeign/feign/blob/e2a1e27560a1e68840c34f031afca88b36096e30/mock/src/main/java/feign/mock/MockClient.java#L79-L115","documentation":"MockClient's sequential execution mode replays recorded request/response pairs in order. When the incoming request's key does not equal the next expected RequestKey (compared with equalsExtended, which matches url and possibly headers/body), a VerificationAssertionError is thrown showing the expected and actual request keys. It signals the test issued a request different from the next one queued in the mock.","triggerScenarios":"Calling a Feign client built with MockClient.imitateSequential() (or executing sequentially) where the outgoing request's method/url does not match the next recorded RequestKey via equalsExtended.","commonSituations":"Test sends requests in a different order than they were enqueued; URL built by the target differs (extra/missing path segments or query params); headers or body included in requestKey comparison differ from what was recorded; test forgot to enqueue the request that fires first (e.g. health check).","solutions":["Reorder or add MockClient.add(requestKey, response) calls so the next expected RequestKey matches the actual outgoing request","Print both keys and diff method, url, query params, and headers; fix the client request or the recorded RequestKey builder arguments","If order does not matter, use MockClient.imitate() (non-sequential) instead of sequential mode"],"exampleFix":"// before\nmockClient.add(RequestKey.builder(HttpMethod.GET, \"/users/1\").build(), okResponse);\n// test calls GET /users/2 -> mismatch\n\n// after\nmockClient.add(RequestKey.builder(HttpMethod.GET, \"/users/2\").build(), okResponse);","handlingStrategy":"validation","validationCode":"// Before asserting, ensure enqueued keys match the calls your client will make:\nRequestKey expected = RequestKey.builder(HttpMethod.GET, url).build();\nif (!expected.equalsExtended(actualRequestKey)) {\n  throw new IllegalStateException(\"Mock sequence mismatch: \" + expected + \" vs \" + actualRequestKey);\n}","typeGuard":null,"tryCatchPattern":"try {\n  response = client.call();\n} catch (VerificationAssertionError e) {\n  // log expected vs actual request keys from e.getMessage()\n  throw new AssertionError(\"Sequential mock request mismatch: \" + e.getMessage(), e);\n}","preventionTips":["Enqueue RequestKeys in exactly the order the client will issue requests","Build RequestKeys from the same constants used by the client target/URL","Prefer non-sequential imitate() when request order is irrelevant"],"tags":["mock","test","sequential","request-mismatch"],"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"}