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


Java Whitebox.setInternalState方法代码示例

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


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

示例1: setup

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Override
public void setup() {
    super.setup();
    Map<String, String> workerProps = new HashMap<>();
    workerProps.put("key.converter", "org.apache.kafka.connect.json.JsonConverter");
    workerProps.put("value.converter", "org.apache.kafka.connect.json.JsonConverter");
    workerProps.put("internal.key.converter", "org.apache.kafka.connect.json.JsonConverter");
    workerProps.put("internal.value.converter", "org.apache.kafka.connect.json.JsonConverter");
    workerProps.put("internal.key.converter.schemas.enable", "false");
    workerProps.put("internal.value.converter.schemas.enable", "false");
    workerProps.put("offset.storage.file.filename", "/tmp/connect.offsets");
    workerProps.put("offset.flush.interval.ms",
            Long.toString(DEFAULT_OFFSET_COMMIT_INTERVAL_MS));
    WorkerConfig config = new StandaloneConfig(workerProps);
    committer = new SourceTaskOffsetCommitter(config, executor, committers);
    Whitebox.setInternalState(SourceTaskOffsetCommitter.class, "log", mockLog);
}
 
开发者ID:YMCoding,项目名称:kafka-0.11.0.0-src-with-comment,代码行数:18,代码来源:SourceTaskOffsetCommitterTest.java

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

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

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

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

示例6: setup

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Before
public void setup() {
    super.setup();
    // noinspection unchecked
    stateLiveData = mock(SafeMutableLiveData.class);
    mNavigatorHelper = mock(NavigatorHelper.class);
    Whitebox.setInternalState(viewModel, "stateLiveData", stateLiveData);
    Whitebox.setInternalState(viewModel, "navigatorHelper", mNavigatorHelper);
}
 
开发者ID:duyp,项目名称:mvvm-template,代码行数:10,代码来源:BaseViewModelTest.java

示例7: testFromSubscriptionDataA

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testFromSubscriptionDataA() {
  SubscriptionBuiltinTopicData subscriptionBuiltinTopicData = new SubscriptionBuiltinTopicData();
  Whitebox.setInternalState(subscriptionBuiltinTopicData, "participant_key", builtinTopicKeyA);

  ParticipantBuiltinTopicData result = BuiltinTopicHelper.getParticipantBuiltinTopicData(
      domainParticipant, subscriptionBuiltinTopicData);

  assertTrue(("A").equals(result.participant_name.name));
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:11,代码来源:BuiltinTopicHelperTest.java

示例8: createPublicationBuiltinTopicData

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
private PublicationBuiltinTopicData createPublicationBuiltinTopicData(
    String topic,
    String type,
    String... partitions
) {
  PublicationBuiltinTopicData builtinTopicData = mock(PublicationBuiltinTopicData.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,代码行数:16,代码来源:DynamicPartitionObserverTest.java

示例9: verifyNeedToSendLocation

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
/**
 * A helper method for testing needToSendLocation.
 *
 * @param lastLocationSentDate Date of the last location sent.
 * @param lastLocationSentAccuracyType Accuracy type of the last location sent.
 * @param currentLocationAccuracyType Accuracy type of the current location.
 * @param expected Expected return value of needToSendLocation given the parameters.
 * @throws Exception
 */
private void verifyNeedToSendLocation(Date lastLocationSentDate,
    LeanplumLocationAccuracyType lastLocationSentAccuracyType,
    LeanplumLocationAccuracyType currentLocationAccuracyType, boolean expected)
    throws Exception {
  Whitebox.setInternalState(mLocationManager, "lastLocationSentDate", lastLocationSentDate);
  Whitebox.setInternalState(mLocationManager, "lastLocationSentAccuracyType",
      lastLocationSentAccuracyType);

  Boolean result = Whitebox.invokeMethod(mLocationManager, "needToSendLocation",
      currentLocationAccuracyType);

  assertEquals(expected, result);
}
 
开发者ID:Leanplum,项目名称:Leanplum-Android-SDK,代码行数:23,代码来源:LeanplumLocationManagerTest.java

示例10: testSimpleContextConstructor

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testSimpleContextConstructor() {
  Whitebox.setInternalState(ReactBuildConfig.class, "DEBUG", true);
  ReactApplicationContext context = mock(ReactApplicationContext.class);
  ModuleSpec spec = ModuleSpec.simple(SimpleContextModule.class, context);

  NativeModule module = spec.getProvider().get();
  assertThat(module).isInstanceOf(SimpleContextModule.class);
  SimpleContextModule contextModule = (SimpleContextModule) module;
  assertThat(contextModule.getReactApplicationContext()).isSameAs(context);
}
 
开发者ID:qq565999484,项目名称:RNLearn_Project1,代码行数:12,代码来源:ModuleSpecTest.java

示例11: testIgnoreSubscriptionFalse

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testIgnoreSubscriptionFalse() throws Exception {
  // setup mock for participant data
  ParticipantBuiltinTopicData participantBuiltinTopicData = mock(ParticipantBuiltinTopicData.class);
  {
    ServiceQosPolicy serviceQosPolicy = PowerMockito.mock(ServiceQosPolicy.class);
    serviceQosPolicy.kind = ServiceQosPolicyKind.NO_SERVICE_QOS;
    Whitebox.setInternalState(participantBuiltinTopicData, "service", serviceQosPolicy);
  }
  PowerMockito.whenNew(ParticipantBuiltinTopicData.class).withAnyArguments().thenReturn(participantBuiltinTopicData);

  // setup mock for topic helper
  PowerMockito.mockStatic(BuiltinTopicHelper.class);
  when(BuiltinTopicHelper.getParticipantBuiltinTopicData(
      any(DomainParticipant.class), any(BuiltinTopicKey_t.class))
  ).thenReturn(participantBuiltinTopicData);

  // setup mock for subscription topic data
  SubscriptionBuiltinTopicData data = mock(SubscriptionBuiltinTopicData.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 subscription
  assertFalse(filter.ignoreSubscription(domainParticipant, instanceHandle, data));
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:29,代码来源:RoutingServiceEntitiesFilterTest.java

示例12: setUpTest_GeneralFileSystemOperations

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
/**
 * Setup method
 */
@Before
public void setUpTest_GeneralFileSystemOperations() {

    mockedTestObject = new FileTransferClient(TransferProtocol.FTP);

    // create a mock file transfer client
    ftpMock = createMock(FtpClient.class);
    factoryMock = createMock(ClientFactory.class);

    // inject the mock client into the test object
    Whitebox.setInternalState(mockedTestObject, ftpMock);
}
 
开发者ID:Axway,项目名称:ats-framework,代码行数:16,代码来源:Test_GenericTransferClient.java

示例13: testIgnoreSubscriptionTrue

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testIgnoreSubscriptionTrue() throws Exception {
  // setup mock for participant data
  ParticipantBuiltinTopicData participantBuiltinTopicData = mock(ParticipantBuiltinTopicData.class);
  PowerMockito.whenNew(ParticipantBuiltinTopicData.class).withAnyArguments().thenReturn(participantBuiltinTopicData);

  PowerMockito.mockStatic(PropertyQosPolicyHelper.class);
  when(PropertyQosPolicyHelper.lookup_property(
      any(), anyString())//eq("rti.routing_service.group_name"))
  ).thenReturn(new Property_t("rti.routing_service.group_name", "TEST", false));

  // setup mock for topic helper
  PowerMockito.mockStatic(BuiltinTopicHelper.class);
  when(BuiltinTopicHelper.getParticipantBuiltinTopicData(
      any(DomainParticipant.class), any(BuiltinTopicKey_t.class))
  ).thenReturn(participantBuiltinTopicData);

  // setup mock for subscription topic data
  SubscriptionBuiltinTopicData data = mock(SubscriptionBuiltinTopicData.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 subscription
  assertTrue(filter.ignoreSubscription(domainParticipant, instanceHandle, data));
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:29,代码来源:RoutingServiceGroupEntitiesFilterTest.java

示例14: testIgnoreSubscriptionFalse

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testIgnoreSubscriptionFalse() throws Exception {
  // setup mock for participant data
  ParticipantBuiltinTopicData participantBuiltinTopicData = mock(ParticipantBuiltinTopicData.class);
  PowerMockito.whenNew(ParticipantBuiltinTopicData.class).withAnyArguments().thenReturn(participantBuiltinTopicData);

  PowerMockito.mockStatic(PropertyQosPolicyHelper.class);
  when(PropertyQosPolicyHelper.lookup_property(
      any(), anyString())//eq("rti.routing_service.group_name"))
  ).thenReturn(new Property_t("rti.routing_service.group_name", "", false));

  // setup mock for topic helper
  PowerMockito.mockStatic(BuiltinTopicHelper.class);
  when(BuiltinTopicHelper.getParticipantBuiltinTopicData(
      any(DomainParticipant.class), any(BuiltinTopicKey_t.class))
  ).thenReturn(participantBuiltinTopicData);

  // setup mock for subscription topic data
  SubscriptionBuiltinTopicData data = mock(SubscriptionBuiltinTopicData.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 subscription
  assertFalse(filter.ignoreSubscription(domainParticipant, instanceHandle, data));
}
 
开发者ID:aguther,项目名称:dds-examples,代码行数:29,代码来源:RoutingServiceGroupEntitiesFilterTest.java

示例15: testIgnoreSubscriptionFalse

import org.powermock.reflect.Whitebox; //导入方法依赖的package包/类
@Test
public void testIgnoreSubscriptionFalse() throws Exception {
  // setup mock for subscription topic data
  SubscriptionBuiltinTopicData data = mock(SubscriptionBuiltinTopicData.class);
  BuiltinTopicKey_t key = PowerMockito.mock(BuiltinTopicKey_t.class);
  Whitebox.setInternalState(data, "participant_key", key);
  Whitebox.setInternalState(data, "topic_name", "topic");

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

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


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