类org.mockito.internal.matchers.VarargMatcher源码实例Demo

下面列出了怎么用org.mockito.internal.matchers.VarargMatcher的API类实例代码及写法,或者点击链接到github查看源代码。

源代码1 项目: astor   文件: ArgumentsComparator.java
private boolean varArgsMatch(InvocationMatcher invocationMatcher, Invocation actual) {
    if (!actual.getMethod().isVarArgs()) {
        //if the method is not vararg forget about it
        return false;
    }

    //we must use raw arguments, not arguments...
    Object[] rawArgs = actual.getRawArguments();
    List<Matcher> matchers = invocationMatcher.getMatchers();

    if (rawArgs.length != matchers.size()) {
        return false;
    }

    for (int i = 0; i < rawArgs.length; i++) {
        Matcher m = matchers.get(i);
        //it's a vararg because it's the last array in the arg list
        if (rawArgs[i] != null && rawArgs[i].getClass().isArray() && i == rawArgs.length-1) {
            Matcher actualMatcher;
            //this is necessary as the framework often decorates matchers
            if (m instanceof MatcherDecorator) {
                actualMatcher = ((MatcherDecorator)m).getActualMatcher();
            } else {
                actualMatcher = m;
            }
            //this is very important to only allow VarargMatchers here. If you're not sure why remove it and run all tests.
            if (!(actualMatcher instanceof VarargMatcher) || !actualMatcher.matches(rawArgs[i])) {
                return false;
            }
        //it's not a vararg (i.e. some ordinary argument before varargs), just do the ordinary check
        } else if (!m.matches(rawArgs[i])){
            return false;
        }
    }

    return true;
}
 
源代码2 项目: astor   文件: ArgumentsComparator.java
private boolean varArgsMatch(InvocationMatcher invocationMatcher, Invocation actual) {
    if (!actual.getMethod().isVarArgs()) {
        //if the method is not vararg forget about it
        return false;
    }

    //we must use raw arguments, not arguments...
    Object[] rawArgs = actual.getRawArguments();
    List<Matcher> matchers = invocationMatcher.getMatchers();

    if (rawArgs.length != matchers.size()) {
        return false;
    }

    for (int i = 0; i < rawArgs.length; i++) {
        Matcher m = matchers.get(i);
        //it's a vararg because it's the last array in the arg list
        if (rawArgs[i] != null && rawArgs[i].getClass().isArray() && i == rawArgs.length-1) {
            Matcher actualMatcher;
            //this is necessary as the framework often decorates matchers
            if (m instanceof MatcherDecorator) {
                actualMatcher = ((MatcherDecorator)m).getActualMatcher();
            } else {
                actualMatcher = m;
            }
            //this is very important to only allow VarargMatchers here. If you're not sure why remove it and run all tests.
            if (!(actualMatcher instanceof VarargMatcher) || !actualMatcher.matches(rawArgs[i])) {
                return false;
            }
        //it's not a vararg (i.e. some ordinary argument before varargs), just do the ordinary check
        } else if (!m.matches(rawArgs[i])){
            return false;
        }
    }

    return true;
}
 
源代码3 项目: astor   文件: InvocationMatcher.java
private boolean isVarargMatcher(Matcher matcher) {
    Matcher actualMatcher = matcher;
    if (actualMatcher instanceof MatcherDecorator) {
        actualMatcher = ((MatcherDecorator) actualMatcher).getActualMatcher();
    }
    return actualMatcher instanceof VarargMatcher;
}
 
 类所在包
 类方法
 同包方法