本文整理汇总了Java中org.mockito.stubbing.Stubber类的典型用法代码示例。如果您正苦于以下问题:Java Stubber类的具体用法?Java Stubber怎么用?Java Stubber使用的例子?那么, 这里精选的类代码示例或许可以为您提供帮助。
Stubber类属于org.mockito.stubbing包,在下文中一共展示了Stubber类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: doThrowWhenCallStackMatches
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
/**
* Throw an exception from the mock/spy only in the case that the
* call stack at the time the method has a line which matches the given
* pattern.
*
* @param t the Throwable to throw
* @param pattern the pattern against which to match the call stack trace
* @return the stub in progress
*/
public static Stubber doThrowWhenCallStackMatches(
final Throwable t, final String pattern) {
return Mockito.doAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
t.setStackTrace(Thread.currentThread().getStackTrace());
for (StackTraceElement elem : t.getStackTrace()) {
if (elem.toString().matches(pattern)) {
throw t;
}
}
return invocation.callRealMethod();
}
});
}
示例2: answerStringByReference
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber answerStringByReference(String value) {
return doAnswer((Answer<Integer>) invocation -> {
Object[] args = invocation.getArguments();
PointerByReference reference = (PointerByReference)args[0];
Pointer pointer = new Memory(Native.WCHAR_SIZE * (value.length() +1));
pointer.setWideString(0, value);
reference.setValue(pointer);
return 0;
});
}
示例3: answerIntByReference
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber answerIntByReference(int value) {
return doAnswer((Answer<Integer>) invocation -> {
Object[] args = invocation.getArguments();
IntByReference reference = (IntByReference)args[0];
reference.setValue(value);
return 0;
});
}
示例4: doUpdateInto
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
private Stubber doUpdateInto(final List<Update> updates) {
return doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation)
throws Throwable {
//noinspection unchecked
Iterables.addAll(updates, (Iterable<Update>) invocation.getArguments()[0]);
return null;
}
});
}
示例5: captureUpdatesAndTags
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
private Stubber captureUpdatesAndTags(final List<Update> updates, final Set<String> tags) {
return doAnswer(new Answer() {
@Override
public Object answer(InvocationOnMock invocation)
throws Throwable {
//noinspection unchecked
Iterables.addAll(updates, (Iterable<Update>) invocation.getArguments()[0]);
//noinspection unchecked
tags.addAll((Collection<? extends String>) invocation.getArguments()[1]);
return null;
}
});
}
示例6: doThrow
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doThrow(final Throwable toBeThrown) {
return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
@Override
public Stubber run() {
return org.mockito.Mockito.doThrow(toBeThrown);
}
});
}
示例7: doCallRealMethod
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doCallRealMethod() {
return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
@Override
public Stubber run() {
return org.mockito.Mockito.doCallRealMethod();
}
});
}
示例8: doAnswer
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doAnswer(final Answer answer) {
return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
@Override
public Stubber run() {
return org.mockito.Mockito.doAnswer(answer);
}
});
}
示例9: doNothing
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doNothing() {
return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
@Override
public Stubber run() {
return org.mockito.Mockito.doNothing();
}
});
}
示例10: doReturn
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber doReturn(final Object toBeReturned) {
return AccessController.doPrivileged(new PrivilegedAction<Stubber>() {
@Override
public Stubber run() {
return org.mockito.Mockito.doReturn(toBeReturned);
}
});
}
示例11: copyToParameter
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public static Stubber copyToParameter(byte[] result)
{
return Mockito.doAnswer((x) ->
{
byte[] dst = (byte[])x.getArguments()[0];
System.arraycopy(result, 0, dst, 0, result.length);
return null;
});
}
示例12: doReturn
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
/**
* Extend Mockito API by allowing an arbitrary number of inputs to
* the method {@code doReturn()}
*
* @param value
* @param values
* @return
*/
public static Stubber doReturn(Object value, Object... values){
Stubber stubber = Mockito.doReturn(value);
for(Object v : values){
stubber = stubber.doReturn(v);
}
return stubber;
}
示例13: toAnswer
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
@SuppressWarnings("unchecked")
public <T> Stubber toAnswer(final Runnable method) {
return Mockito.doAnswer(invocation -> {
Object[] arguments = invocation.getArguments();
method.run();
return null;
});
}
示例14: doAnswer
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
private Stubber doAnswer(final Consumer<Object[]> method, final int argumentCount) {
return Mockito.doAnswer(invocation -> {
Object[] arguments = invocation.getArguments();
if (arguments.length >= argumentCount) {
method.accept(arguments);
} else {
failure("Invocation requires at least " + argumentCount + " argument");
}
return null;
});
}
示例15: spyReturnValue
import org.mockito.stubbing.Stubber; //导入依赖的package包/类
public Stubber spyReturnValue() {
return Mockito.doAnswer(new Answer<T>() {
public T answer(InvocationOnMock invocation) throws Throwable {
return setupSpy(invocation.callRealMethod());
}
});
}