當前位置: 首頁>>代碼示例>>Java>>正文


Java Whitebox.getInternalState方法代碼示例

本文整理匯總了Java中org.powermock.reflect.Whitebox.getInternalState方法的典型用法代碼示例。如果您正苦於以下問題:Java Whitebox.getInternalState方法的具體用法?Java Whitebox.getInternalState怎麽用?Java Whitebox.getInternalState使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.powermock.reflect.Whitebox的用法示例。


在下文中一共展示了Whitebox.getInternalState方法的6個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

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

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

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

示例4: testReloadOnStart

import org.powermock.reflect.Whitebox; //導入方法依賴的package包/類
@Test
public void testReloadOnStart() throws Exception {
    expectConfigure();
    expectStart(Arrays.asList(
            new ConsumerRecord<>(TOPIC, 0, 0, 0L, TimestampType.CREATE_TIME, 0L, 0, 0, TP0_KEY.array(), TP0_VALUE.array()),
            new ConsumerRecord<>(TOPIC, 1, 0, 0L, TimestampType.CREATE_TIME, 0L, 0, 0, TP1_KEY.array(), TP1_VALUE.array()),
            new ConsumerRecord<>(TOPIC, 0, 1, 0L, TimestampType.CREATE_TIME, 0L, 0, 0, TP0_KEY.array(), TP0_VALUE_NEW.array()),
            new ConsumerRecord<>(TOPIC, 1, 1, 0L, TimestampType.CREATE_TIME, 0L, 0, 0, TP1_KEY.array(), TP1_VALUE_NEW.array())
    ));
    expectStop();

    PowerMock.replayAll();

    store.configure(DEFAULT_DISTRIBUTED_CONFIG);
    store.start();
    HashMap<ByteBuffer, ByteBuffer> data = Whitebox.getInternalState(store, "data");
    assertEquals(TP0_VALUE_NEW, data.get(TP0_KEY));
    assertEquals(TP1_VALUE_NEW, data.get(TP1_KEY));

    store.stop();

    PowerMock.verifyAll();
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:24,代碼來源:KafkaOffsetBackingStoreTest.java

示例5: whiteboxAddConnector

import org.powermock.reflect.Whitebox; //導入方法依賴的package包/類
private void whiteboxAddConnector(String connectorName, Map<String, String> connectorConfig, List<Map<String, String>> taskConfigs) {
    Map<ConnectorTaskId, Map<String, String>> storageTaskConfigs = Whitebox.getInternalState(configStorage, "taskConfigs");
    for (int i = 0; i < taskConfigs.size(); i++)
        storageTaskConfigs.put(new ConnectorTaskId(connectorName, i), taskConfigs.get(i));

    Map<String, Map<String, String>> connectorConfigs = Whitebox.getInternalState(configStorage, "connectorConfigs");
    connectorConfigs.put(connectorName, connectorConfig);

    Whitebox.<Map<String, Integer>>getInternalState(configStorage, "connectorTaskCounts").put(connectorName, taskConfigs.size());
}
 
開發者ID:YMCoding,項目名稱:kafka-0.11.0.0-src-with-comment,代碼行數:11,代碼來源:KafkaConfigBackingStoreTest.java

示例6: setUp

import org.powermock.reflect.Whitebox; //導入方法依賴的package包/類
@Before
public void setUp() throws InterruptedException {
    PowerMockito.mockStatic(BluetoothObjectFactoryProvider.class);

    when(BluetoothObjectFactoryProvider.getFactory(TINYB_PROTOCOL_NAME)).thenReturn(tinybObjectFactory);
    when(tinybObjectFactory.getProtocolName()).thenReturn(TINYB_PROTOCOL_NAME);

    when(BluetoothObjectFactoryProvider.getFactory(DBUS_PROTOCOL_NAME)).thenReturn(dbusObjectFactory);
    when(dbusObjectFactory.getProtocolName()).thenReturn(DBUS_PROTOCOL_NAME);

    when(tinybObjectFactory.getAdapter(TINYB_ADAPTER_URL)).thenReturn(tinybAdapter);
    when(tinybObjectFactory.getAdapter(TINYB_ADAPTER_URL.copyWithProtocol(null))).thenReturn(tinybAdapter);
    when(tinybObjectFactory.getDevice(TINYB_DEVICE_URL)).thenReturn(tinybDevice);
    when(tinybObjectFactory.getDevice(TINYB_DEVICE_URL.copyWithProtocol(null))).thenReturn(tinybDevice);
    when(tinybObjectFactory.getCharacteristic(TINYB_CHARACTERISTIC_URL)).thenReturn(tinybCharacteristic);
    when(tinybObjectFactory.getCharacteristic(
            TINYB_CHARACTERISTIC_URL.copyWithProtocol(null))).thenReturn(tinybCharacteristic);

    when(dbusObjectFactory.getAdapter(DBUS_ADAPTER_URL)).thenReturn(dbusAdapter);
    when(dbusObjectFactory.getAdapter(DBUS_ADAPTER_URL.copyWithProtocol(null))).thenReturn(dbusAdapter);
    when(dbusObjectFactory.getDevice(DBUS_DEVICE_URL)).thenReturn(dbusDevice);
    when(dbusObjectFactory.getDevice(DBUS_DEVICE_URL.copyWithProtocol(null))).thenReturn(dbusDevice);
    when(dbusObjectFactory.getCharacteristic(DBUS_CHARACTERISTIC_URL)).thenReturn(dbusCharacteristic);
    when(dbusObjectFactory.getCharacteristic(
            DBUS_CHARACTERISTIC_URL.copyWithProtocol(null))).thenReturn(dbusCharacteristic);

    DiscoveredAdapter tinyBDiscoveredAdapter = mock(DiscoveredAdapter.class);
    when(tinyBDiscoveredAdapter.getURL()).thenReturn(TINYB_ADAPTER_URL);
    DiscoveredAdapter dbusDiscoveredAdapter = mock(DiscoveredAdapter.class);
    when(dbusDiscoveredAdapter.getURL()).thenReturn(DBUS_ADAPTER_URL);

    when(tinybObjectFactory.getDiscoveredAdapters()).thenReturn(Arrays.asList(tinyBDiscoveredAdapter));
    when(dbusObjectFactory.getDiscoveredAdapters()).thenReturn(Arrays.asList(dbusDiscoveredAdapter));

    when(BluetoothObjectFactoryProvider.getRegisteredFactories()).thenReturn(
            Arrays.asList(tinybObjectFactory, dbusObjectFactory));


    when(tinybAdapter.getURL()).thenReturn(TINYB_ADAPTER_URL);
    when(dbusAdapter.getURL()).thenReturn(DBUS_ADAPTER_URL);
    when(tinybDevice.getURL()).thenReturn(TINYB_DEVICE_URL);
    when(dbusDevice.getURL()).thenReturn(DBUS_DEVICE_URL);
    when(tinybCharacteristic.getURL()).thenReturn(TINYB_CHARACTERISTIC_URL);
    when(dbusCharacteristic.getURL()).thenReturn(DBUS_CHARACTERISTIC_URL);

    when(tinybAdapter.isPowered()).thenReturn(true);
    when(dbusAdapter.isPowered()).thenReturn(true);

    bluetoothManager.start(true);

    Set discoveredAdapters = Whitebox.getInternalState(bluetoothManager, "discoveredAdapters");
    while (discoveredAdapters.size() != 2) {
        Thread.sleep(10);
    }
}
 
開發者ID:sputnikdev,項目名稱:bluetooth-manager,代碼行數:56,代碼來源:BluetoothManagerImplTest.java


注:本文中的org.powermock.reflect.Whitebox.getInternalState方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。