Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fixes #3215 : Remove type parameter from Mockito#clearInvocations #3216

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 1 addition & 1 deletion src/main/java/org/mockito/MockedStatic.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ default void verify(Verification verification) {
void reset();

/**
* See {@link Mockito#clearInvocations(Object[])}.
* See {@link Mockito#clearInvocations(Object, Object...)}.
*/
void clearInvocations();

Expand Down
14 changes: 10 additions & 4 deletions src/main/java/org/mockito/Mockito.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
*/
package org.mockito;

import java.util.Objects;
import org.mockito.exceptions.misusing.PotentialStubbingProblem;
import org.mockito.exceptions.misusing.UnnecessaryStubbingException;
import org.mockito.internal.MockitoCore;
Expand Down Expand Up @@ -2629,11 +2630,16 @@ public static void clearAllCaches() {
* </ul>
*
* <b>Try to avoid this method at all costs. Only clear invocations if you are unable to efficiently test your program.</b>
* @param <T> The type of the mocks
* @param mocks The mocks to clear the invocations for
* @param mock a mock to clear the invocations for
* @param otherMocks other mocks to clear the invocation for
*/
public static <T> void clearInvocations(T... mocks) {
MOCKITO_CORE.clearInvocations(mocks);
public static void clearInvocations(final Object mock, final Object... otherMocks) {
Objects.requireNonNull(mock, "mock is null");
Objects.requireNonNull(otherMocks, "otherMocks is null");
MOCKITO_CORE.clearInvocations(mock);
for (final var otherMock: otherMocks) {
MOCKITO_CORE.clearInvocations(otherMock);
}
}

/**
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/mockito/internal/MockitoCore.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,13 +215,13 @@ public <T> void reset(T... mocks) {
}
}

public <T> void clearInvocations(T... mocks) {
public void clearInvocations(final Object... mocks) {
MockingProgress mockingProgress = mockingProgress();
mockingProgress.validateState();
mockingProgress.reset();
mockingProgress.resetOngoingStubbing();

for (T m : mocks) {
for (final Object m : mocks) {
getInvocationContainer(m).clearInvocations();
}
}
Expand Down