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


Java PowerMockito.verifyStatic方法代码示例

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


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

示例1: testGetFileContents_Success

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testGetFileContents_Success() throws Exception {
    String filePath = "c:\\temp\\file.txt";

    Path mockPath = PowerMockito.mock(Path.class);
    PowerMockito.mockStatic(Paths.class);
    PowerMockito.mockStatic(Files.class);

    Mockito.when(Paths.get(Mockito.anyString())).thenReturn(mockPath);
    Mockito.when(Files.readAllBytes(Mockito.isA(Path.class))).thenReturn("hello".getBytes());

    String fileContents = FileUtils.getFileContents(filePath);
    assertThat(fileContents).isNotNull()
            .satisfies(o -> assertThat(o.length()).isGreaterThan(0));

    PowerMockito.verifyStatic(Paths.class);
    Paths.get(Mockito.anyString());
    PowerMockito.verifyStatic(Files.class);
    Files.readAllBytes(Mockito.isA(Path.class));
}
 
开发者ID:enjin,项目名称:Enjin-Coin-Java-SDK,代码行数:21,代码来源:FileUtilsTest.java

示例2: releaseEntryShouldSetValueToRemovePhase2

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void releaseEntryShouldSetValueToRemovePhase2() {
  // mock region entry
  OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);
  when(re.getAddress()).thenReturn(1L);
  when(re.setAddress(1L, OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS))
      .thenReturn(Boolean.TRUE);

  // mock required methods
  PowerMockito.spy(OffHeapRegionEntryHelper.class);
  PowerMockito.doNothing().when(OffHeapRegionEntryHelper.class);
  OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);

  OffHeapRegionEntryHelper.releaseEntry(re);

  PowerMockito.verifyStatic();
  OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:19,代码来源:OffHeapRegionEntryHelperJUnitTest.java

示例3: releaseEntryShouldSetValueToRemovePhase2AndSetsAsyncToFalseForDiskEntry

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void releaseEntryShouldSetValueToRemovePhase2AndSetsAsyncToFalseForDiskEntry() {
  // mock region entry
  OffHeapRegionEntry re = mock(VersionedStatsDiskRegionEntryOffHeap.class);
  when(re.getAddress()).thenReturn(1L);
  when(re.setAddress(1L, OffHeapRegionEntryHelper.REMOVED_PHASE2_ADDRESS))
      .thenReturn(Boolean.TRUE);

  DiskId spy = Mockito.spy(DiskId.class);
  when(((DiskEntry) re).getDiskId()).thenReturn(spy);
  when(spy.isPendingAsync()).thenReturn(Boolean.TRUE);

  // mock required methods
  PowerMockito.spy(OffHeapRegionEntryHelper.class);
  PowerMockito.doNothing().when(OffHeapRegionEntryHelper.class);
  OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);

  OffHeapRegionEntryHelper.releaseEntry(re);

  verify(spy, times(1)).setPendingAsync(Boolean.FALSE);

  PowerMockito.verifyStatic();
  OffHeapRegionEntryHelper.setValue(re, Token.REMOVED_PHASE2);
}
 
开发者ID:ampool,项目名称:monarch,代码行数:25,代码来源:OffHeapRegionEntryHelperJUnitTest.java

示例4: testCreation

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testCreation() throws Exception {
    tested.onCreate(null);
    assertEquals(mockPresenter, tested.getPresenter());
    PowerMockito.verifyStatic(times(1));
    ReflectionPresenterFactory.fromViewClass(argThat(new ArgumentMatcher<Class<?>>() {
        @Override
        public boolean matches(Object argument) {
            return TestView.class.isAssignableFrom((Class)argument);
        }
    }));
    verify(mockDelegate, times(1)).getPresenter();
    verifyNoMoreInteractions(mockPresenter, mockDelegate, mockFactory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:NucleusActivityTest.java

示例5: testCreation

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testCreation() throws Exception {
    tested.onCreate(null);
    assertEquals(mockPresenter, tested.getPresenter());
    PowerMockito.verifyStatic(times(1));
    ReflectionPresenterFactory.fromViewClass(argThat(new ArgumentMatcher<Class<?>>() {
        @Override
        public boolean matches(Object argument) {
            return TestView.class.isAssignableFrom((Class) argument);
        }
    }));
    verify(mockDelegate, times(1)).getPresenter();
    verifyNoMoreInteractions(mockPresenter, mockDelegate, mockFactory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:15,代码来源:NucleusFragmentTest.java

示例6: testCreation

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testCreation() throws Exception {
    assertEquals(mockPresenter, tested.getPresenter());
    PowerMockito.verifyStatic(times(1));
    ReflectionPresenterFactory.fromViewClass(argThat(new ArgumentMatcher<Class<?>>() {
        @Override
        public boolean matches(Object argument) {
            return TestView.class.isAssignableFrom((Class)argument);
        }
    }));
    verify(mockDelegate, times(1)).getPresenter();
    verifyNoMoreInteractions(mockPresenter, mockDelegate, mockFactory);
}
 
开发者ID:weiwenqiang,项目名称:GitHub,代码行数:14,代码来源:NucleusLayoutTest.java

示例7: mainPrintUsageMandatoryWithoutConfFileTest

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void mainPrintUsageMandatoryWithoutConfFileTest() throws Exception {
    PowerMockito.mockStatic(System.class);
    Main.main(new String[]{"-nifi","http://localhost:8080/nifi-api", "-m","extractConfig"});
    PowerMockito.verifyStatic();
    System.exit(1);
}
 
开发者ID:hermannpencole,项目名称:nifi-config,代码行数:8,代码来源:MainTest.java

示例8: testValidateResponse

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testValidateResponse() throws Exception {
    context = Mockito.mock(Activity.class);
    PowerMockito.mockStatic(LiClientManager.class);
    LiClientManager liClientManager = PowerMockito.mock(LiClientManager.class);

    PowerMockito.mockStatic(SSLContext.class);
    SSLContext sslContext = PowerMockito.mock(SSLContext.class);
    when(sslContext.getInstance("SSL")).thenReturn(sslContext);
    Mockito.doNothing().when(sslContext).init(isA(KeyManager[].class), isA(TrustManager[].class), isA(SecureRandom.class));
    SSLSocketFactory socketFactory = mock(SSLSocketFactory.class);
    when(sslContext.getSocketFactory()).thenReturn(socketFactory);

    PowerMockito.mockStatic(Platform.class);
    Platform platform = PowerMockito.mock(Platform.class);
    X509TrustManager trustManager = mock(X509TrustManager.class);
    when(platform.trustManager(socketFactory)).thenReturn(trustManager);
    BDDMockito.given(Platform.get()).willReturn(platform);

    BDDMockito.given(SSLContext.getInstance("SSL")).willReturn(sslContext);

    LiRestv2Client liRestv2Client = LiRestv2Client.getInstance();
    final LiBaseResponse liBaseResponse = mock(LiBaseResponse.class);
    when(liBaseResponse.getHttpCode()).thenReturn(200);
    LiRestv2Client liRestv2ClientSpy = spy(LiRestv2Client.class);
    doReturn(liBaseResponse).when(liRestv2ClientSpy).processSync(isA(LiBaseRestRequest.class));

    LiRestV2Request liBaseRestRequest = new LiRestV2Request(context, liql, "message");
    liBaseRestRequest.addQueryParam("test");

    LiBaseResponse liBaseResponse1 = liRestv2ClientSpy.processSync(liBaseRestRequest);

    Assert.assertEquals(200, liBaseResponse1.getHttpCode());
    PowerMockito.verifyStatic();
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:36,代码来源:LiRestv2ClientTest.java

示例9: testDeleteMessageClient

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testDeleteMessageClient() {
    String id = "33";
    LiClientRequestParams liClientRequestParams = new LiClientRequestParams.LiMessageDeleteClientRequestParams(mContext, id);
    LiClient liClient = null;
    try {
        liClient = LiClientManager.getMessageDeleteClient(liClientRequestParams);
        liClient.processSync();
    } catch (LiRestResponseException e) {
    }
    PowerMockito.verifyStatic();
    Assert.assertNull(liClient.getType());
    Assert.assertEquals(DELETE, "" + liClient.getRequestType());
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:15,代码来源:LiClientManagerTest.java

示例10: testLoadNativeLibraries

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testLoadNativeLibraries() throws Exception {
    PowerMockito.mockStatic(NativesLoader.class);
    PowerMockito.when(NativesLoader.isSupportedEnvironment()).thenReturn(true);
    PowerMockito.when(NativesLoader.prepare(any())).thenReturn("/anypath/anylib");

    TinyBFactory.loadNativeLibraries();

    PowerMockito.verifyStatic(times(1));
}
 
开发者ID:sputnikdev,项目名称:bluetooth-manager-tinyb,代码行数:11,代码来源:TinyBFactoryTest.java

示例11: interruptedDuringReturnValueRetry

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test public void interruptedDuringReturnValueRetry() throws IOException, InterruptedException {
  Retryer.ForReturnValue<String> retryer = new Retryer()
      .uponReturn("bad", Delay.ofMillis(100).exponentialBackoff(10, 1));
  when(action.run()).thenReturn("bad");
  PowerMockito.doThrow(new InterruptedException()).when(Thread.class); Thread.sleep(100);
  Thread thread = PowerMockito.mock(Thread.class);
  PowerMockito.doReturn(thread).when(Thread.class); Thread.currentThread();

  assertThat(retryer.retryBlockingly(action::run)).isEqualTo("bad");
  verify(action).run();
  verify(thread).interrupt();
  PowerMockito.verifyStatic(); Thread.sleep(100);
}
 
开发者ID:google,项目名称:mug,代码行数:14,代码来源:RetryerBlockingTest.java

示例12: testLoadNativeLIbrariesEnvNotSupported

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testLoadNativeLIbrariesEnvNotSupported() {
    PowerMockito.mockStatic(NativesLoader.class);
    PowerMockito.when(NativesLoader.isSupportedEnvironment()).thenReturn(false);

    assertFalse(TinyBFactory.loadNativeLibraries());

    PowerMockito.verifyStatic(times(1));
}
 
开发者ID:sputnikdev,项目名称:bluetooth-manager-tinyb,代码行数:10,代码来源:TinyBFactoryTest.java

示例13: setValueShouldChangeTheRegionEntryAddressToNewAddressAndReleaseOldValueIfItsOnOffHeap

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void setValueShouldChangeTheRegionEntryAddressToNewAddressAndReleaseOldValueIfItsOnOffHeap() {
  // mock region entry
  OffHeapRegionEntry re = mock(OffHeapRegionEntry.class);

  OffHeapStoredObject oldValue = createChunk(Long.MAX_VALUE);
  OffHeapStoredObject newValue = createChunk(Long.MAX_VALUE - 1);

  // mock Chunk static methods - in-order to verify that release is called
  PowerMockito.spy(OffHeapStoredObject.class);
  PowerMockito.doNothing().when(OffHeapStoredObject.class);
  OffHeapStoredObject.release(oldValue.getAddress());

  // mock region entry methods required for test
  when(re.getAddress()).thenReturn(oldValue.getAddress());
  when(re.setAddress(oldValue.getAddress(), newValue.getAddress())).thenReturn(Boolean.TRUE);

  // invoke the method under test
  OffHeapRegionEntryHelper.setValue(re, newValue);

  // verify oldAddress is changed to newAddress
  verify(re, times(1)).setAddress(oldValue.getAddress(), newValue.getAddress());

  // verify oldAddress is released
  PowerMockito.verifyStatic();
  OffHeapStoredObject.release(oldValue.getAddress());
}
 
开发者ID:ampool,项目名称:monarch,代码行数:28,代码来源:OffHeapRegionEntryHelperJUnitTest.java

示例14: setUp

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Before
public void setUp() throws LiRestResponseException {
    mContext = Mockito.mock(Activity.class);
    liRestv2Client = mock(LiRestv2Client.class);
    PowerMockito.mockStatic(LiRestv2Client.class);
    BDDMockito.given(LiRestv2Client.getInstance()).willReturn(liRestv2Client);
    liClient = new LiBaseDeleteClient(mContext, BASE_PATH);
    PowerMockito.verifyStatic();
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:10,代码来源:LiBaseDeleteClientTest.java

示例15: testGetCurrentTimeMillis

import org.powermock.api.mockito.PowerMockito; //导入方法依赖的package包/类
@Test
public void testGetCurrentTimeMillis() {
    PowerMockito.mockStatic(System.class);
    BDDMockito.given(System.currentTimeMillis()).willReturn(currentTime);
    long output = LiSystemClock.INSTANCE.getCurrentTimeMillis();
    PowerMockito.verifyStatic();
    Assert.assertEquals(1L, output);
}
 
开发者ID:lithiumtech,项目名称:li-android-sdk-core,代码行数:9,代码来源:LiSystemClockTest.java


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