Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- unused stubbing detection logic was not thread safe in Mockito JUnit runner - stopped using the StubbingListener - by design it couldn't support thread safe scenarios unfortunately :( Fixes #384
- Loading branch information
1 parent
61a9bff
commit c0a67d7
Showing
8 changed files
with
203 additions
and
160 deletions.
There are no files selected for viewing
38 changes: 38 additions & 0 deletions
38
src/main/java/org/mockito/internal/junit/UnnecessaryStubbingsReporter.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,38 @@ | ||
package org.mockito.internal.junit; | ||
|
||
import org.junit.runner.Description; | ||
import org.junit.runner.notification.Failure; | ||
import org.junit.runner.notification.RunNotifier; | ||
import org.mockito.internal.exceptions.Reporter; | ||
import org.mockito.invocation.Invocation; | ||
import org.mockito.listeners.MockCreationListener; | ||
import org.mockito.mock.MockCreationSettings; | ||
|
||
import java.util.Collection; | ||
import java.util.LinkedList; | ||
import java.util.List; | ||
|
||
/** | ||
* Reports unnecessary stubbings | ||
*/ | ||
public class UnnecessaryStubbingsReporter implements MockCreationListener { | ||
|
||
private List<Object> mocks = new LinkedList<Object>(); | ||
|
||
public void validateUnusedStubs(Class<?> testClass, RunNotifier notifier) { | ||
Collection<Invocation> unused = new UnusedStubbingsFinder().getUnusedStubbingsByLocation(mocks); | ||
if (unused.size() == 0) { | ||
return; //whoa!!! All stubbings were used! | ||
} | ||
|
||
//Oups, there are unused stubbings | ||
Description unnecessaryStubbings = Description.createTestDescription(testClass, "unnecessary Mockito stubbings"); | ||
notifier.fireTestFailure(new Failure(unnecessaryStubbings, | ||
Reporter.formatUnncessaryStubbingException(testClass, unused))); | ||
} | ||
|
||
@Override | ||
public void onMockCreated(Object mock, MockCreationSettings settings) { | ||
mocks.add(mock); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
69 changes: 0 additions & 69 deletions
69
src/main/java/org/mockito/internal/runners/UnnecessaryStubbingsReporter.java
This file was deleted.
Oops, something went wrong.
79 changes: 0 additions & 79 deletions
79
src/test/java/org/mockito/internal/junit/UnusedStubbingsFinderTest.java
This file was deleted.
Oops, something went wrong.
Oops, something went wrong.