本文整理汇总了Java中org.mockito.invocation.InvocationOnMock.getArguments方法的典型用法代码示例。如果您正苦于以下问题:Java InvocationOnMock.getArguments方法的具体用法?Java InvocationOnMock.getArguments怎么用?Java InvocationOnMock.getArguments使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mockito.invocation.InvocationOnMock
的用法示例。
在下文中一共展示了InvocationOnMock.getArguments方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: createOkResponseWithCookie
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
private Answer<HttpResponse> createOkResponseWithCookie() {
return new Answer<HttpResponse>() {
@Override
public HttpResponse answer(InvocationOnMock invocation) throws Throwable {
HttpContext context = (HttpContext) invocation.getArguments()[1];
if (context.getAttribute(ClientContext.COOKIE_STORE) != null) {
BasicCookieStore cookieStore =
(BasicCookieStore) context.getAttribute(ClientContext.COOKIE_STORE);
BasicClientCookie cookie = new BasicClientCookie("cookie", "meLikeCookie");
cookieStore.addCookie(cookie);
}
return OK_200_RESPONSE;
}
};
}
示例2: addConsoleDebug
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
/**
* Adds a little (not complete) console debug output to a mocked logger.
*
* @param mogger
* the mocked logger
*/
public static void addConsoleDebug(SimpleLogger mogger) {
Answer<Void> answer = new Answer<Void>() {
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] arguments = invocation.getArguments();
if (arguments != null && arguments.length > 0
&& arguments[0] != null) {
System.out.println(arguments[0]);
}
return null;
}
};
Mockito.doAnswer(answer).when(mogger).debug(Matchers.anyString());
Mockito.doAnswer(answer).when(mogger).debug(Matchers.anyString(),
Matchers.any(Throwable.class));
}
示例3: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
for (int i = 0; i < args.length; i++) {
if (args[i] instanceof Message) {
Message msg = (Message) args[i];
Object content = null;
content = msg.getBuffer();
if (content instanceof byte[]) {
if (pingPonger.isPingMessage((byte[]) content)) {
pingCount++;
if (simulatedPongRespondersByPort.contains(((JGAddress) msg.getDest()).getPort())) {
channel.getReceiver()
.receive(pingPonger.createPongMessage(msg.getDest(), msg.getSrc()));
}
}
}
}
}
return null;
}
示例4: createClientSocketChannel
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
/**
* Mock a client channel with a connection request and a watches message
* inside.
*
* @return a socket channel
* @throws IOException
*/
private SocketChannel createClientSocketChannel() throws IOException {
SocketChannel socketChannel = mock(SocketChannel.class);
Socket socket = mock(Socket.class);
InetSocketAddress socketAddress = new InetSocketAddress(1234);
when(socket.getRemoteSocketAddress()).thenReturn(socketAddress);
when(socketChannel.socket()).thenReturn(socket);
// Send watches packet to server connection
final ByteBuffer connRequest = createConnRequest();
final ByteBuffer watchesMessage = createWatchesMessage();
final ByteBuffer request = ByteBuffer.allocate(connRequest.limit()
+ watchesMessage.limit());
request.put(connRequest);
request.put(watchesMessage);
Answer<Integer> answer = new Answer<Integer>() {
int i = 0;
@Override
public Integer answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
ByteBuffer bb = (ByteBuffer) args[0];
for (int k = 0; k < bb.limit(); k++) {
bb.put(request.get(i));
i = i + 1;
}
return bb.limit();
}
};
when(socketChannel.read(any(ByteBuffer.class))).thenAnswer(answer);
return socketChannel;
}
示例5: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public LocatedBlocks answer(InvocationOnMock invocation) throws IOException {
Object args[] = invocation.getArguments();
LocatedBlocks realAnswer = realNN.getBlockLocations(
(String)args[0],
(Long)args[1],
(Long)args[2]);
if (failuresLeft-- > 0) {
NameNode.LOG.info("FailNTimesAnswer injecting failure.");
return makeBadBlockList(realAnswer);
}
NameNode.LOG.info("FailNTimesAnswer no longer failing.");
return realAnswer;
}
示例6: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
DataFetcher.DataCallback<T> callback =
(DataFetcher.DataCallback<T>) invocationOnMock.getArguments()[1];
callback.onDataReady(data);
return null;
}
示例7: addDiskImageAnswer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
private void addDiskImageAnswer() throws Exception {
Answer<DiskImage> answerDiskImage = new Answer<DiskImage>() {
@Override
public DiskImage answer(InvocationOnMock invocation)
throws Throwable {
Object[] arguments = invocation.getArguments();
if (arguments != null && arguments.length > 0) {
return diskImages.get(arguments[0]);
}
return null;
}
};
Mockito.doAnswer(answerDiskImage).when(vServerProcessor)
.isDiskImageIdValid(anyString(), any(PropertyHandler.class));
}
示例8: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@SuppressWarnings("unchecked")
@Override
public T answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
//noinspection unchecked
return (T) args[0];
}
示例9: getFromMap
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@NonNull
private Answer getFromMap(final HashMap<String, String> store) {
return new Answer() {
@Override
public String answer(final InvocationOnMock invocation) throws Throwable {
final Object[] args = invocation.getArguments();
//noinspection RedundantCast
return store.get((String) args[0]);
}
};
}
示例10: setupWrites
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
private void setupWrites() {
final Answer<Void> writeSingleValueAnswer = new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
final Object parameter = invocation.getArguments()[0];
mObjects.add(parameter);
return null;
}
};
doAnswer(writeSingleValueAnswer).when(mParcel).writeString(anyString());
doAnswer(writeSingleValueAnswer).when(mParcel).writeInt(anyInt());
doAnswer(writeSingleValueAnswer).when(mParcel).writeLong(anyLong());
doAnswer(writeSingleValueAnswer).when(mParcel).writeIntArray(Matchers.<int[]>any());
doAnswer(writeSingleValueAnswer).when(mParcel).writeLongArray(Matchers.<long[]>any());
}
示例11: setupOther
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
private void setupOther() {
final Answer<Void> setDataPositionAnswer = new Answer<Void>() {
@Override
public Void answer(final InvocationOnMock invocation) throws Throwable {
mPosition = ((Integer) invocation.getArguments()[0]);
return null;
}
};
doAnswer(setDataPositionAnswer).when(mParcel).setDataPosition(anyInt());
}
示例12: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Object answer(InvocationOnMock invocationOnMock) throws Throwable {
SizeReadyCallback cb = (SizeReadyCallback) invocationOnMock.getArguments()[0];
cb.onSizeReady(width, height);
return null;
}
示例13: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Void answer(InvocationOnMock invocationOnMock) throws Throwable {
Bitmap bitmap = (Bitmap) invocationOnMock.getArguments()[0];
bitmaps.add(bitmap);
return null;
}
示例14: answer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
@Override
public Void answer(InvocationOnMock invocation) throws Throwable {
Object[] args = invocation.getArguments();
mFrameCallback = (ChoreographerCompat.FrameCallback) args[1];
return null;
}
示例15: updateFlowAnswer
import org.mockito.invocation.InvocationOnMock; //导入方法依赖的package包/类
private Answer<FlowEntity> updateFlowAnswer() {
return (InvocationOnMock invocation) -> {
final FlowEntity flowEntity = (FlowEntity) invocation.getArguments()[0];
return flowEntity;
};
}