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


Java Whitebox.invokeMethod方法代码示例

本文整理汇总了Java中org.powermock.reflect.Whitebox.invokeMethod方法的典型用法代码示例。如果您正苦于以下问题:Java Whitebox.invokeMethod方法的具体用法?Java Whitebox.invokeMethod怎么用?Java Whitebox.invokeMethod使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.powermock.reflect.Whitebox的用法示例。


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

示例1: testSendRecordsPropagatesTimestamp

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testSendRecordsPropagatesTimestamp() throws Exception {
    final Long timestamp = System.currentTimeMillis();

    createWorkerTask();

    List<SourceRecord> records = Collections.singletonList(
            new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD, timestamp)
    );

    Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecordAnyTimes();

    PowerMock.replayAll();

    Whitebox.setInternalState(workerTask, "toSend", records);
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(timestamp, sent.getValue().timestamp());

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:21,代码来源:WorkerSourceTaskTest.java

示例2: requestLocation

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
/**
 * Tests for requestLocation.
 *
 * @throws Exception
 */
@Test
public void requestLocation() throws Exception {
  GoogleApiClient mockGoogleApiClient = mock(GoogleApiClient.class);
  doReturn(true).when(mockGoogleApiClient).isConnected();

  LocationManager mockLocationManager = spy(mLocationManager);
  Whitebox.setInternalState(mockLocationManager, "googleApiClient", mockGoogleApiClient);

  FusedLocationProviderApi mockLocationProviderApi = mock(FusedLocationProviderApi.class);
  Whitebox.setInternalState(LocationServices.class, "FusedLocationApi", mockLocationProviderApi);

  // Testing when a customer did not disableLocationCollection.
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verify(mockLocationProviderApi).requestLocationUpdates(any(GoogleApiClient.class),
      any(LocationRequest.class), any(LocationListener.class));

  // Testing when a customer disableLocationCollection.
  Leanplum.disableLocationCollection();
  Whitebox.invokeMethod(mockLocationManager, "requestLocation");
  verifyNoMoreInteractions(mockLocationProviderApi);
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:27,代码来源:LeanplumLocationManagerTest.java

示例3: testSendRecordsNoTimestamp

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testSendRecordsNoTimestamp() throws Exception {
    final Long timestamp = -1L;
    createWorkerTask();

    List<SourceRecord> records = Collections.singletonList(
            new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD, timestamp)
    );

    Capture<ProducerRecord<byte[], byte[]>> sent = expectSendRecordAnyTimes();

    PowerMock.replayAll();

    Whitebox.setInternalState(workerTask, "toSend", records);
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(null, sent.getValue().timestamp());

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:WorkerSourceTaskTest.java

示例4: testSendRecordsTaskCommitRecordFail

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testSendRecordsTaskCommitRecordFail() throws Exception {
    createWorkerTask();

    // Differentiate only by Kafka partition so we can reuse conversion expectations
    SourceRecord record1 = new SourceRecord(PARTITION, OFFSET, "topic", 1, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD);
    SourceRecord record2 = new SourceRecord(PARTITION, OFFSET, "topic", 2, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD);
    SourceRecord record3 = new SourceRecord(PARTITION, OFFSET, "topic", 3, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD);

    // Source task commit record failure will not cause the task to abort
    expectSendRecordOnce(false);
    expectSendRecordTaskCommitRecordFail(false, false);
    expectSendRecordOnce(false);

    PowerMock.replayAll();

    Whitebox.setInternalState(workerTask, "toSend", Arrays.asList(record1, record2, record3));
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(false, Whitebox.getInternalState(workerTask, "lastSendFailed"));
    assertNull(Whitebox.getInternalState(workerTask, "toSend"));

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:24,代码来源:WorkerSourceTaskTest.java

示例5: successGetShiftList

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successGetShiftList() throws Exception {
    LocalTime startTime = LocalTime.of(6, 30);
    LocalTime endTime = LocalTime.of(9, 0);
    List<Shift> shiftListTest = Arrays.asList(
            new Shift(0, DayOfWeek.SUNDAY, startTime, endTime),
            new Shift(1, DayOfWeek.MONDAY, startTime, endTime),
            new Shift(2, DayOfWeek.TUESDAY, startTime, endTime),
            new Shift(3, DayOfWeek.WEDNESDAY, startTime, endTime),
            new Shift(4, DayOfWeek.THURSDAY, startTime, endTime));

    when(requestMock.headers("Set-Cookie")).thenReturn("cookie");
    when(DataStore.getShifts("cookie")).thenReturn(shiftListTest);

    List<Shift> getShiftListResult = Whitebox.invokeMethod(shiftControllerTest, "getShiftList", requestMock, responseMock);
    Assert.assertEquals(shiftListTest, getShiftListResult);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:18,代码来源:ShiftControllerTest.java

示例6: successGetFullCourseList

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successGetFullCourseList() throws Exception {
    List<Course> courseListTest = new ArrayList<>();
    courseListTest.add(new Course(1, "CS302", null));
    courseListTest.add(new Course(2, "CS301", null));

    List<Course> expectedCourseListTest = new ArrayList<>();
    expectedCourseListTest.add(new Course(1, "CS302", null));

    when(requestMock.headers("Set-Cookie")).thenReturn("cookie");
    when(requestMock.queryParamOrDefault("limit", null)).thenReturn("1");
    when(DataStore.getCourses("cookie")).thenReturn(courseListTest);

    List<Course> getCourseListResult = Whitebox.invokeMethod(courseControllerTest, "getCourseList", requestMock, responseMock);

    Assert.assertEquals(expectedCourseListTest, getCourseListResult);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:18,代码来源:CourseControllerTest.java

示例7: testSendRecordsRetries

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testSendRecordsRetries() throws Exception {
    createWorkerTask();

    // Differentiate only by Kafka partition so we can reuse conversion expectations
    SourceRecord record1 = new SourceRecord(PARTITION, OFFSET, "topic", 1, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD);
    SourceRecord record2 = new SourceRecord(PARTITION, OFFSET, "topic", 2, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD);
    SourceRecord record3 = new SourceRecord(PARTITION, OFFSET, "topic", 3, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD);

    // First round
    expectSendRecordOnce(false);
    // Any Producer retriable exception should work here
    expectSendRecordSyncFailure(new org.apache.kafka.common.errors.TimeoutException("retriable sync failure"));

    // Second round
    expectSendRecordOnce(true);
    expectSendRecordOnce(false);

    PowerMock.replayAll();

    // Try to send 3, make first pass, second fail. Should save last two
    Whitebox.setInternalState(workerTask, "toSend", Arrays.asList(record1, record2, record3));
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(true, Whitebox.getInternalState(workerTask, "lastSendFailed"));
    assertEquals(Arrays.asList(record2, record3), Whitebox.getInternalState(workerTask, "toSend"));

    // Next they all succeed
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(false, Whitebox.getInternalState(workerTask, "lastSendFailed"));
    assertNull(Whitebox.getInternalState(workerTask, "toSend"));

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:34,代码来源:WorkerSourceTaskTest.java

示例8: testLeaderPerformAssignment2

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testLeaderPerformAssignment2() throws Exception {
    // Since all the protocol responses are mocked, the other tests validate doSync runs, but don't validate its
    // output. So we test it directly here.

    EasyMock.expect(configStorage.snapshot()).andReturn(configState2);

    PowerMock.replayAll();

    // Prime the current configuration state
    coordinator.metadata();

    Map<String, ByteBuffer> configs = new HashMap<>();
    // Mark everyone as in sync with configState1
    configs.put("leader", ConnectProtocol.serializeMetadata(new ConnectProtocol.WorkerState(LEADER_URL, 1L)));
    configs.put("member", ConnectProtocol.serializeMetadata(new ConnectProtocol.WorkerState(MEMBER_URL, 1L)));
    Map<String, ByteBuffer> result = Whitebox.invokeMethod(coordinator, "performAssignment", "leader", WorkerCoordinator.DEFAULT_SUBPROTOCOL, configs);

    // configState2 has 2 connector, 3 tasks and should trigger round robin assignment
    ConnectProtocol.Assignment leaderAssignment = ConnectProtocol.deserializeAssignment(result.get("leader"));
    assertEquals(false, leaderAssignment.failed());
    assertEquals("leader", leaderAssignment.leader());
    assertEquals(1, leaderAssignment.offset());
    assertEquals(Collections.singletonList(connectorId1), leaderAssignment.connectors());
    assertEquals(Arrays.asList(taskId1x0, taskId2x0), leaderAssignment.tasks());

    ConnectProtocol.Assignment memberAssignment = ConnectProtocol.deserializeAssignment(result.get("member"));
    assertEquals(false, memberAssignment.failed());
    assertEquals("leader", memberAssignment.leader());
    assertEquals(1, memberAssignment.offset());
    assertEquals(Collections.singletonList(connectorId2), memberAssignment.connectors());
    assertEquals(Collections.singletonList(taskId1x1), memberAssignment.tasks());

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:36,代码来源:WorkerCoordinatorTest.java

示例9: testDefaultNotificationChannels

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testDefaultNotificationChannels() throws Exception {
  String defaultChannelId = "id_1";

  LeanplumNotificationChannel.configureDefaultNotificationChannel(Leanplum.getContext(),
      defaultChannelId);

  String channelId = Whitebox.invokeMethod(
      LeanplumNotificationChannel.class, "retrieveDefaultNotificationChannel", Leanplum.getContext());

  assertNotNull(channelId);
  assertEquals(defaultChannelId, channelId);
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:14,代码来源:LeanplumNotificationChannelTests.java

示例10: successFetchGeneratedSchedules

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successFetchGeneratedSchedules() throws Exception {
    List<Schedule> fetchGeneratedSchedules = Whitebox.invokeMethod(scheduleControllerTest,
            "fetchGeneratedSchedules", requestMock, responseMock);
    // TODO: implement test case
    Assert.assertEquals(null, fetchGeneratedSchedules);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:8,代码来源:ScheduleControllerTest.java

示例11: successGenerateSchedule

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successGenerateSchedule() throws Exception {
    boolean generateScheduleResult = Whitebox.invokeMethod(scheduleControllerTest,
            "generateSchedule", requestMock, responseMock);
    // TODO: implement test case
    Assert.assertEquals(true, generateScheduleResult);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:8,代码来源:ScheduleControllerTest.java

示例12: successGetSessionList

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successGetSessionList() throws Exception {
    List<String> getSessionListResult = Whitebox.invokeMethod(sessionControllerTest, "getSessionList",
            requestMock, responseMock);

    PowerMockito.verifyNew(File.class).withArguments(Mockito.eq(WORKSPACE_PATH));

    List<String> expectedFilenameList = new ArrayList<>();
    expectedFilenameList.add("session_1511824120.json");
    expectedFilenameList.add("session_1511824113.json");
    expectedFilenameList.add("2.json");
    expectedFilenameList.add("1.json");

    Assert.assertEquals(expectedFilenameList, getSessionListResult);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:16,代码来源:SessionControllerTest.java

示例13: testLeaderPerformAssignment1

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testLeaderPerformAssignment1() throws Exception {
    // Since all the protocol responses are mocked, the other tests validate doSync runs, but don't validate its
    // output. So we test it directly here.

    EasyMock.expect(configStorage.snapshot()).andReturn(configState1);

    PowerMock.replayAll();

    // Prime the current configuration state
    coordinator.metadata();

    Map<String, ByteBuffer> configs = new HashMap<>();
    // Mark everyone as in sync with configState1
    configs.put("leader", ConnectProtocol.serializeMetadata(new ConnectProtocol.WorkerState(LEADER_URL, 1L)));
    configs.put("member", ConnectProtocol.serializeMetadata(new ConnectProtocol.WorkerState(MEMBER_URL, 1L)));
    Map<String, ByteBuffer> result = Whitebox.invokeMethod(coordinator, "performAssignment", "leader", WorkerCoordinator.DEFAULT_SUBPROTOCOL, configs);

    // configState1 has 1 connector, 1 task
    ConnectProtocol.Assignment leaderAssignment = ConnectProtocol.deserializeAssignment(result.get("leader"));
    assertEquals(false, leaderAssignment.failed());
    assertEquals("leader", leaderAssignment.leader());
    assertEquals(1, leaderAssignment.offset());
    assertEquals(Collections.singletonList(connectorId1), leaderAssignment.connectors());
    assertEquals(Collections.emptyList(), leaderAssignment.tasks());

    ConnectProtocol.Assignment memberAssignment = ConnectProtocol.deserializeAssignment(result.get("member"));
    assertEquals(false, memberAssignment.failed());
    assertEquals("leader", memberAssignment.leader());
    assertEquals(1, memberAssignment.offset());
    assertEquals(Collections.emptyList(), memberAssignment.connectors());
    assertEquals(Collections.singletonList(taskId1x0), memberAssignment.tasks());

    PowerMock.verifyAll();
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:36,代码来源:WorkerCoordinatorTest.java

示例14: successGetSession

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successGetSession() throws Exception {
    Session getSessionResult = Whitebox.invokeMethod(sessionControllerTest, "getSession",
            requestMock, responseMock);

    PowerMockito.verifyNew(FileReader.class).withArguments(Mockito.eq(WORKSPACE_PATH + "2.json"));

    Assert.assertEquals("2.json", getSessionResult.getName());
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:10,代码来源:SessionControllerTest.java

示例15: successSaveNamedSession

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void successSaveNamedSession() throws Exception {
    // TODO: implement test case
    Mockito.when(requestMock.params(Mockito.eq(":name"))).thenReturn("");
    Boolean saveSessionResult = Whitebox.invokeMethod(sessionControllerTest, "saveSession",
            requestMock, responseMock);
    Assert.assertEquals(false, saveSessionResult);
}
 
开发者ID:cocolocomoco21,项目名称:ULCRS,代码行数:9,代码来源:SessionControllerTest.java


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