{"record":{"id":"e450a4defebb177b","repo":"mockito/mockito","slug":"no-interactions-wanted-here-location-but-found","errorCode":null,"errorMessage":"No interactions wanted here:\n${location}\nBut found these interactions on mock '${mockName}':\n${locations}\n${scenario}","messagePattern":"No interactions wanted here:\n(.+?)\nBut found these interactions on mock '(.+?)':\n(.+?)\n(.+?)","errorType":"exception","errorClass":"NoInteractionsWanted","httpStatus":null,"severity":"error","filePath":"mockito-core/src/main/java/org/mockito/internal/verification/NoInteractions.java","lineNumber":22,"sourceCode":" */\npackage org.mockito.internal.verification;\n\nimport static org.mockito.internal.exceptions.Reporter.noInteractionsWanted;\n\nimport java.util.List;\n\nimport org.mockito.internal.verification.api.VerificationData;\nimport org.mockito.invocation.Invocation;\nimport org.mockito.verification.VerificationMode;\n\npublic class NoInteractions implements VerificationMode {\n\n    @Override\n    @SuppressWarnings(\"unchecked\")\n    public void verify(VerificationData data) {\n        List<Invocation> invocations = data.getAllInvocations();\n        if (!invocations.isEmpty()) {\n            throw noInteractionsWanted(invocations.get(0).getMock(), (List) invocations);\n        }\n    }\n}\n","sourceCodeStart":4,"sourceCodeEnd":26,"githubUrl":"https://github.com/mockito/mockito/blob/5a676bcd9ef9a10db46e1dc34e190eb46faa2687/mockito-core/src/main/java/org/mockito/internal/verification/NoInteractions.java#L4-L26","documentation":"Mockito throws NoInteractionsWanted when verifyNoInteractions(mock) is called but the mock recorded at least one invocation. The NoInteractions verification mode checks data.getAllInvocations() and, if any exist, reports the first one. It is a test-assertion failure indicating the mock was used when the test expected it to be completely untouched.","triggerScenarios":"Calling verifyNoInteractions(mock) (or Mockito.verifyZeroInteractions in older versions) after the code under test already called any method on the mock, including auto-invocations like toString/hashCode/equals or stubbing setup leaks.","commonSituations":"Verifying no-interactions too late in the test after helper code touched the mock; production code has a new/changed call path that now uses the mock; using the mock for stubbing with doReturn then forgetting the mock was partially invoked; calling verifyNoInteractions on a mock shared across test setup steps.","solutions":["Move verifyNoInteractions(mock) earlier or remove code paths that touch the mock","Check the 'found this interaction' location in the message and eliminate that call in the code under test","Replace verifyNoInteractions with verify(mock, never()).someMethod() if only one method should not be called","Split the test so setup steps that must use the mock don't pollute the verification scope"],"exampleFix":"// before\nsvc.process(mock);\nverifyNoInteractions(mock);\n// after\nverifyNoInteractions(mock); // assert before exercising, or drop the unwanted call\nsvc.process(mock);","handlingStrategy":"validation","validationCode":"if (!mockitoTestingInternalUtil.getInvocations(mock).isEmpty()) { throw new AssertionError(\"mock already used before verifyNoInteractions\"); }","typeGuard":"boolean isUnused(Object mock) { return Mockito.mockingDetails(mock).getInvocations().isEmpty(); }","tryCatchPattern":"try { verifyNoInteractions(mock); } catch (NoInteractionsWanted e) { fail(\"unexpected interaction: \" + e.getMessage()); }","preventionTips":["Call verifyNoInteractions before exercising the code that may touch the mock","Prefer verify(mock, never()).m() for targeted guarantees","Do not share mocks across setup and assertion phases without resetting","Avoid toString/logging on mocks in test code"],"tags":["mockito","verification","java","unit-testing"],"backgroundTag":"mockito-unwanted-interactions","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"}