-
-
Notifications
You must be signed in to change notification settings - Fork 2.5k
/
StubbingArgMismatches.java
55 lines (45 loc) · 1.59 KB
/
StubbingArgMismatches.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
/*
* Copyright (c) 2016 Mockito contributors
* This program is made available under the terms of the MIT License.
*/
package org.mockito.internal.junit;
import org.mockito.plugins.MockitoLogger;
import org.mockito.invocation.Invocation;
import java.util.LinkedHashMap;
import java.util.LinkedHashSet;
import java.util.Map;
import java.util.Set;
/**
* Contains stubbing arg mismatches, knows how to format them
*/
class StubbingArgMismatches {
final Map<Invocation, Set<Invocation>> mismatches = new LinkedHashMap<Invocation, Set<Invocation>>();
public void add(Invocation invocation, Invocation stubbing) {
Set<Invocation> matchingInvocations = mismatches.get(stubbing);
if (matchingInvocations == null) {
matchingInvocations = new LinkedHashSet<Invocation>();
mismatches.put(stubbing, matchingInvocations);
}
matchingInvocations.add(invocation);
}
public void format(String testName, MockitoLogger logger) {
if (mismatches.isEmpty()) {
return;
}
StubbingHint hint = new StubbingHint(testName);
int x = 1;
for (Map.Entry<Invocation, Set<Invocation>> m : mismatches.entrySet()) {
hint.appendLine(x++, ". Unused... ", m.getKey().getLocation());
for (Invocation invocation : m.getValue()) {
hint.appendLine(" ...args ok? ", invocation.getLocation());
}
}
logger.log(hint.toString());
}
public int size() {
return mismatches.size();
}
public String toString() {
return "" + mismatches;
}
}