org.mockito.Mockito.argThat()方法的使用及代码示例

x33g5p2x  于2022-01-24 转载在 其他  
字(13.2k)|赞(0)|评价(0)|浏览(345)

本文整理了Java中org.mockito.Mockito.argThat()方法的一些代码示例,展示了Mockito.argThat()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.argThat()方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:argThat

Mockito.argThat介绍

暂无

代码示例

代码示例来源:origin: org.mockito/mockito-core

/**
 * Use it to capture the argument. This method <b>must be used inside of verification</b>.
 * <p>
 * Internally, this method registers a special implementation of an {@link ArgumentMatcher}.
 * This argument matcher stores the argument value so that you can use it later to perform assertions.
 * <p>
 * See examples in javadoc for {@link ArgumentCaptor} class.
 *
 * @return null or default values
 */
public T capture() {
  Mockito.argThat(capturingMatcher);
  return defaultValue(clazz);
}

代码示例来源:origin: google/j2objc

/**
 * Use it to capture the argument. This method <b>must be used inside of verification</b>.
 * <p>
 * Internally, this method registers a special implementation of an {@link ArgumentMatcher}.
 * This argument matcher stores the argument value so that you can use it later to perform assertions.  
 * <p>
 * See examples in javadoc for {@link ArgumentCaptor} class.
 * 
 * @return null
 */
public T capture() {
  Mockito.argThat(capturingMatcher);
  return handyReturnValues.returnFor(clazz);
}

代码示例来源:origin: apache/hbase

private void verifyCohortSuccessful(List<String> cohortNames,
  SubprocedureFactory subprocFactory, Iterable<Subprocedure> cohortTasks,
  VerificationMode prepare, VerificationMode commit, VerificationMode cleanup,
  VerificationMode finish, boolean opHasError) throws Exception {
 // make sure we build the correct number of cohort members
 Mockito.verify(subprocFactory, Mockito.times(cohortNames.size())).buildSubprocedure(
  Mockito.eq(opName), (byte[]) Mockito.argThat(new ArrayEquals(data)));
 // verify that we ran each of the operations cleanly
 int j = 0;
 for (Subprocedure op : cohortTasks) {
  LOG.debug("Checking mock:" + (j++));
  waitAndVerifySubproc(op, prepare, commit, cleanup, finish, opHasError);
 }
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testSendUserMessageOrderedThickVersionIfOneOfNodesIsLocal() throws Exception {
  Object msg = new Object();
  GridIoManager ioMgr = spy(new TestGridIoManager(ctx));
  try {
    ioMgr.sendUserMessage(F.asList(locNode, rmtNode), msg, GridTopic.TOPIC_IGFS, true, 123L, false);
  }
  catch (Exception ignored) {
    // No-op. We are using mocks so real sending is impossible.
  }
  verify(ioMgr).sendOrderedMessageToGridTopic(
    argThat(new IsEqualCollection(F.asList(locNode, rmtNode))),
    eq(GridTopic.TOPIC_COMM_USER),
    any(GridIoUserMessage.class),
    eq(GridIoPolicy.PUBLIC_POOL),
    eq(123L),
    false);
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testSendUserMessageUnorderedThickVersionIfOneOfNodesIsLocal() throws Exception {
  Object msg = new Object();
  GridIoManager ioMgr = spy(new TestGridIoManager(ctx));
  try {
    ioMgr.sendUserMessage(F.asList(locNode, rmtNode), msg, GridTopic.TOPIC_IGFS, false, 123L, false);
  }
  catch (IgniteCheckedException ignored) {
    // No-op. We are using mocks so real sending is impossible.
  }
  verify(ioMgr).sendToGridTopic(eq(locNode), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class),
    eq(GridIoPolicy.PUBLIC_POOL));
  Collection<? extends ClusterNode> rmtNodes = F.view(F.asList(rmtNode), F.remoteNodes(locNode.id()));
  verify(ioMgr).sendToGridTopic(argThat(new IsEqualCollection(rmtNodes)), eq(GridTopic.TOPIC_COMM_USER),
    any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL));
}

代码示例来源:origin: apache/ignite

/**
 * @throws Exception If failed.
 */
@Test
public void testSendUserMessageThinVersionIfOneOfNodesIsLocal() throws Exception {
  Object msg = new Object();
  GridIoManager ioMgr = spy(new TestGridIoManager(ctx));
  try {
    ioMgr.sendUserMessage(F.asList(locNode, rmtNode), msg, null, false, 0, false);
  }
  catch (IgniteCheckedException ignored) {
    // No-op. We are using mocks so real sending is impossible.
  }
  verify(ioMgr).sendToGridTopic(eq(locNode), eq(GridTopic.TOPIC_COMM_USER), any(GridIoUserMessage.class),
    eq(GridIoPolicy.PUBLIC_POOL));
  Collection<? extends ClusterNode> rmtNodes = F.view(F.asList(rmtNode), F.remoteNodes(locNode.id()));
  verify(ioMgr).sendToGridTopic(argThat(new IsEqualCollection(rmtNodes)), eq(GridTopic.TOPIC_COMM_USER),
    any(GridIoUserMessage.class), eq(GridIoPolicy.PUBLIC_POOL));
}

代码示例来源:origin: AxonFramework/AxonFramework

@Test
public void testPublicationOrderIsMaintained_AggregateAdded() {
  String aggregateId = UUID.randomUUID().toString();
  GenericDomainEventMessage<StubAggregateCreatedEvent> event =
      new GenericDomainEventMessage<>("test", aggregateId, 0, new StubAggregateCreatedEvent(aggregateId));
  when(eventStore.readEvents(aggregateId)).thenReturn(DomainEventStream.of(event));
  doAnswer(invocation -> {
    System.out.println("Published event: " + invocation.getArguments()[0].toString());
    return Void.class;
  }).when(eventStore).publish(isA(EventMessage.class));
  commandBus.dispatch(asCommandMessage(new UpdateStubAggregateWithExtraEventCommand(aggregateId)));
  InOrder inOrder = inOrder(eventStore, eventStore, eventStore);
  inOrder.verify(eventStore).publish(isA(DomainEventMessage.class));
  inOrder.verify(eventStore).publish(argThat(new NotADomainEventMatcher()));
  inOrder.verify(eventStore).publish(isA(DomainEventMessage.class));
}

代码示例来源:origin: apache/geode

@Test
public void mergeResultsCustomCollectorManager() throws Exception {
 TopEntries resultEntries = new TopEntries();
 TopEntriesCollector mockCollector = mock(TopEntriesCollector.class);
 Mockito.doReturn(resultEntries).when(mockCollector).getEntries();
 CollectorManager<TopEntriesCollector> mockManager = mock(CollectorManager.class);
 Mockito.doReturn(mockCollector).when(mockManager)
   .reduce(Mockito.argThat(new ArgumentMatcher<Collection<TopEntriesCollector>>() {
    @Override
    public boolean matches(Collection<TopEntriesCollector> argument) {
     Collection<TopEntriesCollector> collectors = argument;
     return collectors.contains(result1) && collectors.contains(result2);
    }
   }));
 LuceneFunctionContext<TopEntriesCollector> context =
   new LuceneFunctionContext<>(null, null, mockManager);
 TopEntriesFunctionCollector collector = new TopEntriesFunctionCollector(context);
 collector.addResult(null, result1);
 collector.addResult(null, result2);
 collector.endResults();
 TopEntries merged = collector.getResult();
 assertEquals(resultEntries, merged);
}

代码示例来源:origin: pentaho/pentaho-kettle

@Test
public void testGetFields() throws Exception {
 WebServiceMeta webServiceMeta = new WebServiceMeta();
 webServiceMeta.setDefault();
 RowMetaInterface rmi = mock( RowMetaInterface.class );
 RowMetaInterface rmi2 = mock( RowMetaInterface.class );
 StepMeta nextStep = mock( StepMeta.class );
 IMetaStore metastore = mock( IMetaStore.class );
 Repository rep = mock( Repository.class );
 WebServiceField field1 = new WebServiceField();
 field1.setName( "field1" );
 field1.setWsName( "field1WS" );
 field1.setXsdType( "string" );
 WebServiceField field2 = new WebServiceField();
 field2.setName( "field2" );
 field2.setWsName( "field2WS" );
 field2.setXsdType( "string" );
 WebServiceField field3 = new WebServiceField();
 field3.setName( "field3" );
 field3.setWsName( "field3WS" );
 field3.setXsdType( "string" );
 webServiceMeta.setFieldsOut( Arrays.asList( field1, field2, field3 ) );
 webServiceMeta.getFields( rmi, "idk", new RowMetaInterface[]{ rmi2 }, nextStep, new Variables(), rep, metastore );
 verify( rmi ).addValueMeta( argThat( matchValueMetaString( "field1" ) ) );
 verify( rmi ).addValueMeta( argThat( matchValueMetaString( "field2" ) ) );
 verify( rmi ).addValueMeta( argThat( matchValueMetaString( "field3" ) ) );
}

代码示例来源:origin: apache/hbase

(byte[]) Mockito.argThat(new ArrayEquals(data)))).thenAnswer(
new Answer<Subprocedure>() {
 @Override

代码示例来源:origin: apache/hbase

Mockito.when(
 subprocFactory.buildSubprocedure(Mockito.eq(opName),
  (byte[]) Mockito.argThat(new ArrayEquals(data)))).thenAnswer(
 new Answer<Subprocedure>() {
  @Override

代码示例来源:origin: camunda/camunda-bpm-platform

public Void execute(CommandContext commandContext) {
  AuthorizationManager authorizationManager = spyOnSession(commandContext, AuthorizationManager.class);
  TaskQueryImpl taskQuery = (TaskQueryImpl) spy(processEngine.getTaskService().createTaskQuery());
  AuthorizationCheck authCheck = spy(new AuthorizationCheck());
  when(taskQuery.getAuthCheck()).thenReturn(authCheck);
  taskQuery.list();
  verify(authorizationManager, atLeastOnce()).filterAuthenticatedGroupIds(eq(testGroupIds));
  verify(authCheck, atLeastOnce()).setAuthGroupIds((List<String>) argThat(containsInAnyOrder(testGroupIds.toArray())));
  return null;
 }
});

代码示例来源:origin: serso/android-checkout

@Test
public void testShouldLoadAllPurchases() throws Exception {
  final Billing billing = prepareMultiPurchasesBilling();
  final CountDownLatch latch = new CountDownLatch(1);
  final CountDownListener l = new CountDownListener(latch);
  billing.getRequests().getAllPurchases(ProductTypes.IN_APP, l);
  assertTrue(latch.await(1, SECONDS));
  verify(l.listener).onSuccess(argThat(new PurchasesMatcher()));
}

代码示例来源:origin: serso/android-checkout

@Test
public void testShouldLoadWholePurchaseHistory() throws Exception {
  final Billing billing = prepareMultiPurchasesBilling();
  final CountDownLatch latch = new CountDownLatch(1);
  final CountDownListener l = new CountDownListener(latch);
  billing.getRequests().getWholePurchaseHistory(ProductTypes.IN_APP, null, l);
  assertTrue(latch.await(1, SECONDS));
  verify(l.listener).onSuccess(argThat(new PurchasesMatcher()));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPutSingleVariableWithNoValue() {
 String variableKey = "aVariableKey";
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
  .contentType(ContentType.JSON).body(EMPTY_JSON_OBJECT)
  .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
  .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
 verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
   argThat(EqualsNullValue.matcher()));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPutSingleVariableWithTypeString() {
 String variableKey = "aVariableKey";
 String variableValue = "aVariableValue";
 String type = "String";
 Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type);
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
  .contentType(ContentType.JSON).body(variableJson)
  .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
  .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
 verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
   argThat(EqualsPrimitiveValue.stringValue(variableValue)));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPutSingleVariable() {
 String variableKey = "aVariableKey";
 String variableValue = "aVariableValue";
 Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue);
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
  .contentType(ContentType.JSON).body(variableJson)
  .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
  .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
 verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
   argThat(EqualsUntypedValue.matcher().value(variableValue)));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPutSingleVariableWithTypeDouble() {
 String variableKey = "aVariableKey";
 Double variableValue = 123.456;
 String type = "Double";
 Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type);
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
  .contentType(ContentType.JSON).body(variableJson)
  .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
  .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
 verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
   argThat(EqualsPrimitiveValue.doubleValue(variableValue)));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPutSingleVariableWithTypeShort() {
 String variableKey = "aVariableKey";
 Short variableValue = 123;
 String type = "Short";
 Map<String, Object> variableJson = VariablesBuilder.getVariableValueMap(variableValue, type);
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
  .contentType(ContentType.JSON).body(variableJson)
  .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
  .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
 verify(runtimeServiceMock).setVariable(eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
   argThat(EqualsPrimitiveValue.shortValue(variableValue)));
}

代码示例来源:origin: camunda/camunda-bpm-platform

@Test
public void testPutSingleVariableFromSerializedWithNoValue() {
 String variableKey = "aVariableKey";
 Map<String, Object> requestJson = VariablesBuilder
   .getObjectValueMap(null, ValueType.OBJECT.getName(), null, null);
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).pathParam("varId", variableKey)
  .contentType(ContentType.JSON).body(requestJson)
  .then().expect().statusCode(Status.NO_CONTENT.getStatusCode())
  .when().put(SINGLE_PROCESS_INSTANCE_VARIABLE_URL);
 verify(runtimeServiceMock).setVariable(
   eq(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID), eq(variableKey),
   argThat(EqualsObjectValue.objectValueMatcher()));
}

相关文章