本文整理汇总了Java中org.powermock.reflect.internal.WhiteboxImpl.getInternalState方法的典型用法代码示例。如果您正苦于以下问题:Java WhiteboxImpl.getInternalState方法的具体用法?Java WhiteboxImpl.getInternalState怎么用?Java WhiteboxImpl.getInternalState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.powermock.reflect.internal.WhiteboxImpl
的用法示例。
在下文中一共展示了WhiteboxImpl.getInternalState方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testCreateCloudFileSystemInternalWillCreateTheFileSystemIfItHasntBeenCreatedYet
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testCreateCloudFileSystemInternalWillCreateTheFileSystemIfItHasntBeenCreatedYet() {
CloudHostConfiguration config = context.mock(CloudHostConfiguration.class);
FileSystemProvider provider = context.mock(FileSystemProvider.class);
BlobStoreContext blobStoreContext = context.mock(BlobStoreContext.class);
context.checking(new Expectations() {{
allowing(config).getName();
will(returnValue("test-config"));
exactly(1).of(config).createBlobStoreContext();
will(returnValue(blobStoreContext));
}});
Assert.assertTrue(((Map<?,?>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems")).isEmpty());
impl.createCloudFilesystemInternal(provider, config);
Map<String,CloudFileSystem> cloudFileSystemsMap =
((Map<String,CloudFileSystem>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems"));
Assert.assertTrue(cloudFileSystemsMap.containsKey("test-config"));
Assert.assertNotNull(cloudFileSystemsMap.get("test-config"));
}
示例2: testCreateCloudFileSystemWillUseTheCloudHostConfigurationBuilderToCreateACloudFileSystem
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testCreateCloudFileSystemWillUseTheCloudHostConfigurationBuilderToCreateACloudFileSystem() throws URISyntaxException, IOException {
FileSystemProvider provider = context.mock(FileSystemProvider.class);
URI uri = new URI("cloud", "mock-fs", "/path", "fragment"); // The host holds the name
Map<String,Object> env = new HashMap<>();
env.put(JCloudsCloudHostProvider.CLOUD_TYPE_ENV, "mock-test");
// Test we can create the FS
Assert.assertTrue(((Map<?,?>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems")).isEmpty());
impl.createCloudFileSystem(provider, uri, env);
Map<String,CloudFileSystem> cloudFileSystemsMap =
((Map<String,CloudFileSystem>)WhiteboxImpl.getInternalState(impl, "cloudFileSystems"));
Assert.assertTrue(cloudFileSystemsMap.containsKey("mock-fs"));
Assert.assertNotNull(cloudFileSystemsMap.get("mock-fs"));
// Now get the FS back
CloudFileSystem cloudFileSystem = impl.getCloudFileSystem(uri);
Assert.assertNotNull(cloudFileSystem);
Assert.assertEquals(provider, cloudFileSystem.provider());
Assert.assertEquals(MockCloudHostConfiguration.class, cloudFileSystem.getCloudHostConfiguration().getClass());
Assert.assertEquals("mock-fs", cloudFileSystem.getCloudHostConfiguration().getName());
// Close it and make sure we don't get it back
cloudFileSystem.close();
Assert.assertNull(impl.getCloudFileSystem(uri));
}
示例3: getMockType
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
public MocksControl.MockType getMockType() {
final MocksControl control = invocationHandler.getControl();
if (WhiteboxImpl.getFieldsOfType(control, MocksControl.MockType.class).isEmpty()) {
// EasyMock is of version 3.2+
final MockType mockType = WhiteboxImpl.getInternalState(control, MockType.class);
switch (mockType) {
case DEFAULT:
return MocksControl.MockType.DEFAULT;
case NICE:
return MocksControl.MockType.NICE;
case STRICT:
return MocksControl.MockType.STRICT;
default:
throw new IllegalStateException("PowerMock doesn't seem to work with the used EasyMock version. Please report to the PowerMock mailing list");
}
} else {
return WhiteboxImpl.getInternalState(control, MocksControl.MockType.class);
}
}
示例4: testSetCachePeerHostsSetsANewListOfHosts
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testSetCachePeerHostsSetsANewListOfHosts() {
invokeInitAndCheckDiscoveryServiceHasBeenStarted();
context.checking(new Expectations() {{
allowing(discoveryServiceConfig).getRmiListenerPort(); will(returnValue(61616));
}});
// Make sure that the initial list is empty
Assert.assertTrue(((Set<String>)WhiteboxImpl.getInternalState(peerProvider, PEER_URLS_SET_VARIABLE_NAME)).isEmpty());
// Set up a list of hosts. Because these hosts are actually resolved they need to be real.
Set<CachePeerHost> cachePeerHosts = new HashSet<>();
cachePeerHosts.add(new CachePeerHost("www.google.com", 61616));
cachePeerHosts.add(new CachePeerHost("www.yahoo.com", 61618));
// Set the hosts
peerProvider.setCachePeerHosts(cachePeerHosts);
// Check that RMI URL's should be formed from the values
Set<String> peerUrls = (Set<String>)WhiteboxImpl.getInternalState(peerProvider, PEER_URLS_SET_VARIABLE_NAME);
Assert.assertEquals(2, peerUrls.size());
Assert.assertTrue(peerUrls.contains("//www.google.com:61616"));
Assert.assertTrue(peerUrls.contains("//www.yahoo.com:61618"));
}
示例5: testSetCachePeerHostsUpdatesTheSetOfHostsWhenAHostHasBeenRemoved
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testSetCachePeerHostsUpdatesTheSetOfHostsWhenAHostHasBeenRemoved() {
invokeInitAndCheckDiscoveryServiceHasBeenStarted();
context.checking(new Expectations() {{
allowing(discoveryServiceConfig).getRmiListenerPort(); will(returnValue(61616));
}});
// Set up a list of hosts. Because these hosts are actually resolved they need to be real.
Set<CachePeerHost> cachePeerHosts = new HashSet<>();
CachePeerHost googleCachePeerHost = new CachePeerHost("www.google.com", 61616);
cachePeerHosts.add(googleCachePeerHost);
CachePeerHost yahooCachePeerHost = new CachePeerHost("www.yahoo.com", 61618);
cachePeerHosts.add(yahooCachePeerHost);
// Set the hosts
peerProvider.setCachePeerHosts(cachePeerHosts);
// Check that RMI URL's should be formed from the values
Set<String> peerUrls = (Set<String>)WhiteboxImpl.getInternalState(peerProvider, PEER_URLS_SET_VARIABLE_NAME);
Assert.assertEquals(2, peerUrls.size());
Assert.assertTrue(peerUrls.contains("//www.google.com:61616"));
Assert.assertTrue(peerUrls.contains("//www.yahoo.com:61618"));
// Remove the first one so that we should only have one in the list and set this
Assert.assertTrue(cachePeerHosts.remove(googleCachePeerHost));
peerProvider.setCachePeerHosts(cachePeerHosts);
// Check that RMI URL's should be formed from the values
peerUrls = (Set<String>)WhiteboxImpl.getInternalState(peerProvider, PEER_URLS_SET_VARIABLE_NAME);
Assert.assertEquals(1, peerUrls.size());
Assert.assertTrue(peerUrls.contains("//www.yahoo.com:61618"));
}
示例6: testListRemoteCachePeersReturnsAListofPeersPerCacheAndUpdatesTheInternalMap
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
@Test
public void testListRemoteCachePeersReturnsAListofPeersPerCacheAndUpdatesTheInternalMap() {
invokeInitAndCheckDiscoveryServiceHasBeenStarted();
// Mock some stuff up
final Ehcache cache = context.mock(Ehcache.class);
final CachePeer googleCacheRemote = context.mock(CachePeer.class, "googleCacheRemote");
final CachePeer yahooCacheRemote = context.mock(CachePeer.class, "yahooCacheRemote");
// We are expecting RMI Naming.lookup calls to these URL's for the cache
final String cacheName = "myCache";
peerProvider.addCachePeerPerUrl("//www.google.com:61616/" + cacheName, googleCacheRemote);
peerProvider.addCachePeerPerUrl("//www.yahoo.com:61618/" + cacheName, yahooCacheRemote);
context.checking(new Expectations() {{
allowing(discoveryServiceConfig).getRmiListenerPort(); will(returnValue(61616));
allowing(cache).getName(); will(returnValue(cacheName));
}});
// Make sure that the initial list is empty
Assert.assertTrue(((Map<String,List<CachePeer>>)WhiteboxImpl.getInternalState(peerProvider, CACHE_PEERS_MAP_VARIABLE_NAME)).isEmpty());
// Set up a list of hosts. Because these hosts are actually resolved they need to be real.
Set<CachePeerHost> cachePeerHosts = new HashSet<>();
cachePeerHosts.add(new CachePeerHost("www.google.com", 61616));
cachePeerHosts.add(new CachePeerHost("www.yahoo.com", 61618));
// Set the hosts
peerProvider.setCachePeerHosts(cachePeerHosts);
// Now list the peers, which should create a new entry in the map and return a list of CachePeer's
List<CachePeer> listRemoteCachePeers = peerProvider.listRemoteCachePeers(cache);
Assert.assertEquals(2, listRemoteCachePeers.size());
Assert.assertTrue(listRemoteCachePeers.contains(googleCacheRemote));
Assert.assertTrue(listRemoteCachePeers.contains(yahooCacheRemote));
try {
listRemoteCachePeers.add(context.mock(CachePeer.class, "dummyCachePeer"));
Assert.fail("Did not expect to be able to add a member to the cache peers list that was returned");
} catch (UnsupportedOperationException e) {
// OK
}
// Check that the cache has also been populated with this list
Map<String,List<CachePeer>> cachePeers =
(Map<String,List<CachePeer>>)WhiteboxImpl.getInternalState(peerProvider, CACHE_PEERS_MAP_VARIABLE_NAME);
Assert.assertEquals(1, cachePeers.size());
Assert.assertEquals(listRemoteCachePeers, cachePeers.get(cacheName));
// Another invocation should return exactly the same object, i.e. this list should not be recreated
Assert.assertEquals(listRemoteCachePeers.hashCode(), peerProvider.listRemoteCachePeers(cache).hashCode());
}
示例7: getInternalState
import org.powermock.reflect.internal.WhiteboxImpl; //导入方法依赖的package包/类
/**
* Get the value of a field using reflection. This method will iterate
* through the entire class hierarchy and return the value of the first
* field named <tt>fieldName</tt>. If you want to get a specific field value
* at specific place in the class hierarchy please refer to
* {@link #getInternalState(Object, String, Class)}.
*
* @param object
* the object to modify
* @param fieldName
* the name of the field
*/
public static <T> T getInternalState(Object object, String fieldName) {
return WhiteboxImpl.<T> getInternalState(object, fieldName);
}