• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    迪恩网络公众号

Java Primitives类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

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



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

示例1: verifyThrottled

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
private DataStore verifyThrottled(final DataStore dataStore) {
    return (DataStore) Proxy.newProxyInstance(getClass().getClassLoader(), new Class[] { DataStore.class },
            new AbstractInvocationHandler() {
                @Override
                protected Object handleInvocation(Object proxy, Method method, Object[] args) throws Throwable {
                    try {
                        method.invoke(dataStore, args);
                        fail(String.format("Throttled request did not generate a 503 error: %s(%s)",
                                method.getName(), Joiner.on(",").join(args)));
                    } catch (InvocationTargetException e) {
                        assertTrue(e.getCause() instanceof EmoClientException);
                        EmoClientException ce = (EmoClientException) e.getCause();
                        assertEquals(ce.getResponse().getStatus(), HttpStatus.SERVICE_UNAVAILABLE_503);
                    }
                    // This should be unreachable; the caller doesn't care what the result is
                    if (method.getReturnType().isPrimitive()) {
                        return Primitives.defaultValueForPrimitiveOrWrapper(method.getReturnType());
                    }
                    return null;
                }
            });
}
 
开发者ID:bazaarvoice,项目名称:emodb,代码行数:23,代码来源:AdHocThrottleTest.java


示例2: invokeMethod

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
protected void invokeMethod(Class<?> usedClass, String methodName, Object... params) throws Exception {
	Class<?> subjectClass = loadClass(usedClass);

	if (params == null) {
		params = new Object[] {};
	}
	Method targetedMethod = null;
	for (Method method : subjectClass.getMethods()) {
		if (method.getName().equals(methodName) && (method.getParameterTypes().length == params.length)) {
			boolean paramCanMatch = true;
			for (int i = 0; i < method.getParameterTypes().length && paramCanMatch; i++) {
				Class<?> paramClass = method.getParameterTypes()[i];
				if (params[i] != null && !paramClass.isAssignableFrom(params[i].getClass()) && !(paramClass.isPrimitive() && paramClass.equals(Primitives.primitiveTypeOf(params[i].getClass())))) {
					paramCanMatch = false;
				}
			}
			if (!paramCanMatch) {
				continue;
			}
			targetedMethod = method;
			break;
		}
	}

	if (targetedMethod == null) {
		throw new Exception("Aucune méthode " + methodName + " ne matche pour les paramètres données");
	}
	// On n'utile pas directement subjectClass.getMethod(methodName, paramClass) car la m�thode test�e peut avoir des types primitifs en param�tre.
	targetedMethod.invoke(createNewInstanceOfTestedClass(subjectClass), params);
}
 
开发者ID:BenoitRonflette,项目名称:FreeYourCode,代码行数:31,代码来源:AgentTest.java


示例3: isValidReturnType

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
public boolean isValidReturnType(Class clazz) {
    if (method.getReturnType().isPrimitive()) {
        return Primitives.primitiveTypeOf(clazz) == method.getReturnType();
    } else {
        return method.getReturnType().isAssignableFrom(clazz);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:Invocation.java


示例4: returnValueFor

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
Object returnValueFor(Class<?> type) {
    if (type.isPrimitive()) {
        return primitiveOf(type);
    } else if (Primitives.isPrimitiveWrapper(type)) {
        return Primitives.primitiveWrapperOf(type);
    //new instances are used instead of Collections.emptyList(), etc.
    //to avoid UnsupportedOperationException if code under test modifies returned collection
    } else if (type == Collection.class) {
        return new LinkedList<Object>();
    } else if (type == Set.class) {
        return new HashSet<Object>();
    } else if (type == HashSet.class) {
        return new HashSet<Object>();
    } else if (type == SortedSet.class) {
        return new TreeSet<Object>();
    } else if (type == TreeSet.class) {
        return new TreeSet<Object>();
    } else if (type == LinkedHashSet.class) {
        return new LinkedHashSet<Object>();
    } else if (type == List.class) {
        return new LinkedList<Object>();
    } else if (type == LinkedList.class) {
        return new LinkedList<Object>();
    } else if (type == ArrayList.class) {
        return new ArrayList<Object>();
    } else if (type == Map.class) {
        return new HashMap<Object, Object>();
    } else if (type == HashMap.class) {
        return new HashMap<Object, Object>();
    } else if (type == SortedMap.class) {
        return new TreeMap<Object, Object>();
    } else if (type == TreeMap.class) {
        return new TreeMap<Object, Object>();
    } else if (type == LinkedHashMap.class) {
        return new LinkedHashMap<Object, Object>();
    }       
    //Let's not care about the rest of collections.
    return null;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:40,代码来源:ReturnsEmptyValues.java


示例5: returnValueFor

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
Object returnValueFor(Class<?> type) {
    if (Primitives.isPrimitiveOrWrapper(type)) {
        return Primitives.defaultValueForPrimitiveOrWrapper(type);
    //new instances are used instead of Collections.emptyList(), etc.
    //to avoid UnsupportedOperationException if code under test modifies returned collection
    } else if (type == Collection.class) {
        return new LinkedList<Object>();
    } else if (type == Set.class) {
        return new HashSet<Object>();
    } else if (type == HashSet.class) {
        return new HashSet<Object>();
    } else if (type == SortedSet.class) {
        return new TreeSet<Object>();
    } else if (type == TreeSet.class) {
        return new TreeSet<Object>();
    } else if (type == LinkedHashSet.class) {
        return new LinkedHashSet<Object>();
    } else if (type == List.class) {
        return new LinkedList<Object>();
    } else if (type == LinkedList.class) {
        return new LinkedList<Object>();
    } else if (type == ArrayList.class) {
        return new ArrayList<Object>();
    } else if (type == Map.class) {
        return new HashMap<Object, Object>();
    } else if (type == HashMap.class) {
        return new HashMap<Object, Object>();
    } else if (type == SortedMap.class) {
        return new TreeMap<Object, Object>();
    } else if (type == TreeMap.class) {
        return new TreeMap<Object, Object>();
    } else if (type == LinkedHashMap.class) {
        return new LinkedHashMap<Object, Object>();
    }
    // TODO return empty Iterable ; see issue 175

    //Let's not care about the rest of collections.
    return null;
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:40,代码来源:ReturnsEmptyValues.java


示例6: isValidReturnType

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
public boolean isValidReturnType(Class clazz) {
    if (method.getReturnType().isPrimitive() || clazz.isPrimitive()) {
        return Primitives.primitiveTypeOf(clazz) == Primitives.primitiveTypeOf(method.getReturnType());
    } else {
        return method.getReturnType().isAssignableFrom(clazz);
    }
}
 
开发者ID:SpoonLabs,项目名称:astor,代码行数:8,代码来源:MethodInfo.java


示例7: returnForConsumerLambda

import org.mockito.internal.util.Primitives; //导入依赖的package包/类
@SuppressWarnings("unchecked")
<T> T returnForConsumerLambda(Consumer<T> consumer) {
    Class<?>[] typeArgs = TypeResolver.resolveRawArguments(Consumer.class, consumer.getClass());
    return (T) Primitives.defaultValue(typeArgs[0]);
}
 
开发者ID:szpak,项目名称:mockito-java8,代码行数:6,代码来源:LambdaAwareHandyReturnValues.java



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


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
Java RowProcessorService类代码示例发布时间:2022-05-22
下一篇:
Java SshFutureListener类代码示例发布时间:2022-05-22
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap