當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。