本文整理汇总了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();
}
示例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());
}
示例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());
}
示例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();
}
示例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());
}
示例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);
}
}