Search in sources :

Example 1 with ContainsExtraTypeInfo

use of org.mockito.internal.matchers.ContainsExtraTypeInfo in project mockito by mockito.

the class ArgumentMatchingTool method getSuspiciouslyNotMatchingArgsIndexes.

/**
     * Suspiciously not matching arguments are those that don't match, the toString() representation is the same but types are different.
     */
public static Integer[] getSuspiciouslyNotMatchingArgsIndexes(List<ArgumentMatcher> matchers, Object[] arguments) {
    if (matchers.size() != arguments.length) {
        return new Integer[0];
    }
    List<Integer> suspicious = new LinkedList<Integer>();
    int i = 0;
    for (ArgumentMatcher m : matchers) {
        if (m instanceof ContainsExtraTypeInfo && !safelyMatches(m, arguments[i]) && toStringEquals(m, arguments[i]) && !((ContainsExtraTypeInfo) m).typeMatches(arguments[i])) {
            suspicious.add(i);
        }
        i++;
    }
    return suspicious.toArray(new Integer[0]);
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) ContainsExtraTypeInfo(org.mockito.internal.matchers.ContainsExtraTypeInfo) LinkedList(java.util.LinkedList)

Example 2 with ContainsExtraTypeInfo

use of org.mockito.internal.matchers.ContainsExtraTypeInfo in project mockito by mockito.

the class MatchersPrinter method applyPrintSettings.

private Iterator<FormattedText> applyPrintSettings(List<ArgumentMatcher> matchers, PrintSettings printSettings) {
    List<FormattedText> out = new LinkedList<FormattedText>();
    int i = 0;
    for (final ArgumentMatcher matcher : matchers) {
        if (matcher instanceof ContainsExtraTypeInfo && printSettings.extraTypeInfoFor(i)) {
            out.add(new FormattedText(((ContainsExtraTypeInfo) matcher).toStringWithType()));
        } else {
            out.add(new FormattedText(MatcherToString.toString(matcher)));
        }
        i++;
    }
    return out.iterator();
}
Also used : ArgumentMatcher(org.mockito.ArgumentMatcher) ContainsExtraTypeInfo(org.mockito.internal.matchers.ContainsExtraTypeInfo) LinkedList(java.util.LinkedList)

Aggregations

LinkedList (java.util.LinkedList)2 ArgumentMatcher (org.mockito.ArgumentMatcher)2 ContainsExtraTypeInfo (org.mockito.internal.matchers.ContainsExtraTypeInfo)2