當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。