當前位置: 首頁>>代碼示例>>Java>>正文


Java InvocationOnMock.getArguments方法代碼示例

本文整理匯總了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;
        }
    };
}
 
開發者ID:philipwhiuk,項目名稱:q-mail,代碼行數:17,代碼來源:WebDavStoreTest.java

示例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));
}
 
開發者ID:servicecatalog,項目名稱:oscm,代碼行數:23,代碼來源:LoggerMocking.java

示例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;
}
 
開發者ID:ampool,項目名稱:monarch,代碼行數:22,代碼來源:GMSQuorumCheckerJUnitTest.java

示例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;
}
 
開發者ID:l294265421,項目名稱:ZooKeeper,代碼行數:41,代碼來源:WatchLeakTest.java

示例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;
}
 
開發者ID:naver,項目名稱:hadoop,代碼行數:16,代碼來源:TestDFSClientRetries.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:9,代碼來源:Util.java

示例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));
}
 
開發者ID:servicecatalog,項目名稱:oscm-app,代碼行數:16,代碼來源:VSystemProcessorBeanTest.java

示例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];
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:8,代碼來源:EnumRuleTest.java

示例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]);
        }
    };
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:12,代碼來源:AbstractPresenterDestroyTest.java

示例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());
}
 
開發者ID:GlobusLTD,項目名稱:primitive-collections-android,代碼行數:16,代碼來源:MockParcel.java

示例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());
}
 
開發者ID:GlobusLTD,項目名稱:primitive-collections-android,代碼行數:11,代碼來源:MockParcel.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:7,代碼來源:SingleRequestTest.java

示例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;
}
 
開發者ID:weiwenqiang,項目名稱:GitHub,代碼行數:7,代碼來源:BitmapPreFillRunnerTest.java

示例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;
}
 
開發者ID:qq565999484,項目名稱:RNLearn_Project1,代碼行數:7,代碼來源:TimingModuleTest.java

示例15: updateFlowAnswer

import org.mockito.invocation.InvocationOnMock; //導入方法依賴的package包/類
private Answer<FlowEntity> updateFlowAnswer() {
    return (InvocationOnMock invocation) -> {
        final FlowEntity flowEntity = (FlowEntity) invocation.getArguments()[0];
        return flowEntity;
    };
}
 
開發者ID:apache,項目名稱:nifi-registry,代碼行數:7,代碼來源:TestRegistryService.java


注:本文中的org.mockito.invocation.InvocationOnMock.getArguments方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。