本文整理汇总了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));
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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);
}
示例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();
}
示例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());
}
示例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));
}
示例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);
}
示例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));
}
示例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());
}
示例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();
}
示例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);
}