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

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

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

Mockito.anyMap介绍

暂无

代码示例

代码示例来源:origin: kaaproject/kaa

public void verify() throws Exception {
  Mockito.verify(multiplexer, Mockito.times(wantedNumberOfInvocations)).compileRequest(Mockito.anyMap());
  Mockito.verify(demultiplexer, Mockito.times(wantedNumberOfInvocations)).processResponse(Mockito.any(byte[].class));
 }
}

代码示例来源:origin: kaaproject/kaa

public void verify() throws Exception {
 Mockito.verify(getMultiplexer(), Mockito.times(wantedNumberOfInvocations)).compileRequest(Mockito.anyMap());
 Mockito.verify(getDemultiplexer(), Mockito.times(wantedNumberOfInvocations))
   .processResponse(Mockito.eq(new byte[]{5, 5, 5}));
}

代码示例来源:origin: kaaproject/kaa

public void verify() throws Exception {
  Mockito.verify(getMultiplexer(), Mockito.times(wantedNumberOfInvocations)).compileRequest(Mockito.anyMap());
  Mockito.verify(getDemultiplexer(), Mockito.times(wantedNumberOfInvocations)).processResponse(Mockito.any(byte[].class));
 }
}

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

@SuppressWarnings( "unchecked" )
@Test
@PrepareForTest( StepWithMappingMeta.class )
public void testExportResources() throws Exception {
 StepWithMappingMeta stepWithMappingMeta = spy( new StepWithMappingMeta() {
  @Override
  public void setDefault() {
  }
  @Override
  public StepDataInterface getStepData() {
   return null;
  }
  @Override
  public StepInterface getStep( StepMeta stepMeta, StepDataInterface stepDataInterface, int copyNr, TransMeta transMeta, Trans trans ) {
   return null;
  }
 } );
 String testName = "test";
 PowerMockito.mockStatic( StepWithMappingMeta.class );
 when( StepWithMappingMeta.loadMappingMeta( any(), any(), any(), any() ) ).thenReturn( transMeta );
 when( transMeta.exportResources( any(), anyMap(), any(), any(), any() ) ).thenReturn( testName );
 stepWithMappingMeta.exportResources( null, null, null, null, null );
 verify( transMeta ).setFilename( "${" + Const.INTERNAL_VARIABLE_ENTRY_CURRENT_DIRECTORY + "}/" + testName );
 verify( stepWithMappingMeta ).setSpecificationMethod( ObjectLocationSpecificationMethod.FILENAME );
}

代码示例来源:origin: kaaproject/kaa

Mockito.when(multiplexer.compileRequest(Mockito.anyMap())).thenReturn(new byte[]{1, 1, 1});
KaaDataDemultiplexer demultiplexer = Mockito.mock(KaaDataDemultiplexer.class);
DefaultOperationsChannelFake channel = new DefaultOperationsChannelFake(client, state, failoverManager, 3);

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

environmentVariableContext.setProperty("VAR4", "old-value4", true);
when(artifactExtension.fetchArtifact(eq(PLUGIN_ID), eq(artifactStore), any(), anyMap(), eq(metadataDest.getParent())))
    .thenReturn(Arrays.asList(
        new FetchArtifactEnvironmentVariable("VAR1", "value1-is-now-secure", true),

代码示例来源:origin: kaaproject/kaa

@Test
public void onUserResponse() throws Exception {
 Map<Integer, EndpointAccessToken> attachingEPs = new HashMap<>();
 attachingEPs.put(REQUEST_ID_1, new EndpointAccessToken("token1"));
 attachingEPs.put(REQUEST_ID_2, new EndpointAccessToken("token2"));
 Map<Integer, EndpointKeyHash> dettachingEPs = new HashMap<>();
 dettachingEPs.put(REQUEST_ID_1, new EndpointKeyHash("keyhash1"));
 dettachingEPs.put(REQUEST_ID_2, new EndpointKeyHash("keyhash2"));
 KaaClientState clientState = Mockito.mock(KaaClientState.class);
 EndpointRegistrationProcessor processor = Mockito.mock(EndpointRegistrationProcessor.class);
 Mockito.when(processor.getAttachEndpointRequests()).thenReturn(attachingEPs);
 Mockito.when(processor.getDetachEndpointRequests()).thenReturn(dettachingEPs);
 UserTransport transport = new DefaultUserTransport();
 UserSyncResponse response1 = new UserSyncResponse();
 response1.setEndpointAttachResponses(Arrays.asList(
   new EndpointAttachResponse(REQUEST_ID_1, "keyhash1", SyncResponseResultType.SUCCESS),
   new EndpointAttachResponse(REQUEST_ID_2, "keyhash2", SyncResponseResultType.SUCCESS),
   new EndpointAttachResponse(REQUEST_ID_1 + 1, "keyhash2", SyncResponseResultType.FAILURE)));
 response1.setEndpointDetachResponses(Arrays.asList(
   new EndpointDetachResponse(REQUEST_ID_1, SyncResponseResultType.SUCCESS),
   new EndpointDetachResponse(REQUEST_ID_1 + 2, SyncResponseResultType.FAILURE)));
 transport.setEndpointRegistrationProcessor(processor);
 transport.setClientState(clientState);
 transport.onUserResponse(response1);
 Mockito.verify(processor, Mockito.times(1)).onUpdate(Mockito.anyListOf(EndpointAttachResponse.class), Mockito.anyListOf(EndpointDetachResponse.class), Mockito.any(UserAttachResponse.class), Mockito.any(UserAttachNotification.class), Mockito.any(UserDetachNotification.class));
 Mockito.verify(clientState, Mockito.times(1)).setAttachedEndpointsList(Mockito.anyMap());
}

代码示例来源:origin: googleapis/google-cloud-java

@Test
public void testBatchReadOnlyTxnWithBound() throws Exception {
 Session sessionProto = Session.newBuilder().setName(SESSION_NAME).build();
 when(gapicRpc.createSession(
     eq(DB_NAME), (Map<String, String>) anyMap(), optionsCaptor.capture()))
   .thenReturn(sessionProto);
 com.google.protobuf.Timestamp timestamp = Timestamps.parse(TIMESTAMP);
 Transaction txnMetadata =
   Transaction.newBuilder().setId(TXN_ID).setReadTimestamp(timestamp).build();
 when(spannerOptions.getSpannerRpcV1()).thenReturn(gapicRpc);
 when(gapicRpc.beginTransaction(Mockito.<BeginTransactionRequest>any(), optionsCaptor.capture()))
   .thenReturn(txnMetadata);
 BatchReadOnlyTransaction batchTxn = client.batchReadOnlyTransaction(TimestampBound.strong());
 assertThat(batchTxn.getBatchTransactionId().getSessionId()).isEqualTo(SESSION_NAME);
 assertThat(batchTxn.getBatchTransactionId().getTransactionId()).isEqualTo(TXN_ID);
 Timestamp t = Timestamp.parseTimestamp(TIMESTAMP);
 assertThat(batchTxn.getReadTimestamp()).isEqualTo(t);
 assertThat(batchTxn.getReadTimestamp())
   .isEqualTo(batchTxn.getBatchTransactionId().getTimestamp());
}

代码示例来源:origin: Netflix/conductor

subWorkflowParamMap.put("name", "FooWorkFlow");
subWorkflowParamMap.put("version", 2);
when(parametersUtils.getTaskInputV2(anyMap(), any(Workflow.class), anyString(), any(TaskDef.class)))
    .thenReturn(subWorkflowParamMap);

代码示例来源:origin: aws-amplify/aws-sdk-android

@Test
  public void testReferenceToNotificationClient() {
    System.gc();
    receiver.onReceive(context, intent);
    verify(notificationClient, times(1)).handleNotificationOpen(Mockito.anyMap(),
        Mockito.any(Bundle.class));
  }
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testInvalidRequestBody() throws Exception {
  ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
  handler.handle(context, createRequest(HttpMethod.POST, "", "{\"xxx\": \"yyy\"}"));
  verify(searchIO, never()).insert(anyString(), anyMap());
  verify(channel).write(argument.capture());
  String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
  ErrorResponse errorResponse = getErrorResponse(errorResponseBody);
  assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size());
  assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
  assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testMalformedEventPut() throws Exception {
  final String malformedJSON = "{\"when\":, what]}"; //causes JsonParseException
  handler.handle(context, createRequest(HttpMethod.POST, "", malformedJSON));
  ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
  verify(searchIO, never()).insert(anyString(), anyMap());
  verify(channel).write(argument.capture());
  String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
  ErrorResponse errorResponse = getErrorResponse(errorResponseBody);
  assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size());
  assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
  assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testEmptyPut() throws Exception {
  Map<String, Object> event = new HashMap<String, Object>();
  ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
  handler.handle(context, createPutOneEventRequest(event));
  verify(searchIO, never()).insert(anyString(), anyMap());
  verify(channel).write(argument.capture());
  String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
  ErrorResponse errorResponse = getErrorResponse(errorResponseBody);
  System.out.println(errorResponse);
  assertEquals("Number of errors invalid", 2, errorResponse.getErrors().size());
  assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
  assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
}

代码示例来源:origin: rackerlabs/blueflood

@Test
  public void testMinimumEventPut() throws Exception {
    Map<String, Object> event = new HashMap<String, Object>();
    event.put(Event.FieldLabels.data.name(), "data");
    ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
    handler.handle(context, createPutOneEventRequest(event));
    verify(searchIO, never()).insert(anyString(), anyMap());
    verify(channel).write(argument.capture());

    String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
    ErrorResponse errorResponse = getErrorResponse(errorResponseBody);

    assertEquals("Number of errors invalid", 2, errorResponse.getErrors().size());
    assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
    assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
  }
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testEmptyWhatField() throws Exception {
  Map<String, Object> event = new HashMap<String, Object>();
  event.put(Event.FieldLabels.what.name(), "");
  event.put(Event.FieldLabels.when.name(), System.currentTimeMillis());
  ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
  handler.handle(context, createPutOneEventRequest(event));
  verify(searchIO, never()).insert(anyString(), anyMap());
  verify(channel).write(argument.capture());
  String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
  ErrorResponse errorResponse = getErrorResponse(errorResponseBody);
  assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size());
  assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
  assertEquals("Invalid error message", "may not be empty", errorResponse.getErrors().get(0).getMessage());
  assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testWhenFieldInThePast() throws Exception {
  long collectionTimeInPast = new DefaultClockImpl().now().getMillis() - 10000
      - Configuration.getInstance().getLongProperty( CoreConfig.BEFORE_CURRENT_COLLECTIONTIME_MS );
  Map<String, Object> event = new HashMap<String, Object>();
  event.put(Event.FieldLabels.what.name(), "xxxx");
  event.put(Event.FieldLabels.when.name(), collectionTimeInPast);
  ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
  handler.handle(context, createPutOneEventRequest(event));
  verify(searchIO, never()).insert(anyString(), anyMap());
  verify(channel).write(argument.capture());
  String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
  ErrorResponse errorResponse = getErrorResponse(errorResponseBody);
  assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size());
  assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
  assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." +
      " Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage());
  assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
}

代码示例来源:origin: rackerlabs/blueflood

@Test
public void testWhenFieldInTheFuture() throws Exception {
  long collectionTimeInFuture = new DefaultClockImpl().now().getMillis() + 10000
      + Configuration.getInstance().getLongProperty( CoreConfig.AFTER_CURRENT_COLLECTIONTIME_MS );
  Map<String, Object> event = new HashMap<String, Object>();
  event.put(Event.FieldLabels.what.name(), "xxxx");
  event.put(Event.FieldLabels.when.name(), collectionTimeInFuture);
  ArgumentCaptor<FullHttpResponse> argument = ArgumentCaptor.forClass(FullHttpResponse.class);
  handler.handle(context, createPutOneEventRequest(event));
  verify(searchIO, never()).insert(anyString(), anyMap());
  verify(channel).write(argument.capture());
  String errorResponseBody = argument.getValue().content().toString(Charset.defaultCharset());
  ErrorResponse errorResponse = getErrorResponse(errorResponseBody);
  assertEquals("Number of errors invalid", 1, errorResponse.getErrors().size());
  assertEquals("Invalid tenant", TENANT, errorResponse.getErrors().get(0).getTenantId());
  assertEquals("Invalid error message", "Out of bounds. Cannot be more than 259200000 milliseconds into the past." +
      " Cannot be more than 600000 milliseconds into the future", errorResponse.getErrors().get(0).getMessage());
  assertEquals("Invalid status", HttpResponseStatus.BAD_REQUEST, argument.getValue().getStatus());
}

代码示例来源:origin: westnordost/StreetComplete

private void doTestHandleChangesetConflict(ChangesetsDao changesetsDao, long userId,
                      long firstChangesetId, long secondChangesetId)
{
  OsmQuest quest = createAnsweredQuestWithAppliableChange();
  Element element = createElement();
  MergedElementDao elementDb = mock(MergedElementDao.class);
  OsmQuestDao questDb = mock(OsmQuestDao.class);
  DownloadedTilesDao downloadedTilesDao = mock(DownloadedTilesDao.class);
  OsmQuestGiver questGiver = mock(OsmQuestGiver.class);
  OpenChangesetsDao manageChangesetsDb = mock(OpenChangesetsDao.class);
  MapDataDao mapDataDao = createMapDataDaoThatReportsConflictOnUploadAndNodeDeleted();
  when(mapDataDao.openChangeset(anyMap())).thenReturn(secondChangesetId);
  SharedPreferences prefs = createPreferencesForUser(userId);
  OsmQuestChangesUpload u = new OsmQuestChangesUpload(mapDataDao, questDb, elementDb, null,
      null, manageChangesetsDb, changesetsDao, downloadedTilesDao, prefs, questGiver);
  assertFalse(u.uploadQuestChange(firstChangesetId, quest, element, false, false));
  verify(manageChangesetsDb).replace(new OpenChangesetKey("TestQuestType","test case"), secondChangesetId);
  verify(questDb).delete(quest.getId());
  verify(elementDb).delete(Element.Type.NODE, A_NODE_ID);
  verify(downloadedTilesDao).remove(any());
}

代码示例来源:origin: org.uberfire/uberfire-preferences-ui-client

@Before
public void setup() {
  perspective = spy(new AdminPagePerspective());
  doNothing().when(perspective).configurePerspective(anyMap());
}

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

@Test
public void testSetGlobalUserSettingAdmin() throws Exception {
 final String settingName = "settingName";
 final String settingValue = "settingValue";
 when( userSettingService.canAdminister() ).thenReturn( true );
 assertEquals( 4, globalSettings.size() );
 userSettingService.setGlobalUserSetting( settingName, settingValue );
 assertEquals( 5, globalSettings.size() );
 verify( repository ).setFileMetadata( eq( TENANT_FOLDER_ID ), anyMap() );
}

相关文章