mockito/mockito · error · Reporter-method
mocksHaveToBePassedToVerifyNoMoreInteractions()
Error message
mocksHaveToBePassedToVerifyNoMoreInteractions()
What it means
assertMocksNotEmpty() throws MockUtil-provided MockitoException (mocksHaveToBePassedToVerifyNoMoreInteractions) when verifyNoMoreInteractions() or verifyNoInteractions() is called with a null array or an empty varargs list. Interaction verification is meaningless without at least one mock, so Mockito fails fast with a descriptive exception instead of silently passing.
Source
Thrown at mockito-core/src/main/java/org/mockito/internal/MockitoCore.java:244
VerificationDataImpl data = new VerificationDataImpl(invocations, null);
noInteractions().verify(data);
} catch (NotAMockException e) {
throw notAMockPassedToVerifyNoMoreInteractions();
}
}
}
public void verifyNoMoreInteractionsInOrder(List<Object> mocks, InOrderContext inOrderContext) {
mockingProgress().validateState();
VerificationDataInOrder data =
new VerificationDataInOrderImpl(
inOrderContext, VerifiableInvocationsFinder.find(mocks), null);
VerificationModeFactory.noMoreInteractions().verifyInOrder(data);
}
private void assertMocksNotEmpty(Object[] mocks) {
if (mocks == null || mocks.length == 0) {
throw mocksHaveToBePassedToVerifyNoMoreInteractions();
}
}
private void assertNotStubOnlyMock(Object mock) {
if (getMockHandler(mock).getMockSettings().isStubOnly()) {
throw stubPassedToVerify(mock);
}
}
public InOrder inOrder(Object... mocks) {
if (mocks == null || mocks.length == 0) {
throw mocksHaveToBePassedWhenCreatingInOrder();
}
for (Object mock : mocks) {
if (mock == null) {
throw nullPassedWhenCreatingInOrder();
}
if (!isMock(mock)) {View on GitHub (pinned to 5a676bcd9e)
Solutions
- Pass at least one actual mock to the call; if the test has no collaborators, delete the verifyNoMoreInteractions/verifyNoInteractions statement.
- In shared base-test teardown code, guard the call: if (!mocks.isEmpty()) Mockito.verifyNoMoreInteractions(mocks.toArray());
- Re-add the missing mock registration (@Mock fields / Mockito.mock) if the empty list indicates broken wiring rather than intent.
Example fix
// before
Mockito.verifyNoMoreInteractions(); // nothing passed
// after
if (!mocks.isEmpty()) {
Mockito.verifyNoMoreInteractions(mocks.toArray());
} Defensive patterns
Strategy: validation
Validate before calling
if (mocks == null || mocks.length == 0) {
return; // nothing to verify — skip instead of calling Mockito
}
Mockito.verifyNoMoreInteractions(mocks); Try / catch
try {
Mockito.verifyNoMoreInteractions(mocks);
} catch (MockitoException e) {
assumeTrue("No mocks registered in this test configuration", false);
} Prevention
- Only call verifyNoMoreInteractions/verifyNoInteractions when at least one mock was registered.
- Guard shared base-class teardown with an isEmpty check on the mock collection.
- If the list is unexpectedly empty, treat it as wiring failure: assert the collection is non-empty first.
When it happens
Trigger: Mockito.verifyNoMoreInteractions(); verifyNoInteractions(); verifyNoMoreInteractions((Object[]) null); or spreading an empty array: verifyNoMoreInteractions(collectedMocks.toArray()) where collectedMocks is empty.
Common situations: A test helper that accumulates mocks into a list that ends up empty because the mocked collaborators were removed in a refactor; conditional test setups where no mocks are registered but a shared teardown still calls verifyNoMoreInteractions; accidental empty varargs after removing arguments.
Related errors
- nullPassedToVerifyNoMoreInteractions()
- notAMockPassedToVerifyNoMoreInteractions()
- mocksHaveToBePassedWhenCreatingInOrder()
- notAMockPassedToVerify(mock.getClass())
- nullPassedWhenCreatingInOrder()
AI-assisted analysis of mockito/mockito@5a676bcd9e (2026-09-05).
Data as JSON: /api/errors/8350f810aa247bdb.
Report an issue: GitHub.