当前位置: 首页>>代码示例>>Java>>正文


Java VarargMatcher类代码示例

本文整理汇总了Java中org.mockito.internal.matchers.VarargMatcher的典型用法代码示例。如果您正苦于以下问题:Java VarargMatcher类的具体用法?Java VarargMatcher怎么用?Java VarargMatcher使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。


VarargMatcher类属于org.mockito.internal.matchers包,在下文中一共展示了VarargMatcher类的2个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: varArgsMatch

import org.mockito.internal.matchers.VarargMatcher; //导入依赖的package包/类
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;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:38,代码来源:ArgumentsComparator.java

示例2: isVarargMatcher

import org.mockito.internal.matchers.VarargMatcher; //导入依赖的package包/类
private boolean isVarargMatcher(Matcher matcher) {
    Matcher actualMatcher = matcher;
    if (actualMatcher instanceof MatcherDecorator) {
        actualMatcher = ((MatcherDecorator) actualMatcher).getActualMatcher();
    }
    return actualMatcher instanceof VarargMatcher;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:InvocationMatcher.java


注:本文中的org.mockito.internal.matchers.VarargMatcher类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。