{"record":{"id":"7f3be8729aae8ce2","repo":"mockito/mockito","slug":"argument-s-are-different-wanted-wanted-lo","errorCode":null,"errorMessage":"\nArgument(s) are different! Wanted:\n${wanted}\n${location}\nActual invocations have different arguments${ at position(s) ${indexes}}:\n${actualCalls with locations}\n","messagePattern":"\nArgument\\(s\\) are different! Wanted:\n(.+?)\n(.+?)\nActual invocations have different arguments(.+?)\\}:\n(.+?)\n","errorType":"exception","errorClass":"ArgumentsAreDifferent","httpStatus":null,"severity":"error","filePath":"mockito-core/src/main/java/org/mockito/internal/verification/checkers/MissingInvocationChecker.java","lineNumber":54,"sourceCode":"            return;\n        }\n\n        Invocation similar = findSimilarInvocation(invocations, wanted);\n        if (similar == null) {\n            throw wantedButNotInvoked(wanted, invocations);\n        }\n\n        Integer[] indexesOfSuspiciousArgs =\n                getSuspiciouslyNotMatchingArgsIndexes(wanted.getMatchers(), similar.getArguments());\n        Set<String> classesWithSameSimpleName =\n                getNotMatchingArgsWithSameName(wanted.getMatchers(), similar.getArguments());\n        SmartPrinter smartPrinter =\n                new SmartPrinter(\n                        wanted, invocations, indexesOfSuspiciousArgs, classesWithSameSimpleName);\n        List<Location> actualLocations =\n                invocations.stream().map(Invocation::getLocation).collect(Collectors.toList());\n\n        throw argumentsAreDifferent(\n                similar,\n                wanted,\n                smartPrinter.getWanted(),\n                smartPrinter.getActuals(),\n                actualLocations);\n    }\n\n    public static void checkMissingInvocation(\n            List<Invocation> invocations, MatchableInvocation wanted, InOrderContext context) {\n        List<Invocation> chunk = findAllMatchingUnverifiedChunks(invocations, wanted, context);\n\n        if (!chunk.isEmpty()) {\n            return;\n        }\n\n        Invocation previousInOrder = findPreviousVerifiedInOrder(invocations, context);\n        if (previousInOrder != null) {\n            throw wantedButNotInvokedInOrder(wanted, previousInOrder);","sourceCodeStart":36,"sourceCodeEnd":72,"githubUrl":"https://github.com/mockito/mockito/blob/5a676bcd9ef9a10db46e1dc34e190eb46faa2687/mockito-core/src/main/java/org/mockito/internal/verification/checkers/MissingInvocationChecker.java#L36-L72","documentation":"MissingInvocationChecker throws ArgumentsAreDifferent (an AssertionError with this message) when a similar invocation exists (same method) but with different arguments. It computes suspiciously non-matching argument indexes, builds a SmartPrinter diff of wanted vs actual arguments, and prints the actual calls with their locations, so the developer sees exactly which arguments diverged.","triggerScenarios":"verify(mock).m(expectedArg) while the mock was actually called with a different value for one or more parameters, e.g. different string content, different object instance without matching equals, or null vs non-null.","commonSituations":"]Comparing objects without equals/hashCode overridden (reference inequality); IDs or timestamps generated at runtime differ from test constants; mutable objects changed after the call; wrong hardcoded expected value after behavior change; equals vs same-instance matcher confusion.","solutions":["Use ArgumentCaptor to capture the actual argument and assert fields explicitly","Use any()/any(Class) matchers or argThat(...) with a field-wise predicate instead of equals","Implement equals/hashCode on the compared type, or compare with same(...)/refEq semantics","Print/log the actual arguments shown in the message and correct the expected values"],"exampleFix":"// before\nverify(repo).save(new User(\"id-1\")); // fails: actual id-2, no equals()\n// after\nArgumentCaptor<User> cap = ArgumentCaptor.forClass(User.class);\nverify(repo).save(cap.capture());\nassertEquals(\"id-2\", cap.getValue().getId());","handlingStrategy":"try-catch","validationCode":"boolean sameArgs = Mockito.mockingDetails(mock).getInvocations().stream().anyMatch(i -> i.getMethod().getName().equals(\"save\") && Objects.equals(i.getArguments()[0], expected)); if (!sameArgs) throw new AssertionError(\"args differ from expected\");","typeGuard":"<T> boolean invokedWith(Object mock, String method, java.util.function.Predicate<T> argMatch) { return Mockito.mockingDetails(mock).getInvocations().stream().anyMatch(i -> i.getMethod().getName().equals(method) && argMatch.test((T) i.getArguments()[0])); }","tryCatchPattern":"try { verify(mock).save(expected); } catch (ArgumentsAreDifferent e) { fail(\"argument mismatch: \" + e.getMessage()); }","preventionTips":["Implement equals/hashCode on argument types used in verify","Use ArgumentCaptor for objects with identity semantics","Avoid volatile values (timestamps, random IDs) in expected args","Compare captured arguments field-by-field instead of whole-object equals"],"tags":["mockito","verification","arguments","java","assertion"],"backgroundTag":"mockito-arguments-are-different","analyzedSha":"5a676bcd9ef9a10db46e1dc34e190eb46faa2687","analyzedAt":"2026-09-05T19:32:58.607Z","contentChangedAt":"2026-09-05T19:32:58.607Z","schemaVersion":2},"datasetVersion":"2026-09-12T22:17:10.623Z"}