当前位置: 首页>>代码示例>>Java>>正文


Java ArgumentCaptor类代码示例

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


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

示例1: oldSecurityShouldFailIfNotAuthorized

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void oldSecurityShouldFailIfNotAuthorized() throws Exception {
  when(this.securityService.isClientSecurityRequired()).thenReturn(true);
  when(this.securityService.isIntegratedSecurity()).thenReturn(false);

  doThrow(new NotAuthorizedException("")).when(this.authzRequest)
      .registerInterestAuthorize(eq(REGION_NAME), eq(KEY), anyInt(), any());

  this.registerInterest61.cmdExecute(this.message, this.serverConnection, 0);

  verify(this.authzRequest).registerInterestAuthorize(eq(REGION_NAME), eq(KEY), anyInt(), any());

  ArgumentCaptor<NotAuthorizedException> argument =
      ArgumentCaptor.forClass(NotAuthorizedException.class);
  verify(this.chunkedResponseMessage).addObjPart(argument.capture());

  assertThat(argument.getValue()).isExactlyInstanceOf(NotAuthorizedException.class);
  verify(this.chunkedResponseMessage).sendChunk(this.serverConnection);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:20,代码来源:RegisterInterest61Test.java

示例2: testReleaseClosesOpenFileChannel

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void testReleaseClosesOpenFileChannel()
		throws Exception {
	// Given
	FileHandleFiller filler = mock(FileHandleFiller.class);
	ArgumentCaptor<Integer> handleCaptor = ArgumentCaptor.forClass(Integer.class);
	doNothing().when(filler).setFileHandle(handleCaptor.capture());
	Path fooBar = mockPath(mirrorRoot, "foo.bar");
	FileChannel fileChannel = mock(FileChannel.class);
	when(fileSystem.provider().newFileChannel(eq(fooBar), eq(set(StandardOpenOption.READ)))).thenReturn(fileChannel);
	fs.open("foo.bar", filler);
	// When
	int result = fs.release("foo.bar", handleCaptor.getValue());
	// Then
	assertThat(result).isEqualTo(SUCCESS);
	verify(fileChannelCloser).close(fileChannel);
	verifyNoMoreInteractions(fileChannel);
}
 
开发者ID:tfiskgul,项目名称:mux2fs,代码行数:19,代码来源:MirrorFsTest.java

示例3: statusShouldSendNoMatchResponseToTransaction_whenNoMatchResponseSentFromMatchingServiceCycle3Match

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void statusShouldSendNoMatchResponseToTransaction_whenNoMatchResponseSentFromMatchingServiceCycle3Match() throws Exception {
    final String requestId = "requestId";
    final SessionId sessionId = SessionId.createNewSessionId();
    Cycle3MatchRequestSentState state = aCycle3MatchRequestSentState().withSessionId(sessionId).withRequestId(requestId).build();
    Cycle3MatchRequestSentStateController controller =
            new Cycle3MatchRequestSentStateController(state, eventSinkHubEventLogger, stateTransitionAction, policyConfiguration,
                    null, null, transactionsConfigProxy, matchingServiceConfigProxy, assertionRestrictionFactory, attributeQueryService);
    ArgumentCaptor<NoMatchState> argumentCaptor = ArgumentCaptor.forClass(NoMatchState.class);
    NoMatchFromMatchingService noMatchFromMatchingService = new NoMatchFromMatchingService(matchingServiceEntityId, requestId);

    controller.handleNoMatchResponseFromMatchingService(noMatchFromMatchingService);

    verify(stateTransitionAction, times(1)).transitionTo(argumentCaptor.capture());
    NoMatchStateController noMatchStateController = new NoMatchStateController(argumentCaptor.getValue(), responseFromHubFactory);
    ResponseProcessingDetails responseProcessingDetails = noMatchStateController.getResponseProcessingDetails();
    assertThat(responseProcessingDetails.getResponseProcessingStatus()).isEqualTo(ResponseProcessingStatus.SEND_NO_MATCH_RESPONSE_TO_TRANSACTION);
    assertThat(responseProcessingDetails.getSessionId()).isEqualTo(sessionId);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:20,代码来源:Cycle3MatchRequestSentStateControllerTest.java

示例4: processSMimeEncryptedMessageAndCaptureMocks

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
private void processSMimeEncryptedMessageAndCaptureMocks(
        Message message, Body encryptedBody, OutputStream outputStream)
        throws Exception {
    messageCryptoHelper.asyncStartOrResumeProcessingMessage(message, messageCryptoCallback,
            null, null, false);

    ArgumentCaptor<Intent> intentCaptor = ArgumentCaptor.forClass(Intent.class);
    ArgumentCaptor<SMimeDataSource> dataSourceCaptor = ArgumentCaptor.forClass(SMimeDataSource.class);
    ArgumentCaptor<ISMimeSinkResultCallback> callbackCaptor = ArgumentCaptor.forClass(
            ISMimeSinkResultCallback.class);
    verify(sMimeApi).executeApiAsync(intentCaptor.capture(), dataSourceCaptor.capture(),
            any(SMimeDataSink.class), callbackCaptor.capture());

    capturedApiIntent = intentCaptor.getValue();
    capturedSMimeCallback = callbackCaptor.getValue();

    SMimeDataSource dataSource = dataSourceCaptor.getValue();
    dataSource.writeTo(outputStream);
    verify(encryptedBody).writeTo(outputStream);
}
 
开发者ID:philipwhiuk,项目名称:q-mail,代码行数:21,代码来源:MessageCryptoHelperTest.java

示例5: logEventSinkHubEvent_shouldSendEvent

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void logEventSinkHubEvent_shouldSendEvent() throws Exception {
    EventSinkHubEventLogger eventLogger = new EventSinkHubEventLogger(serviceInfo, eventSinkProxy);
    ArgumentCaptor<EventSinkHubEvent> eventCaptor = ArgumentCaptor.forClass(EventSinkHubEvent.class);
    SessionId expectedSessionId = aSessionId().build();

    eventLogger.logRequestFromHub(expectedSessionId, "transaction-entity-id");
    verify(eventSinkProxy).logHubEvent(eventCaptor.capture());

    EventSinkHubEvent actualEvent = eventCaptor.getValue();

    assertThat(actualEvent.getEventType()).isEqualTo(HUB_EVENT);
    assertThat(actualEvent.getSessionId()).isEqualTo(expectedSessionId.getSessionId());
    Map<EventDetailsKey, String> details = actualEvent.getDetails();

    assertThat(details.containsKey(hub_event_type)).isTrue();
    String hubEventType = details.get(hub_event_type);
    assertThat(hubEventType).isEqualTo(RECEIVED_AUTHN_REQUEST_FROM_HUB);
}
 
开发者ID:alphagov,项目名称:verify-hub,代码行数:20,代码来源:EventSinkHubEventLoggerTest.java

示例6: testResultWithLevelAndThrowableAndArgs

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void testResultWithLevelAndThrowableAndArgs() throws Exception {
    SmartLog.start(output);

    SmartLog.format(new SimpleTextFormat("${result}"));
    final RuntimeException exception = new RuntimeException("test");
    SmartLog.result(LogLevel.WARN, exception, "test-result: %d", 42);

    SmartLog.finish();

    final ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);
    final ArgumentCaptor<Exception> exceptionCaptor = ArgumentCaptor.forClass(Exception.class);
    Mockito.verify(logger).warn(msgCaptor.capture(), exceptionCaptor.capture());

    Assertions.assertThat(msgCaptor.getValue())
            .matches("test-result: 42");
    assertThat(exceptionCaptor.getValue())
            .isSameAs(exception);
}
 
开发者ID:ivnik,项目名称:smartlog,代码行数:20,代码来源:SmartLogTest.java

示例7: show_and_remove_button_several_activities

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void show_and_remove_button_several_activities() {
    final ArgumentCaptor<View> viewArgumentCaptor = ArgumentCaptor.forClass(View.class);

    final WindowManager windowManager1 = mock(WindowManager.class);
    final Activity activity1 = mockActivity(windowManager1);
    final ArgumentCaptor<View> viewArgumentCaptor1 = ArgumentCaptor.forClass(View.class);

    view.showButton(activity, false);
    verify(windowManager).addView(viewArgumentCaptor.capture(), any());

    view.showButton(activity1, false);
    verify(windowManager1).addView(viewArgumentCaptor1.capture(), any());

    view.removeButton(activity);
    verify(windowManager).removeView(viewArgumentCaptor.getValue());

    view.removeButton(activity1);
    verify(windowManager1).removeView(viewArgumentCaptor1.getValue());
}
 
开发者ID:roshakorost,项目名称:Phial,代码行数:21,代码来源:OverlayViewTest.java

示例8: testEnablePoweredNotifications

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void testEnablePoweredNotifications() throws Exception {
    Notification<Boolean> notification = mock(Notification.class);
    ArgumentCaptor<BluetoothNotification> captor = ArgumentCaptor.forClass(BluetoothNotification.class);
    doNothing().when(bluetoothAdapter).enablePoweredNotifications(captor.capture());

    tinyBAdapter.enablePoweredNotifications(notification);

    verify(bluetoothAdapter, times(1)).enablePoweredNotifications(captor.getValue());
    verifyNoMoreInteractions(bluetoothAdapter, notification);

    captor.getValue().run(Boolean.TRUE);
    verify(notification, times(1)).notify(Boolean.TRUE);

    doThrow(RuntimeException.class).when(notification).notify(anyBoolean());
    captor.getValue().run(Boolean.FALSE);
    verify(notification, times(1)).notify(Boolean.FALSE);
}
 
开发者ID:sputnikdev,项目名称:bluetooth-manager-tinyb,代码行数:19,代码来源:TinyBAdapterTest.java

示例9: testAuthenticateTMForController_noControllerSettings

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@SuppressWarnings("unchecked")
@Test
public void testAuthenticateTMForController_noControllerSettings()
        throws Throwable {

    // given
    VOUserDetails manager = createVOUserDetails(10000, "user", "tp123");
    Mockito.doThrow(new ConfigurationException("test")).when(configService)
            .getAuthenticationForBESTechnologyManager(anyString(),
                    any(ServiceInstance.class), Matchers.anyMap());
    Mockito.doReturn(null).when(authService)
            .getAuthenticatedTMForController(anyString(),
                    any(PasswordAuthentication.class));
    ArgumentCaptor<PasswordAuthentication> ac = ArgumentCaptor
            .forClass(PasswordAuthentication.class);

    // when
    authenticateTMForController(CTRL_ID, manager.getUserId(), "pass");

    // then
    verify(authService).getAuthenticatedTMForController(
            anyString(), ac.capture());
    assertEquals(manager.getUserId(), ac.getValue().getUserName());
    assertEquals("pass", ac.getValue().getPassword());
}
 
开发者ID:servicecatalog,项目名称:oscm-app,代码行数:26,代码来源:APPAuthenticationServiceBeanIT.java

示例10: saveOperatorRevenueShare

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void saveOperatorRevenueShare() throws Exception {
    PORevenueShare po = new PORevenueShare();
    po.setKey(101L);
    po.setRevenueShare(BigDecimal.TEN);
    po.setVersion(2);
    ArgumentCaptor<RevenueShareModel> captor = ArgumentCaptor
            .forClass(RevenueShareModel.class);

    // when
    Response response = bean.saveOperatorRevenueShare(1L, po);

    // then
    assertTrue(response.getResults().isEmpty());
    assertTrue(response.getWarnings().isEmpty());
    assertTrue(response.getReturnCodes().isEmpty());
    verify(bean.spPartnerServiceLocal, times(1)).saveOperatorRevenueShare(
            eq(1L), captor.capture(), eq(2));
    assertEquals(BigDecimal.TEN, captor.getValue().getRevenueShare());
    assertEquals(RevenueShareModelType.OPERATOR_REVENUE_SHARE, captor
            .getValue().getRevenueShareModelType());
    assertEquals(101L, captor.getValue().getKey());
}
 
开发者ID:servicecatalog,项目名称:oscm,代码行数:24,代码来源:PricingServiceBeanTest.java

示例11: findOne

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@SuppressWarnings({"rawtypes", "unchecked"})
@Test
public void findOne() throws Exception {

	resourceAdapter.findOne(1L, queryAdapter);

	ArgumentCaptor<Iterable> linksResources = ArgumentCaptor.forClass(Iterable.class);
	ArgumentCaptor<Iterable> metaResources = ArgumentCaptor.forClass(Iterable.class);
	ArgumentCaptor<RepositoryFilterContext> contexts = ArgumentCaptor.forClass(RepositoryFilterContext.class);

	Mockito.verify(filter, Mockito.times(1)).filterRequest(contexts.capture(), Mockito.any(RepositoryRequestFilterChain.class));
	Mockito.verify(filter, Mockito.times(1)).filterResult(Mockito.any(RepositoryFilterContext.class), Mockito.any(RepositoryResultFilterChain.class));
	Mockito.verify(filter, Mockito.times(1)).filterLinks(Mockito.any(RepositoryFilterContext.class), linksResources.capture(), Mockito.any(RepositoryLinksFilterChain.class));
	Mockito.verify(filter, Mockito.times(1)).filterMeta(Mockito.any(RepositoryFilterContext.class), metaResources.capture(), Mockito.any(RepositoryMetaFilterChain.class));

	Assert.assertEquals(1, linksResources.getAllValues().size());
	Assert.assertEquals(1, metaResources.getAllValues().size());
	Assert.assertEquals(1, contexts.getAllValues().size());
	RepositoryFilterContext context = contexts.getAllValues().iterator().next();
	RepositoryRequestSpec requestSpec = context.getRequest();
	Assert.assertEquals(queryAdapter, requestSpec.getQueryAdapter());
	Assert.assertEquals(1L, requestSpec.getId());
	Assert.assertEquals(Collections.singleton(1L), requestSpec.getIds());
	Assert.assertSame(querySpec, requestSpec.getQuerySpec(userInfo));
}
 
开发者ID:crnk-project,项目名称:crnk-framework,代码行数:26,代码来源:RepositoryFilterTest.java

示例12: testDataChangeListener

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@SuppressWarnings({ "rawtypes", "unchecked" })
@Test
public void testDataChangeListener() throws Exception {
    DataChangeListener listener = mock(DataChangeListener.class);
    InstanceIdentifier<ListItem> wildCard = InstanceIdentifier.builder(ListenerTest.class)
            .child(ListItem.class).build();
    ListenerRegistration<DataChangeListener> reg = getDataBroker().registerDataChangeListener(
            LogicalDatastoreType.OPERATIONAL, wildCard, listener, AsyncDataBroker.DataChangeScope.SUBTREE);

    final ListItem item = writeListItem();

    ArgumentCaptor<AsyncDataChangeEvent> captor = ArgumentCaptor.forClass(AsyncDataChangeEvent.class);

    verify(listener, timeout(100)).onDataChanged(captor.capture());

    AsyncDataChangeEvent event = captor.getValue();
    assertEquals("createdData", 1, event.getCreatedData().size());
    assertEquals("ListItem", item, event.getCreatedData().values().iterator().next());
}
 
开发者ID:hashsdn,项目名称:hashsdn-controller,代码行数:20,代码来源:Bug4513Test.java

示例13: monitorFailuresForSpecificMetastore

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void monitorFailuresForSpecificMetastore() throws Throwable {
  CurrentMonitoredMetaStoreHolder.monitorMetastore("metastoreName");
  when(pjp.proceed()).thenThrow(new ClassCastException());
  try {
    aspect.monitor(pjp, monitored);
  } catch (ClassCastException e) {
    // Expected
  }

  ArgumentCaptor<String> metricCaptor = ArgumentCaptor.forClass(String.class);
  verify(counterService, times(2)).increment(metricCaptor.capture());
  assertThat(metricCaptor.getAllValues().get(0), is("counter.Type_Anonymous.myMethod.metastoreName.calls"));
  assertThat(metricCaptor.getAllValues().get(1), is("counter.Type_Anonymous.myMethod.metastoreName.failure"));

  metricCaptor = ArgumentCaptor.forClass(String.class);
  ArgumentCaptor<Long> durationCaptor = ArgumentCaptor.forClass(Long.class);
  verify(gaugeService).submit(metricCaptor.capture(), durationCaptor.capture());
  assertThat(metricCaptor.getValue(), is("timer.Type_Anonymous.myMethod.metastoreName.duration"));
}
 
开发者ID:HotelsDotCom,项目名称:waggle-dance,代码行数:21,代码来源:MonitoredAspectTest.java

示例14: itCanAuthenticateWithAuthLogin

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void itCanAuthenticateWithAuthLogin() throws Exception {
  String username = "user";
  String password = "password";

  // do the initial request, which just includes the username
  session.authLogin("user", "password");

  verify(channel).writeAndFlush(new DefaultSmtpRequest("AUTH", "LOGIN", encodeBase64(username)));

  // now the second request, which sends the password
  responseFuture.complete(Lists.newArrayList(INTERMEDIATE_RESPONSE));

  // this is sent to the second invocation of writeAndFlush
  ArgumentCaptor<Object> bufCaptor = ArgumentCaptor.forClass(Object.class);
  verify(channel, times(2)).writeAndFlush(bufCaptor.capture());
  ByteBuf capturedBuffer = (ByteBuf) bufCaptor.getAllValues().get(1);

  String actualString = capturedBuffer.toString(0, capturedBuffer.readableBytes(), StandardCharsets.UTF_8);
  assertThat(actualString).isEqualTo(encodeBase64(password) + "\r\n");
}
 
开发者ID:HubSpot,项目名称:NioSmtpClient,代码行数:22,代码来源:SmtpSessionTest.java

示例15: testLogEmptyList

import org.mockito.ArgumentCaptor; //导入依赖的package包/类
@Test
public void testLogEmptyList() throws Exception {

    final TiLog.Logger logger = mock(TiLog.Logger.class);
    final LoggingInterceptor loggingInterceptor = new LoggingInterceptor(logger);
    final TestView view = loggingInterceptor.intercept(new TestViewImpl());

    final ArgumentCaptor<String> msgCaptor = ArgumentCaptor.forClass(String.class);

    view.twoArgs(new ArrayList(), "B");
    verify(logger).log(anyInt(), anyString(), msgCaptor.capture());

    assertThat(msgCaptor.getValue())
            .matches("twoArgs\\("
                    + "\\{ArrayList\\[0\\]@[\\da-f]{1,8}\\} \\[\\], "
                    + "B"
                    + "\\)");
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:19,代码来源:LoggingInterceptorTest.java


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