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


Java Whitebox类代码示例

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


Whitebox类属于org.powermock.reflect包,在下文中一共展示了Whitebox类的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: createBinaryFilePositiveRandomContent

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
@Test
public void createBinaryFilePositiveRandomContent() throws IOException {

    //Replace the randomGenerator with cutsom one.
    Random random = new Random(1);
    Random originalRandom = (Random) Whitebox.getInternalState(testObject.getClass(),
                                                               "randomGenerator");
    Whitebox.setInternalState(testObject.getClass(), "randomGenerator", random);

    testObject.createBinaryFile(file.getPath(), 10, true);

    //Restore original random generator
    Whitebox.setInternalState(testObject.getClass(), "randomGenerator", originalRandom);

    assertTrue(file.exists());
    assertEquals(10L, file.length());

    byte[] expectedBytes = new byte[]{ 115, -40, 111, -110, -4, -16, -27, -35, -43, 104 };
    byte[] actualBytes = new byte[10];
    BufferedInputStream bis = new BufferedInputStream(new FileInputStream(file));
    bis.read(actualBytes);
    assertTrue(Arrays.equals(expectedBytes, actualBytes));
    bis.close();

}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:26,代码来源:Test_LocalFileSystemOperations.java

示例3: testSendRecordsConvertsData

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

    List<SourceRecord> records = new ArrayList<>();
    // Can just use the same record for key and value
    records.add(new SourceRecord(PARTITION, OFFSET, "topic", null, KEY_SCHEMA, KEY, RECORD_SCHEMA, RECORD));

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

    PowerMock.replayAll();

    Whitebox.setInternalState(workerTask, "toSend", records);
    Whitebox.invokeMethod(workerTask, "sendRecords");
    assertEquals(SERIALIZED_KEY, sent.getValue().key());
    assertEquals(SERIALIZED_RECORD, sent.getValue().value());

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

示例4: createSubscriptionBuiltinTopicData

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
private SubscriptionBuiltinTopicData createSubscriptionBuiltinTopicData(
    String topic,
    String type,
    String... partitions
) {
  SubscriptionBuiltinTopicData builtinTopicData = mock(SubscriptionBuiltinTopicData.class);
  PartitionQosPolicy partitionQosPolicy = mock(PartitionQosPolicy.class);
  Whitebox.setInternalState(builtinTopicData, "partition", partitionQosPolicy);
  Whitebox.setInternalState(partitionQosPolicy, "name", new StringSeq());

  builtinTopicData.topic_name = topic;
  builtinTopicData.type_name = type;
  builtinTopicData.partition.name.addAll(Arrays.asList(partitions));

  return builtinTopicData;
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:17,代码来源:DynamicPartitionObserverTest.java

示例5: testIgnorePublicationFalseNoParticipantData

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
@Test
public void testIgnorePublicationFalseNoParticipantData() throws Exception {
  // setup mock for topic helper
  PowerMockito.mockStatic(BuiltinTopicHelper.class);
  when(BuiltinTopicHelper.getParticipantBuiltinTopicData(
      any(DomainParticipant.class), any(BuiltinTopicKey_t.class))
  ).thenReturn(null);

  // setup mock for publication topic data
  PublicationBuiltinTopicData data = mock(PublicationBuiltinTopicData.class);
  BuiltinTopicKey_t key = PowerMockito.mock(BuiltinTopicKey_t.class);
  Whitebox.setInternalState(data, "participant_key", key);

  // setup mock for instance handle
  InstanceHandle_t instanceHandle = mock(InstanceHandle_t.class);

  // call ignore publication
  assertFalse(filter.ignorePublication(domainParticipant, instanceHandle, data));
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:20,代码来源:RoutingServiceGroupEntitiesFilterTest.java

示例6: getHttpClient

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
protected static HttpClient
        getHttpClient( MockHttpURLConnection mockHttpURLConnection ) throws AgentException {

    // construct the client
    List<ActionHeader> httpHeaders = new ArrayList<ActionHeader>();
    httpHeaders.add( new ActionHeader( "User-Agent",
                                       "Mozilla/5.0 (Windows; U; Windows NT 5.1; en-US; rv:1.9.2.3) Gecko/20100401 Firefox/3.6.3" ) );
    NetworkingStopWatch stopWatch = new NetworkingStopWatch( "action" );
    stopWatch.step0_SetNewContext( "my_action[1]" );
    stopWatch.setStateFromBeforeStep1ToAfterStep4(); /// so it can be suspended for getting response
    stopWatch.step5_StartInterimTimer();
    HttpClient client = new HttpClient( "http://", "GET", httpHeaders, stopWatch );

    // inject a mock connection object
    Whitebox.setInternalState( client, "urlConnection", mockHttpURLConnection );

    return client;
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:19,代码来源:TemplateActionsBaseTest.java

示例7: 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

示例8: before

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
@Override
public void before() throws Exception {
  super.before();

  mMessageMatchResult = new ActionManager.MessageMatchResult();
  Whitebox.setInternalState(mMessageMatchResult, "matchedTrigger", true);
  Whitebox.setInternalState(mMessageMatchResult, "matchedLimit", true);
  assertTrue(mMessageMatchResult.matchedTrigger);
  assertTrue(mMessageMatchResult.matchedLimit);


  mContextualValues = new ActionContext.ContextualValues();
  // create mock object
  mMockActionManager = mock(ActionManager.class);
  // workaround for singleton objects
  Whitebox.setInternalState(ActionManager.class, "instance", mMockActionManager);
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:18,代码来源:MessagesTest.java

示例9: 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

示例10: 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

示例11: testCacheSchemaToConnectConversion

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
@Test
public void testCacheSchemaToConnectConversion() {
    Cache<JsonNode, Schema> cache = Whitebox.getInternalState(converter, "toConnectSchemaCache");
    assertEquals(0, cache.size());

    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\" }, \"payload\": true }".getBytes());
    assertEquals(1, cache.size());

    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\" }, \"payload\": true }".getBytes());
    assertEquals(1, cache.size());

    // Different schema should also get cached
    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\", \"optional\": true }, \"payload\": true }".getBytes());
    assertEquals(2, cache.size());

    // Even equivalent, but different JSON encoding of schema, should get different cache entry
    converter.toConnectData(TOPIC, "{ \"schema\": { \"type\": \"boolean\", \"optional\": false }, \"payload\": true }".getBytes());
    assertEquals(3, cache.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:20,代码来源:JsonConverterTest.java

示例12: testCacheSchemaToJsonConversion

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
@Test
public void testCacheSchemaToJsonConversion() {
    Cache<Schema, ObjectNode> cache = Whitebox.getInternalState(converter, "fromConnectSchemaCache");
    assertEquals(0, cache.size());

    // Repeated conversion of the same schema, even if the schema object is different should return the same Java
    // object
    converter.fromConnectData(TOPIC, SchemaBuilder.bool().build(), true);
    assertEquals(1, cache.size());

    converter.fromConnectData(TOPIC, SchemaBuilder.bool().build(), true);
    assertEquals(1, cache.size());

    // Validate that a similar, but different schema correctly returns a different schema.
    converter.fromConnectData(TOPIC, SchemaBuilder.bool().optional().build(), true);
    assertEquals(2, cache.size());
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:JsonConverterTest.java

示例13: testSendRecordsCorruptTimestamp

import org.powermock.reflect.Whitebox; //导入依赖的package包/类
@Test(expected = InvalidRecordException.class)
public void testSendRecordsCorruptTimestamp() throws Exception {
    final Long timestamp = -3L;
    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

示例14: 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

示例15: 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


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