org.mockito.internal.junit.StubbingArgMismatches Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of mockito-core Show documentation
Show all versions of mockito-core Show documentation
Mockito mock objects library core API and implementation
/*
* 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> mismatches = new LinkedHashMap>();
public void add(Invocation invocation, Invocation stubbing) {
Set matchingInvocations = mismatches.get(stubbing);
if (matchingInvocations == null) {
matchingInvocations = new LinkedHashSet();
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> 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;
}
}