Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Pushed complexity to a separate object
Issue #384
- Loading branch information
1 parent
d875684
commit 8987022
Showing
3 changed files
with
46 additions
and
15 deletions.
There are no files selected for viewing
42 changes: 42 additions & 0 deletions
42
src/main/java/org/mockito/internal/runners/StubbingArgMismatches.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,42 @@ | ||
package org.mockito.internal.runners; | ||
|
||
import org.mockito.internal.util.MockitoLogger; | ||
import org.mockito.invocation.Invocation; | ||
|
||
import java.util.HashMap; | ||
import java.util.HashSet; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
/** | ||
* Renders the stubbing hint on argument mismatches | ||
*/ | ||
class StubbingArgMismatches { | ||
|
||
Map<Invocation, Set<Invocation>> mismatches = new HashMap<Invocation, Set<Invocation>>(); | ||
|
||
public void add(Invocation invocation, Invocation stubbing) { | ||
Set<Invocation> matchingInvocations = mismatches.get(stubbing); | ||
if (matchingInvocations == null) { | ||
matchingInvocations = new HashSet<Invocation>(); | ||
mismatches.put(stubbing, matchingInvocations); | ||
} | ||
matchingInvocations.add(invocation); | ||
} | ||
|
||
public void log(MockitoLogger logger) { | ||
if (mismatches.isEmpty()) { | ||
return; | ||
} | ||
|
||
StringBuilder out = new StringBuilder("[MockitoHint] See javadoc for MockitoHint class.\n"); | ||
int x = 1; | ||
for (Map.Entry<Invocation, Set<Invocation>> m : mismatches.entrySet()) { | ||
out.append("[MockitoHint] ").append(x++).append(". unused stub ") | ||
.append(m.getKey().getLocation()).append("\n"); | ||
out.append("[MockitoHint] similar call ").append(m.getValue().iterator().next().getLocation()); | ||
} | ||
|
||
logger.log(out.toString()); | ||
} | ||
} |
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