本文整理汇总了Java中org.mockito.internal.util.reflection.Whitebox.getInternalState方法的典型用法代码示例。如果您正苦于以下问题:Java Whitebox.getInternalState方法的具体用法?Java Whitebox.getInternalState怎么用?Java Whitebox.getInternalState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.mockito.internal.util.reflection.Whitebox
的用法示例。
在下文中一共展示了Whitebox.getInternalState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: checkBindAddress
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
private HttpServer2 checkBindAddress(String host, int port, boolean findPort)
throws Exception {
HttpServer2 server = createServer(host, port);
try {
// not bound, ephemeral should return requested port (0 for ephemeral)
List<?> listeners = (List<?>) Whitebox.getInternalState(server,
"listeners");
Connector listener = (Connector) listeners.get(0);
assertEquals(port, listener.getPort());
// verify hostname is what was given
server.openListeners();
assertEquals(host, server.getConnectorAddress(0).getHostName());
int boundPort = server.getConnectorAddress(0).getPort();
if (port == 0) {
assertTrue(boundPort != 0); // ephemeral should now return bound port
} else if (findPort) {
assertTrue(boundPort > port);
}
} catch (Exception e) {
server.stop();
throw e;
}
return server;
}
示例2: testCloseTwice
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
/**
* The close() method of DFSOutputStream should never throw the same exception
* twice. See HDFS-5335 for details.
*/
@Test
public void testCloseTwice() throws IOException {
DistributedFileSystem fs = cluster.getFileSystem();
FSDataOutputStream os = fs.create(new Path("/test"));
DFSOutputStream dos = (DFSOutputStream) Whitebox.getInternalState(os,
"wrappedStream");
@SuppressWarnings("unchecked")
AtomicReference<IOException> ex = (AtomicReference<IOException>) Whitebox
.getInternalState(dos, "lastException");
Assert.assertEquals(null, ex.get());
dos.close();
IOException dummy = new IOException("dummy");
ex.set(dummy);
try {
dos.close();
} catch (IOException e) {
Assert.assertEquals(e, dummy);
}
Assert.assertEquals(null, ex.get());
dos.close();
}
示例3: testRegionOpenFailsDueToIOException
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
/**
* If region open fails with IOException in openRegion() while doing tableDescriptors.get()
* the region should not add into regionsInTransitionInRS map
* @throws Exception
*/
@Test
public void testRegionOpenFailsDueToIOException() throws Exception {
HRegionInfo REGIONINFO = new HRegionInfo(TableName.valueOf("t"),
HConstants.EMPTY_START_ROW, HConstants.EMPTY_START_ROW);
HRegionServer regionServer = TEST_UTIL.getHBaseCluster().getRegionServer(0);
TableDescriptors htd = Mockito.mock(TableDescriptors.class);
Object orizinalState = Whitebox.getInternalState(regionServer,"tableDescriptors");
Whitebox.setInternalState(regionServer, "tableDescriptors", htd);
Mockito.doThrow(new IOException()).when(htd).get((TableName) Mockito.any());
try {
ProtobufUtil.openRegion(null, regionServer.getRSRpcServices(),
regionServer.getServerName(), REGIONINFO);
fail("It should throw IOException ");
} catch (IOException e) {
}
Whitebox.setInternalState(regionServer, "tableDescriptors", orizinalState);
assertFalse("Region should not be in RIT",
regionServer.getRegionsInTransitionInRS().containsKey(REGIONINFO.getEncodedNameAsBytes()));
}
示例4: run
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Override
public void run() {
try {
Thread.sleep(1000);
LOG.info("Deleting" + path);
final FSDirectory fsdir = cluster.getNamesystem().dir;
INode fileINode = fsdir.getINode4Write(path.toString());
INodeMap inodeMap = (INodeMap) Whitebox.getInternalState(fsdir,
"inodeMap");
fs.delete(path, false);
// after deletion, add the inode back to the inodeMap
inodeMap.put(fileINode);
LOG.info("Deleted" + path);
} catch (Exception e) {
LOG.info(e);
}
}
示例5: getActiveFederationWallet
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void getActiveFederationWallet() throws IOException {
Federation expectedFederation = new Federation(Arrays.asList(new BtcECKey[]{
BtcECKey.fromPublicOnly(Hex.decode("036bb9eab797eadc8b697f0e82a01d01cabbfaaca37e5bafc06fdc6fdd38af894a")),
BtcECKey.fromPublicOnly(Hex.decode("031da807c71c2f303b7f409dd2605b297ac494a563be3b9ca5f52d95a43d183cc5"))
}), Instant.ofEpochMilli(5005L), 0L, NetworkParameters.fromID(NetworkParameters.ID_REGTEST));
BridgeSupport bridgeSupport = getBridgeSupportWithMocksForFederationTests(
false,
expectedFederation,
null,
null,
null,
null,
null
);
Context expectedContext = mock(Context.class);
Whitebox.setInternalState(bridgeSupport, "btcContext", expectedContext);
BridgeStorageProvider provider = (BridgeStorageProvider) Whitebox.getInternalState(bridgeSupport, "provider");
Object expectedUtxos = provider.getNewFederationBtcUTXOs();
final Wallet expectedWallet = mock(Wallet.class);
PowerMockito.mockStatic(BridgeUtils.class);
PowerMockito.when(BridgeUtils.getFederationSpendWallet(any(), any(), any())).then((InvocationOnMock m) -> {
Assert.assertEquals(m.getArgumentAt(0, Context.class), expectedContext);
Assert.assertEquals(m.getArgumentAt(1, Federation.class), expectedFederation);
Assert.assertEquals(m.getArgumentAt(2, Object.class), expectedUtxos);
return expectedWallet;
});
Assert.assertSame(expectedWallet, bridgeSupport.getActiveFederationWallet());
}
示例6: testDaemonAddressOverrideEnvironmentVariable
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testDaemonAddressOverrideEnvironmentVariable() throws SocketException {
environmentVariables.set(UDPEmitter.DAEMON_ADDRESS_ENVIRONMENT_VARIABLE_KEY, "1.2.3.4:5");
UDPEmitter emitter = new UDPEmitter();
InetSocketAddress address = (InetSocketAddress) Whitebox.getInternalState(emitter, "address");
Assert.assertEquals("1.2.3.4", address.getHostString());
Assert.assertEquals(5, address.getPort());
environmentVariables.set(UDPEmitter.DAEMON_ADDRESS_ENVIRONMENT_VARIABLE_KEY, null);
}
示例7: testRunInvalidInput3
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testRunInvalidInput3() throws Exception {
String[] args = {"-i=foo", "-o=bar.xml"};
JunitXmlParser parser = new JunitXmlParser();
parser.run(args);
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
assertTrue(hasCmdLineParameterErrors);
}
示例8: regionAndProxyShouldBeReflectedInClient
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void regionAndProxyShouldBeReflectedInClient(){
AwsKmsClientBuilder clientBuilder = new AwsKmsClientBuilder();
clientBuilder.region("eu-west-1").proxyHost("host").proxyPort(8080);
AWSKMSClient amazonKmsClient = clientBuilder.build();
{
ClientConfiguration configuration = (ClientConfiguration) Whitebox.getInternalState(amazonKmsClient,"clientConfiguration");
assertThat(configuration.getProxyHost()).isEqualTo("host");
assertThat(configuration.getProxyPort()).isEqualTo(8080);
}
}
示例9: testAWSXRayServletAsyncListenerEmitsSegmentWhenProcessingEvent
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testAWSXRayServletAsyncListenerEmitsSegmentWhenProcessingEvent() throws IOException, ServletException {
AWSXRayServletFilter servletFilter = new AWSXRayServletFilter("test");
AsyncContext asyncContext = Mockito.mock(AsyncContext.class);
HttpServletRequest request = Mockito.mock(HttpServletRequest.class);
Mockito.when(request.getRequestURL()).thenReturn(new StringBuffer("test_url"));
Mockito.when(request.getMethod()).thenReturn("TEST_METHOD");
Mockito.when(request.isAsyncStarted()).thenReturn(true);
Mockito.when(request.getAsyncContext()).thenReturn(asyncContext);
HttpServletResponse response = Mockito.mock(HttpServletResponse.class);
FilterChain chain = Mockito.mock(FilterChain.class);
AsyncEvent event = Mockito.mock(AsyncEvent.class);
Mockito.when(event.getSuppliedRequest()).thenReturn(request);
Mockito.when(event.getSuppliedResponse()).thenReturn(response);
servletFilter.doFilter(request, response, chain);
Entity currentEntity = AWSXRay.getTraceEntity();
Mockito.when(request.getAttribute("com.amazonaws.xray.entities.Entity")).thenReturn(currentEntity);
AWSXRayServletAsyncListener listener = (AWSXRayServletAsyncListener) Whitebox.getInternalState(servletFilter, "listener");
listener.onComplete(event);
Mockito.verify(AWSXRay.getGlobalRecorder().getEmitter(), Mockito.times(1)).sendSegment(Mockito.any());
}
示例10: assertDefaultRulesSet
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
private void assertDefaultRulesSet(LocalizedSamplingStrategy localizedSamplingStrategy) {
@SuppressWarnings("unchecked")
ArrayList<SamplingRule> internalRules = (ArrayList<SamplingRule>) Whitebox.getInternalState(localizedSamplingStrategy, "rules");
SamplingRule defaultRule = (SamplingRule) Whitebox.getInternalState(localizedSamplingStrategy, "defaultRule");
Assert.assertEquals(0, internalRules.size());
Assert.assertNull(defaultRule.getServiceName());
Assert.assertNull(defaultRule.getHttpMethod());
Assert.assertNull(defaultRule.getUrlPath());
Assert.assertEquals(1, defaultRule.getFixedTarget());
Assert.assertEquals(0.05, defaultRule.getRate(), 0.0000001);
}
示例11: testRunInvalidInput1
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testRunInvalidInput1() throws Exception {
String[] args = {};
JunitXmlParser parser = new JunitXmlParser();
parser.run(args);
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
assertTrue(hasCmdLineParameterErrors);
}
示例12: regionSetButHostEmpty
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void regionSetButHostEmpty(){
AwsS3ClientBuilder clientBuilder = new AwsS3ClientBuilder();
clientBuilder.region("eu-west-1").proxyPort(8080);
AmazonS3Client amazonS3Client = clientBuilder.build();
assertThat(amazonS3Client.getRegion().toString()).isEqualTo(Region.getRegion(Regions.EU_WEST_1).toString());
{
ClientConfiguration configuration = (ClientConfiguration)Whitebox.getInternalState(amazonS3Client,"clientConfiguration");
assertThat(configuration.getProxyHost()).isNull();
assertThat(configuration.getProxyPort()).isEqualTo(-1);
}
}
示例13: testRegistration
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test(timeout = 1000)
public void testRegistration() throws IOException, InterruptedException {
XDR req = new XDR();
RpcCall.getInstance(++xid, RpcProgramPortmap.PROGRAM,
RpcProgramPortmap.VERSION,
RpcProgramPortmap.PMAPPROC_SET,
new CredentialsNone(), new VerifierNone()).write(req);
PortmapMapping sent = new PortmapMapping(90000, 1,
PortmapMapping.TRANSPORT_TCP, 1234);
sent.serialize(req);
byte[] reqBuf = req.getBytes();
DatagramSocket s = new DatagramSocket();
DatagramPacket p = new DatagramPacket(reqBuf, reqBuf.length,
pm.getUdpServerLoAddress());
try {
s.send(p);
} finally {
s.close();
}
// Give the server a chance to process the request
Thread.sleep(100);
boolean found = false;
@SuppressWarnings("unchecked")
Map<String, PortmapMapping> map = (Map<String, PortmapMapping>) Whitebox
.getInternalState(pm.getHandler(), "map");
for (PortmapMapping m : map.values()) {
if (m.getPort() == sent.getPort()
&& PortmapMapping.key(m).equals(PortmapMapping.key(sent))) {
found = true;
break;
}
}
Assert.assertTrue("Registration failed", found);
}
示例14: regionSetButHostFilledWithSpaces
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void regionSetButHostFilledWithSpaces() {
AwsKmsClientBuilder clientBuilder = new AwsKmsClientBuilder();
clientBuilder.region("eu-west-1").proxyHost(" ").proxyPort(8080);
AWSKMSClient amazonS3Client = clientBuilder.build();
{
ClientConfiguration configuration = (ClientConfiguration)Whitebox.getInternalState(amazonS3Client,"clientConfiguration");
assertThat(configuration.getProxyHost()).isNull();
assertThat(configuration.getProxyPort()).isEqualTo(-1);
}
}
示例15: testRunInvalidInput2
import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testRunInvalidInput2() throws Exception {
String[] args = {"-i=foo"};
JunitXmlParser parser = new JunitXmlParser();
parser.run(args);
Boolean hasCmdLineParameterErrors = (Boolean) Whitebox.getInternalState(parser, "hasCmdLineParameterErrors");
assertTrue(hasCmdLineParameterErrors);
}