当前位置: 首页>>代码示例>>Java>>正文


Java Whitebox.setInternalState方法代码示例

本文整理汇总了Java中org.mockito.internal.util.reflection.Whitebox.setInternalState方法的典型用法代码示例。如果您正苦于以下问题:Java Whitebox.setInternalState方法的具体用法?Java Whitebox.setInternalState怎么用?Java Whitebox.setInternalState使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.mockito.internal.util.reflection.Whitebox的用法示例。


在下文中一共展示了Whitebox.setInternalState方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: isBtcTxHashAlreadyProcessed_exception

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void isBtcTxHashAlreadyProcessed_exception() throws IOException {
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(null, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);

    boolean thrown = false;
    try {
        bridge.isBtcTxHashAlreadyProcessed(new Object[]{"notahash"});
    } catch (RuntimeException e) {
        thrown = true;
    }
    Assert.assertTrue(thrown);
    verify(bridgeSupportMock, never()).isBtcTxHashAlreadyProcessed(any());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:17,代码来源:BridgeTest.java

示例2: getBtcTxHashProcessedHeight_normalFlow

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void getBtcTxHashProcessedHeight_normalFlow() throws IOException {
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(null, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
    Map<Sha256Hash, Long> hashes = new HashMap<>();
    when(bridgeSupportMock.getBtcTxHashProcessedHeight(any(Sha256Hash.class))).then((InvocationOnMock invocation) -> hashes.get(invocation.getArgumentAt(0, Sha256Hash.class)));

    hashes.put(Sha256Hash.of("hash_1".getBytes()), 1L);
    hashes.put(Sha256Hash.of("hash_2".getBytes()), 2L);
    hashes.put(Sha256Hash.of("hash_3".getBytes()), 3L);
    hashes.put(Sha256Hash.of("hash_4".getBytes()), 4L);

    for (Map.Entry<Sha256Hash, Long> entry : hashes.entrySet()) {
        Assert.assertEquals(entry.getValue(), bridge.getBtcTxHashProcessedHeight(new Object[]{entry.getKey().toString()}));
        verify(bridgeSupportMock).getBtcTxHashProcessedHeight(entry.getKey());
    }
    Assert.assertNull(bridge.getBtcTxHashProcessedHeight(new Object[]{Sha256Hash.of("anything".getBytes()).toString()}));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:21,代码来源:BridgeTest.java

示例3: setUp

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Before
public void setUp() {
    // not sure why, but adapter does not get injected properly, hence a workaround here:
    Whitebox.setInternalState(governor, "bluetoothObject", adapter);

    when(adapter.isPowered()).thenReturn(POWERED);
    when(adapter.isDiscovering()).thenReturn(DISCOVERING);
    when(adapter.getAlias()).thenReturn(ALIAS);
    when(adapter.getName()).thenReturn(NAME);
    doNothing().when(adapter).enablePoweredNotifications(poweredCaptor.capture());
    doNothing().when(adapter).enableDiscoveringNotifications(discoveringCaptor.capture());
    governor.addAdapterListener(listener);

    when(adapter.getURL()).thenReturn(URL);

    PowerMockito.mockStatic(BluetoothObjectFactoryProvider.class);
    when(BluetoothObjectFactoryProvider.getFactory(any())).thenReturn(bluetoothObjectFactory);
    when(bluetoothObjectFactory.getAdapter(URL)).thenReturn(adapter);
    when(adapter.getDevices()).thenReturn(DEVICES);
}
 
开发者ID:sputnikdev,项目名称:bluetooth-manager,代码行数:21,代码来源:AdapterGovernorImplTest.java

示例4: testPutMetrics

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test(timeout=3000)
public void testPutMetrics() throws IOException, InterruptedException {
  final StatsDSink sink = new StatsDSink();
  List<MetricsTag> tags = new ArrayList<MetricsTag>();
  tags.add(new MetricsTag(MsInfo.Hostname, "host"));
  tags.add(new MetricsTag(MsInfo.Context, "jvm"));
  tags.add(new MetricsTag(MsInfo.ProcessName, "process"));
  Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
  metrics.add(makeMetric("foo1", 1.25, MetricType.COUNTER));
  metrics.add(makeMetric("foo2", 2.25, MetricType.GAUGE));
  final MetricsRecord record =
      new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

  try (DatagramSocket sock = new DatagramSocket()) {
    sock.setReceiveBufferSize(8192);
    final StatsDSink.StatsD mockStatsD =
        new StatsD(sock.getLocalAddress().getHostName(),
            sock.getLocalPort());
    Whitebox.setInternalState(sink, "statsd", mockStatsD);
    final DatagramPacket p = new DatagramPacket(new byte[8192], 8192);
    sink.putMetrics(record);
    sock.receive(p);

    String result =new String(p.getData(), 0, p.getLength(),
        Charset.forName("UTF-8"));
    assertTrue(
        "Received data did not match data sent",
        result.equals("host.process.jvm.Context.foo1:1.25|c") ||
        result.equals("host.process.jvm.Context.foo2:2.25|g"));

  } finally {
    sink.close();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:35,代码来源:TestStatsDMetrics.java

示例5: testPutMetrics2

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test(timeout=3000)
public void testPutMetrics2() throws IOException {
  StatsDSink sink = new StatsDSink();
  List<MetricsTag> tags = new ArrayList<MetricsTag>();
  tags.add(new MetricsTag(MsInfo.Hostname, null));
  tags.add(new MetricsTag(MsInfo.Context, "jvm"));
  tags.add(new MetricsTag(MsInfo.ProcessName, "process"));
  Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
  metrics.add(makeMetric("foo1", 1, MetricType.COUNTER));
  metrics.add(makeMetric("foo2", 2, MetricType.GAUGE));
  MetricsRecord record =
      new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

  try (DatagramSocket sock = new DatagramSocket()) {
    sock.setReceiveBufferSize(8192);
    final StatsDSink.StatsD mockStatsD =
        new StatsD(sock.getLocalAddress().getHostName(),
            sock.getLocalPort());
    Whitebox.setInternalState(sink, "statsd", mockStatsD);
    final DatagramPacket p = new DatagramPacket(new byte[8192], 8192);
    sink.putMetrics(record);
    sock.receive(p);
    String result =
        new String(p.getData(), 0, p.getLength(), Charset.forName("UTF-8"));

    assertTrue("Received data did not match data sent",
        result.equals("process.jvm.Context.foo1:1|c") ||
        result.equals("process.jvm.Context.foo2:2|g"));
  } finally {
    sink.close();
  }
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:33,代码来源:TestStatsDMetrics.java

示例6: testPutMetrics

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testPutMetrics() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
    tags.add(new MetricsTag(MsInfo.Hostname, "host"));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1.25));
    metrics.add(makeMetric("foo2", 2.25));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);

    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    final GraphiteSink.Graphite mockGraphite = makeGraphite();
    Whitebox.setInternalState(sink, "graphite", mockGraphite);
    sink.putMetrics(record);

    try {
      verify(mockGraphite).write(argument.capture());
    } catch (IOException e) {
      e.printStackTrace();
    }

    String result = argument.getValue();

    assertEquals(true,
        result.equals("null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n" +
        "null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n") ||
        result.equals("null.all.Context.Context=all.Hostname=host.foo2 2.25 10\n" + 
        "null.all.Context.Context=all.Hostname=host.foo1 1.25 10\n"));
}
 
开发者ID:nucypher,项目名称:hadoop-oss,代码行数:31,代码来源:TestGraphiteMetrics.java

示例7: getPendingFederationSize

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void getPendingFederationSize() throws IOException {
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(null, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
    when(bridgeSupportMock.getPendingFederationSize()).thenReturn(1234);

    Assert.assertEquals(1234, bridge.getPendingFederationSize(new Object[]{}).intValue());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:11,代码来源:BridgeTest.java

示例8: testLambdaInvokeSubsegmentContainsFunctionName

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testLambdaInvokeSubsegmentContainsFunctionName() {
    // Setup test
    AWSLambda lambda = AWSLambdaClientBuilder.standard().withRequestHandlers(new TracingHandler()).withRegion(Regions.US_EAST_1).withCredentials(new AWSStaticCredentialsProvider(new BasicAWSCredentials("fake", "fake"))).build();

    AmazonHttpClient amazonHttpClient = new AmazonHttpClient(new ClientConfiguration());
    ConnectionManagerAwareHttpClient apacheHttpClient = Mockito.mock(ConnectionManagerAwareHttpClient.class);
    HttpResponse httpResponse = new BasicHttpResponse(new BasicStatusLine(HttpVersion.HTTP_1_1, 200, "OK"));
    BasicHttpEntity responseBody = new BasicHttpEntity();
    responseBody.setContent(new ByteArrayInputStream("null".getBytes(StandardCharsets.UTF_8))); // Lambda returns "null" on successful fn. with no return value
    httpResponse.setEntity(responseBody);

    try {
        Mockito.doReturn(httpResponse).when(apacheHttpClient).execute(Mockito.any(HttpUriRequest.class), Mockito.any(HttpContext.class));
    } catch (IOException e) { }

    Whitebox.setInternalState(amazonHttpClient, "httpClient", apacheHttpClient);
    Whitebox.setInternalState(lambda, "client", amazonHttpClient);

    // Test logic
    Segment segment = AWSXRay.beginSegment("test");

    InvokeRequest request = new InvokeRequest();
    request.setFunctionName("testFunctionName");
    InvokeResult r = lambda.invoke(request);
    System.out.println(r.getStatusCode());
    System.out.println(r);

    Assert.assertEquals(1, segment.getSubsegments().size());
    Assert.assertEquals("Invoke", segment.getSubsegments().get(0).getAws().get("operation"));
    System.out.println(segment.getSubsegments().get(0).getAws());
    Assert.assertEquals("testFunctionName", segment.getSubsegments().get(0).getAws().get("function_name"));
}
 
开发者ID:aws,项目名称:aws-xray-sdk-java,代码行数:34,代码来源:TracingHandlerTest.java

示例9: getPendingFederatorPublicKey

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void getPendingFederatorPublicKey() throws IOException {
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(null, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
    when(bridgeSupportMock.getPendingFederatorPublicKey(any(int.class))).then((InvocationOnMock invocation) ->
            BigInteger.valueOf(invocation.getArgumentAt(0, int.class)).toByteArray());

    Assert.assertTrue(Arrays.equals(new byte[]{10}, bridge.getPendingFederatorPublicKey(new Object[]{BigInteger.valueOf(10)})));
    Assert.assertTrue(Arrays.equals(new byte[]{20}, bridge.getPendingFederatorPublicKey(new Object[]{BigInteger.valueOf(20)})));
    Assert.assertTrue(Arrays.equals(new byte[]{1, 0}, bridge.getPendingFederatorPublicKey(new Object[]{BigInteger.valueOf(256)})));
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:14,代码来源:BridgeTest.java

示例10: getFederationCreationTime

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void getFederationCreationTime() throws IOException {
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(null, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
    when(bridgeSupportMock.getFederationCreationTime()).thenReturn(Instant.ofEpochMilli(5000));

    Assert.assertEquals(5000, bridge.getFederationCreationTime(new Object[]{}).intValue());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:11,代码来源:BridgeTest.java

示例11: createFederation

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void createFederation() throws IOException {
    Transaction txMock = mock(Transaction.class);
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(txMock, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
    when(bridgeSupportMock.voteFederationChange(txMock, new ABICallSpec("create", new byte[][]{}))).thenReturn(123);

    Assert.assertEquals(123, bridge.createFederation(new Object[]{}).intValue());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:12,代码来源:BridgeTest.java

示例12: setUp

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Before
public void setUp() throws Exception {
    font = new BitmapFont();

    chr = PowerMockito.mock(BitmapChar.class);
    PowerMockito.when(chr, "getId").thenReturn(97);

    chr2 = PowerMockito.mock(BitmapChar.class);
    PowerMockito.when(chr2, "getId").thenReturn(98);

    pagesMock = PowerMockito.mock(SparseArray.class);
    PowerMockito.doNothing().when(pagesMock, "put", 0, "value");
    PowerMockito.when(pagesMock, "get", 0).thenReturn("value");
    PowerMockito.when(pagesMock, "get", 100).thenReturn(null);
    PowerMockito.when(pagesMock, "size").thenReturn(2);

    charsMock = PowerMockito.mock(SparseArray.class);
    PowerMockito.doNothing().when(charsMock, "put", 97, chr);
    PowerMockito.when(charsMock, "get", 97).thenReturn(chr);

    firstKernings = PowerMockito.mock(SparseArray.class);
    PowerMockito.when(firstKernings, "get", 98).thenReturn(2);

    kerningsMock = PowerMockito.mock(SparseArray.class);
    PowerMockito.when(kerningsMock, "get", 97).thenReturn(firstKernings);

    Whitebox.setInternalState(font, "pages", pagesMock);
    Whitebox.setInternalState(font, "chars", charsMock);
    Whitebox.setInternalState(font, "kernings", kerningsMock);
}
 
开发者ID:snada,项目名称:BitmapFontLoader,代码行数:31,代码来源:BitmapFontTest.java

示例13: testPutMetrics2

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void testPutMetrics2() {
    GraphiteSink sink = new GraphiteSink();
    List<MetricsTag> tags = new ArrayList<MetricsTag>();
    tags.add(new MetricsTag(MsInfo.Context, "all"));
  tags.add(new MetricsTag(MsInfo.Hostname, null));
    Set<AbstractMetric> metrics = new HashSet<AbstractMetric>();
    metrics.add(makeMetric("foo1", 1));
    metrics.add(makeMetric("foo2", 2));
    MetricsRecord record = new MetricsRecordImpl(MsInfo.Context, (long) 10000, tags, metrics);


    ArgumentCaptor<String> argument = ArgumentCaptor.forClass(String.class);
    final GraphiteSink.Graphite mockGraphite = makeGraphite();
    Whitebox.setInternalState(sink, "graphite", mockGraphite);
    sink.putMetrics(record);

    try {
        verify(mockGraphite).write(argument.capture());
    } catch (IOException e) {
        e.printStackTrace();
    }

    String result = argument.getValue();

    assertEquals(true,
        result.equals("null.all.Context.Context=all.foo1 1 10\n" + 
        "null.all.Context.Context=all.foo2 2 10\n") ||
        result.equals("null.all.Context.Context=all.foo2 2 10\n" + 
        "null.all.Context.Context=all.foo1 1 10\n"));
}
 
开发者ID:naver,项目名称:hadoop,代码行数:32,代码来源:TestGraphiteMetrics.java

示例14: getLockWhitelistSize

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@Test
public void getLockWhitelistSize() throws IOException {
    Bridge bridge = new Bridge(ConfigHelper.CONFIG, PrecompiledContracts.BRIDGE_ADDR);
    bridge.init(null, null, null, null, null, null);
    BridgeSupport bridgeSupportMock = mock(BridgeSupport.class);
    Whitebox.setInternalState(bridge, "bridgeSupport", bridgeSupportMock);
    when(bridgeSupportMock.getLockWhitelistSize()).thenReturn(1234);

    Assert.assertEquals(1234, bridge.getLockWhitelistSize(new Object[]{}).intValue());
}
 
开发者ID:rsksmart,项目名称:rskj,代码行数:11,代码来源:BridgeTest.java

示例15: statuses

import org.mockito.internal.util.reflection.Whitebox; //导入方法依赖的package包/类
@DataProvider
public Object[][] statuses() {
    TitanMigrationManager happyMigrationManager = new TitanMigrationManager();
    TitanMigrationManager sadMigrationManager = new TitanMigrationManager();
    Whitebox.setInternalState(happyMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, true);
    Whitebox.setInternalState(sadMigrationManager, IS_MIGRATION_COMPLETE_FIELD_NAME, false);

    return new Object[][] { new Object[] { mockDbWithUp(), Status.UP, AcsMonitoringUtilities.HealthCode.AVAILABLE,
            happyMigrationManager },

            { mockDbWithException(new TransientDataAccessResourceException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager },

            { mockDbWithException(new QueryTimeoutException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNAVAILABLE, happyMigrationManager },

            { mockDbWithException(new DataSourceLookupFailureException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.UNREACHABLE, happyMigrationManager },

            { mockDbWithException(new PermissionDeniedDataAccessException("", null)), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.MISCONFIGURATION, happyMigrationManager },

            { mockDbWithException(new ConcurrencyFailureException("")), Status.DOWN,
                    AcsMonitoringUtilities.HealthCode.ERROR, happyMigrationManager },

            { mockDbWithUp(), Status.DOWN, AcsMonitoringUtilities.HealthCode.MIGRATION_INCOMPLETE,
                    sadMigrationManager }, };
}
 
开发者ID:eclipse,项目名称:keti,代码行数:29,代码来源:AcsDbHealthIndicatorTest.java


注:本文中的org.mockito.internal.util.reflection.Whitebox.setInternalState方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。