本文整理汇总了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;
}
});
}
示例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);
}
示例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);
}
}
示例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;
}
示例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;
}
示例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);
}
}
示例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]);
}