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

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

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

Mockito.anyMapOf介绍

暂无

代码示例

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

@Before
public void setUp() {
 MockitoAnnotations.initMocks(this);
 SpannerImpl spanner = new SpannerImpl(rpc, 1, spannerOptions);
 String dbName = "projects/p1/instances/i1/databases/d1";
 String sessionName = dbName + "/sessions/s1";
 DatabaseId db = DatabaseId.of(dbName);
 Session sessionProto = Session.newBuilder().setName(sessionName).build();
 Mockito.when(
     rpc.createSession(
       Mockito.eq(dbName),
       Mockito.anyMapOf(String.class, String.class),
       optionsCaptor.capture()))
   .thenReturn(sessionProto);
 session = spanner.createSession(db);
 // We expect the same options, "options", on all calls on "session".
 options = optionsCaptor.getValue();
 Mockito.reset(rpc);
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void updateStatusJoinFailure() throws Exception {
 mockSelectExecutors(mWorkerInfo);
 Mockito
   .when(mJobDefinition.join(Mockito.eq(mJobconfig),
     Mockito.anyMapOf(WorkerInfo.class, Serializable.class)))
   .thenThrow(new UnsupportedOperationException("test exception"));
 JobCoordinator jobCoordinator = JobCoordinator.create(mCommandManager, mUfsManager,
   mWorkerInfoList, mJobId, mJobconfig, null);
 setTasksWithStatuses(jobCoordinator, Status.COMPLETED, Status.COMPLETED, Status.COMPLETED);
 Assert.assertEquals(Status.FAILED, jobCoordinator.getJobInfoWire().getStatus());
 Assert.assertEquals("test exception", jobCoordinator.getJobInfoWire().getErrorMessage());
}

代码示例来源:origin: Alluxio/alluxio

@Test
public void updateStatusCompleted() throws Exception {
 mockSelectExecutors(mWorkerInfo);
 JobCoordinator jobCoordinator = JobCoordinator.create(mCommandManager, mUfsManager,
   mWorkerInfoList, mJobId, mJobconfig, null);
 setTasksWithStatuses(jobCoordinator, Status.COMPLETED, Status.COMPLETED, Status.COMPLETED);
 Assert.assertEquals(Status.COMPLETED, jobCoordinator.getJobInfoWire().getStatus());
 Mockito.verify(mJobDefinition).join(Mockito.eq(jobCoordinator.getJobInfoWire().getJobConfig()),
   Mockito.anyMapOf(WorkerInfo.class, Serializable.class));
}

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

AvroByteArrayConverter<SyncRequest> requestCreator = new AvroByteArrayConverter<SyncRequest>(SyncRequest.class);
KaaDataMultiplexer multiplexer = Mockito.mock(KaaDataMultiplexer.class);
Mockito.when(multiplexer.compileRequest(Mockito.anyMapOf(TransportType.class, ChannelDirection.class))).thenReturn(requestCreator.toByteArray(new SyncRequest()));
KaaDataDemultiplexer demultiplexer = Mockito.mock(KaaDataDemultiplexer.class);
tcpChannel.setMultiplexer(multiplexer);
Mockito.verify(multiplexer, Mockito.times(2)).compileRequest(Mockito.anyMapOf(TransportType.class, ChannelDirection.class));
Mockito.verify(multiplexer, Mockito.times(3)).compileRequest(Mockito.anyMapOf(TransportType.class, ChannelDirection.class));
Mockito.verify(tcpChannel.socketMock, Mockito.times(3)).getOutputStream();

代码示例来源:origin: weexteam/weex-hackernews

@Test
public void testFetchRequestHttpbinCallback() throws Exception{
 WXStreamModule streamModule = createModule(new DefaultWXHttpAdapter());
 JSCallback progress = mock(JSCallback.class);
 JSCallback finish = mock(JSCallback.class);
 System.out.print("request start "+System.currentTimeMillis());
 streamModule.fetch("{method: 'POST',url: 'http://httpbin.org/post',type:'json'}",finish,progress);
 verify(progress,timeout(10*1000).atLeastOnce()).invokeAndKeepAlive(anyMapOf(String.class, Object.class));
 verify(finish,timeout(10*1000).times(1)).invoke(anyMapOf(String.class, Object.class));
 System.out.print("\nrequest finish"+System.currentTimeMillis());
}

代码示例来源:origin: weexteam/weex-hackernews

@Test
public void testSetItem() throws Exception {
 storage.setItem("","",listener);
 verify(listener,timeout(3000).times(1)).onReceived(anyMapOf(String.class,Object.class));
 storage.close();
}

代码示例来源:origin: weexteam/weex-hackernews

@Test
 public void testGetAllKeys() throws Exception {
  storage.getAllKeys(listener);

  verify(listener,timeout(3000).times(1)).onReceived(anyMapOf(String.class,Object.class));
  storage.close();
 }
}

代码示例来源:origin: weexteam/weex-hackernews

@Test
public void testRemoveItem() throws Exception {
 storage.removeItem("",listener);
 verify(listener,timeout(3000).times(1)).onReceived(anyMapOf(String.class,Object.class));
 storage.close();
}

代码示例来源:origin: weexteam/weex-hackernews

@Test
public void testGetItem() throws Exception {
 storage.getItem("",listener);
 verify(listener,timeout(3000).times(1)).onReceived(anyMapOf(String.class,Object.class));
 storage.close();
}

代码示例来源:origin: weexteam/weex-hackernews

@Test
public void testLength() throws Exception {
 storage.length(listener);
 verify(listener,timeout(3000).times(1)).onReceived(anyMapOf(String.class,Object.class));
 storage.close();
}

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

@Test
public void testVariableModificationForNonExistingProcessInstance() {
 doThrow(new ProcessEngineException("expected exception")).when(runtimeServiceMock).updateVariables(anyString(), anyMapOf(String.class, Object.class), anyCollectionOf(String.class));
 String variableKey = "aKey";
 int variableValue = 123;
 Map<String, Object> messageBodyJson = new HashMap<String, Object>();
 Map<String, Object> modifications = VariablesBuilder.create().variable(variableKey, variableValue).getVariables();
 messageBodyJson.put("modifications", modifications);
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID).contentType(ContentType.JSON).body(messageBodyJson)
  .then().expect().statusCode(Status.INTERNAL_SERVER_ERROR.getStatusCode()).contentType(ContentType.JSON)
  .body("type", equalTo(RestException.class.getSimpleName()))
  .body("message", equalTo("Cannot modify variables for process instance " + MockProvider.EXAMPLE_PROCESS_INSTANCE_ID + ": expected exception"))
  .when().post(PROCESS_INSTANCE_VARIABLES_URL);
}

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

@Test
public void testVariableModificationThrowsAuthorizationException() {
 String variableKey = "aKey";
 int variableValue = 123;
 Map<String, Object> messageBodyJson = new HashMap<String, Object>();
 Map<String, Object> modifications = VariablesBuilder.create().variable(variableKey, variableValue).getVariables();
 messageBodyJson.put("modifications", modifications);
 String message = "excpected exception";
 doThrow(new AuthorizationException(message)).when(runtimeServiceMock).updateVariables(anyString(), anyMapOf(String.class, Object.class), anyCollectionOf(String.class));
 given()
  .pathParam("id", MockProvider.EXAMPLE_PROCESS_INSTANCE_ID)
  .contentType(ContentType.JSON)
  .body(messageBodyJson)
 .then().expect()
  .statusCode(Status.FORBIDDEN.getStatusCode())
  .body("type", is(AuthorizationException.class.getSimpleName()))
  .body("message", is(message))
 .when()
  .post(PROCESS_INSTANCE_VARIABLES_URL);
}

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

@Test
public void testProcessInstantiationWithTransientVariables() throws IOException {
 Map<String, Object> json = new HashMap<String, Object>();
 json.put("variables", VariablesBuilder.create().variableTransient("foo", "bar", "string").getVariables());
 final VariableMap varMap = new VariableMapImpl();
 when(mockInstantiationBuilder.setVariables(anyMapOf(String.class, Object.class))).thenAnswer(new Answer<ProcessInstantiationBuilder>() {
  @Override
  public ProcessInstantiationBuilder answer(InvocationOnMock invocation) throws Throwable {
   varMap.putAll((VariableMap) invocation.getArguments()[0]);
   return mockInstantiationBuilder;
  }
 });
 given().pathParam("id", MockProvider.EXAMPLE_PROCESS_DEFINITION_ID)
  .contentType(POST_JSON_CONTENT_TYPE).body(json)
  .then().expect()
   .statusCode(Status.OK.getStatusCode())
   .body("id", equalTo(MockProvider.EXAMPLE_PROCESS_INSTANCE_ID))
  .when().post(START_PROCESS_INSTANCE_URL);
 VariableMap expectedVariables = Variables.createVariables().putValueTyped("foo", Variables.stringValue("bar", true));
 verify(runtimeServiceMock).createProcessInstanceById(eq(MockProvider.EXAMPLE_PROCESS_DEFINITION_ID));
 verify(mockInstantiationBuilder).setVariables(expectedVariables);
 assertEquals(expectedVariables.getValueTyped("foo").isTransient(), varMap.getValueTyped("foo").isTransient());
 verify(mockInstantiationBuilder).executeWithVariablesInReturn(anyBoolean(), anyBoolean());
}

代码示例来源:origin: 3wks/thundr

public static final Map<String, String> anyMap() {
    return Mockito.anyMapOf(String.class, String.class);
  }
}

代码示例来源:origin: org.uberfire/uberfire-runtime-plugins-backend

@Test
public void testInit() throws Exception {
  when(iterable.iterator()).thenReturn(iterator);
  when(fileSystem.getRootDirectories()).thenReturn(iterable);
  when(config.getInitParameter(anyString())).thenReturn("/fake");
  when(ioService.newFileSystem(any(URI.class),
                 anyMapOf(String.class,
                     Class.class))).thenReturn(fileSystem);
  servlet.init(config);
  verify(mediaServletURI).setURI(eq("fake/"));
}

代码示例来源:origin: kiegroup/appformer

@Test
public void testInit() throws Exception {
  when(iterable.iterator()).thenReturn(iterator);
  when(fileSystem.getRootDirectories()).thenReturn(iterable);
  when(config.getInitParameter(anyString())).thenReturn("/fake");
  when(ioService.newFileSystem(any(URI.class),
                 anyMapOf(String.class,
                     Class.class))).thenReturn(fileSystem);
  servlet.init(config);
  verify(mediaServletURI).setURI(eq("fake/"));
}

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

@Test
public void getOneTimeIdAndPassword() throws Exception {
  doReturn(EXPECTED_RESULT).when(httpClient).post(
      any(Uri.class),
      anyMapOf(String.class, String.class),
      anyMapOf(String.class, String.class),
      any(ResponseDataParser.class));
  LineApiResponse<OneTimePassword> actualResult =
      target.getOneTimeIdAndPassword(CHANNEL_ID);
  assertSame(EXPECTED_RESULT, actualResult);
  verify(httpClient, times(1)).post(
      eq(Uri.parse(API_BASE_URL + "/oauth2/v2.1/otp")),
      eq(Collections.<String, String>emptyMap()),
      eq(Collections.singletonMap("client_id", String.valueOf(CHANNEL_ID))),
      responseParserCaptor.capture());
  verifyOneTimeIdAndPasswordParser(responseParserCaptor.getValue());
}

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

@Test
public void testGetFriendshipStatus() {
  doReturn(EXPECTED_RESULT).when(httpClient).get(
      any(Uri.class),
      anyMapOf(String.class, String.class),
      anyMapOf(String.class, String.class),
      any(ResponseDataParser.class));
  LineApiResponse<LineFriendshipStatus> actualResult = target.getFriendshipStatus(ACCESS_TOKEN);
  assertSame(EXPECTED_RESULT, actualResult);
  verify(httpClient, times(1)).get(
      eq(Uri.parse(API_BASE_URL + "/friendship/v1/status")),
      eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())),
      eq(Collections.emptyMap()),
      responseParserCaptor.capture());
  assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.FriendshipStatusParser);
}

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

@Test
public void testGetProfile() {
  doReturn(EXPECTED_RESULT).when(httpClient).get(
      any(Uri.class),
      anyMapOf(String.class, String.class),
      anyMapOf(String.class, String.class),
      any(ResponseDataParser.class));
  LineApiResponse<LineProfile> actualResult = target.getProfile(ACCESS_TOKEN);
  assertSame(EXPECTED_RESULT, actualResult);
  verify(httpClient, times(1)).get(
      eq(Uri.parse(API_BASE_URL + "/v2/profile")),
      eq(Collections.singletonMap("Authorization", "Bearer " + ACCESS_TOKEN.getAccessToken())),
      eq(Collections.emptyMap()),
      responseParserCaptor.capture());
  assertTrue(responseParserCaptor.getValue() instanceof TalkApiClient.ProfileParser);
}

代码示例来源:origin: 3wks/thundr

@SuppressWarnings("unchecked")
@Test
public void shouldNotBindIfNoParametersArePresent() {
  addFormField("field1", "value1");
  addFormField("field2", "value2");
  addFileField("data", new byte[] { 1, 2, 3 });
  binder = spy(binder);
  binder.bindAll(parameterDescriptions, request, response);
  verify(binder, times(0)).extractParameters(Mockito.any(Request.class), Mockito.anyMap(), Mockito.anyMapOf(String.class, MultipartFile.class));
  assertThat(binder.shouldTryToBind(parameterDescriptions), is(false));
}

相关文章