本文整理了Java中org.mockito.Mockito.isNull()
方法的一些代码示例,展示了Mockito.isNull()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.isNull()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:isNull
暂无
代码示例来源:origin: apache/geode
/**
* FastLogger should delegate isDebugEnabled when isDelegating
*/
@Test
public void delegateIsDebugEnabledWhenIsDelegating() {
when(mockedLogger.getLevel()).thenReturn(Level.DEBUG);
when(mockedLogger.isEnabled(eq(Level.DEBUG), isNull(), isNull())).thenReturn(true);
when(mockedLogger.isEnabled(eq(Level.DEBUG), eq(mockedMarker), (Object) isNull(), isNull()))
.thenReturn(true);
assertThat(fastLogger.isDebugEnabled()).isTrue();
assertThat(fastLogger.isDebugEnabled(mockedMarker)).isTrue();
verify(mockedLogger).isEnabled(eq(Level.DEBUG), isNull(), isNull());
verify(mockedLogger).isEnabled(eq(Level.DEBUG), eq(mockedMarker), (Object) isNull(), isNull());
}
代码示例来源:origin: apache/geode
/**
* FastLogger should delegate isTraceEnabled when isDelegating
*/
@Test
public void delegateIsTraceEnabledWhenIsDelegating() {
when(mockedLogger.getLevel()).thenReturn(Level.TRACE);
when(mockedLogger.isEnabled(eq(Level.TRACE), isNull(), (Object) isNull(), isNull()))
.thenReturn(true);
when(mockedLogger.isEnabled(eq(Level.TRACE), eq(mockedMarker), (Object) isNull(), isNull()))
.thenReturn(true);
assertThat(fastLogger.isTraceEnabled()).isTrue();
assertThat(fastLogger.isTraceEnabled(mockedMarker)).isTrue();
verify(mockedLogger).isEnabled(eq(Level.TRACE), isNull(), (Object) isNull(), isNull());
verify(mockedLogger).isEnabled(eq(Level.TRACE), eq(mockedMarker), (Object) isNull(), isNull());
}
代码示例来源:origin: gocd/gocd
@Test
public void shouldReturnChangeSetsFromAPreviouslyKnownRevisionUptilTheLatest() throws Exception {
Changeset[] changeSets = getChangeSets(42);
when(client.queryHistory(eq(TFS_PROJECT), or(isNull(), any(ChangesetVersionSpec.class)), anyInt())).thenReturn(changeSets);
TfsSDKCommand spy = spy(tfsCommand);
doReturn(null).when(spy).getModifiedFiles(changeSets[0]);
List<Modification> modifications = spy.modificationsSince(null, new StringRevision("2"));
assertThat(modifications.isEmpty(), is(false));
verify(client, times(2)).queryHistory(eq(TFS_PROJECT), or(isNull(), any(ChangesetVersionSpec.class)), anyInt());
}
代码示例来源:origin: apache/geode
/**
* FastLogger should not delegate isTraceEnabled when not isDelegating
*/
@Test
public void notDelegateIsTraceEnabledWhenNotIsDelegating() {
FastLogger.setDelegating(false);
assertThat(fastLogger.getLevel()).isEqualTo(Level.INFO);
assertThat(fastLogger.isTraceEnabled()).isFalse();
verify(mockedLogger, never()).isEnabled(eq(Level.TRACE), isNull(), isNull());
assertThat(fastLogger.isTraceEnabled(mockedMarker)).isFalse();
verify(mockedLogger, never()).isEnabled(eq(Level.TRACE), eq(mockedMarker), (Object) isNull(),
isNull());
}
代码示例来源:origin: apache/geode
/**
* FastLogger should not delegate isDebugEnabled when not isDelegating
*/
@Test
public void notDelegateIsDebugEnabledWhenNotIsDelegating() {
FastLogger.setDelegating(false);
when(mockedLogger.getLevel()).thenReturn(Level.INFO);
assertThat(fastLogger.getLevel()).isEqualTo(Level.INFO);
assertThat(fastLogger.isDebugEnabled()).isFalse();
assertThat(fastLogger.isDebugEnabled(mockedMarker)).isFalse();
verify(mockedLogger, never()).isEnabled(eq(Level.DEBUG), isNull(), isNull());
verify(mockedLogger, never()).isEnabled(eq(Level.DEBUG), eq(mockedMarker), (Object) isNull(),
isNull());
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void invokeListenerRuntimeException() {
Method method = ReflectionUtils.findMethod(
SampleEvents.class, "generateRuntimeException", GenericTestEvent.class);
GenericTestEvent<String> event = createGenericTestEvent("fail");
this.thrown.expect(IllegalStateException.class);
this.thrown.expectMessage("Test exception");
this.thrown.expectCause(is((Throwable) isNull()));
invokeListener(method, event);
}
代码示例来源:origin: apache/geode
@Test
public void invokeSuppliersShouldLogErrorOnlyOnce() {
Logger logger = mock(Logger.class);
StatisticsImpl.logger = logger;
IntSupplier supplier1 = mock(IntSupplier.class);
when(supplier1.getAsInt()).thenThrow(NullPointerException.class);
stats.setIntSupplier(4, supplier1);
assertEquals(1, stats.invokeSuppliers());
// String message, Object p0, Object p1, Object p2
verify(logger, times(1)).warn(anyString(), isNull(), anyInt(), isA(NullPointerException.class));
assertEquals(1, stats.invokeSuppliers());
// Make sure the logger isn't invoked again
verify(logger, times(1)).warn(anyString(), isNull(), anyInt(), isA(NullPointerException.class));
}
代码示例来源:origin: AxonFramework/AxonFramework
@Test
public void testResetRejectedIfNotAllTokensCanBeClaimed() {
tokenStore.initializeTokenSegments("test", 4);
when(tokenStore.fetchToken("test", 3)).thenThrow(new UnableToClaimTokenException("Mock"));
try {
testSubject.resetTokens();
fail("Expected exception");
} catch (UnableToClaimTokenException e) {
// expected
}
verify(tokenStore, never()).storeToken(isNull(), anyString(), anyInt());
}
代码示例来源:origin: apache/geode
when(this.serverConnection.getClientVersion()).thenReturn(Version.CURRENT);
when(this.localRegion.basicBridgePut(eq(KEY), eq(VALUE), isNull(), eq(true), eq(CALLBACK_ARG),
any(), anyBoolean(), any())).thenReturn(true);
代码示例来源:origin: apache/geode
conn.setSharedUnorderedForTest();
conn.run();
verify(membership).suspectMember(isNull(InternalDistributedMember.class), any(String.class));
代码示例来源:origin: serso/android-checkout
private void prepareMultiPurchasesService(@Nonnull Billing billing) throws RemoteException, JSONException {
final IInAppBillingService service = mock(IInAppBillingService.class);
when(service.getPurchases(anyInt(), anyString(), anyString(), isNull(String.class))).thenReturn(newPurchasesBundle(0, true));
when(service.getPurchases(anyInt(), anyString(), anyString(), eq("1"))).thenReturn(newPurchasesBundle(1, true));
when(service.getPurchases(anyInt(), anyString(), anyString(), eq("2"))).thenReturn(newPurchasesBundle(2, true));
when(service.getPurchases(anyInt(), anyString(), anyString(), eq("3"))).thenReturn(newPurchasesBundle(3, true));
when(service.getPurchases(anyInt(), anyString(), anyString(), eq("4"))).thenReturn(newPurchasesBundle(4, false));
when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), isNull(String.class), any(Bundle.class))).thenReturn(newPurchasesBundle(0, true, true));
when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("1"), any(Bundle.class))).thenReturn(newPurchasesBundle(1, true, true));
when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("2"), any(Bundle.class))).thenReturn(newPurchasesBundle(2, true, true));
when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("3"), any(Bundle.class))).thenReturn(newPurchasesBundle(3, true, true));
when(service.getPurchaseHistory(anyInt(), anyString(), anyString(), eq("4"), any(Bundle.class))).thenReturn(newPurchasesBundle(4, false, true));
Tests.setService(billing, service);
}
代码示例来源:origin: serso/android-checkout
@Test
public void testShouldCancelIsPurchasedListener() throws Exception {
final Billing billing = Tests.newBilling(true);
final CountDownLatch requestWaiter = new CountDownLatch(1);
final CountDownLatch cancelWaiter = new CountDownLatch(1);
final IInAppBillingService service = mock(IInAppBillingService.class);
when(service.getPurchases(anyInt(), anyString(), anyString(), isNull(String.class))).thenAnswer(new Answer<Object>() {
@Override
public Object answer(InvocationOnMock invocation) throws Throwable {
requestWaiter.countDown();
return newPurchasesBundle(0, true);
}
});
when(service.getPurchases(anyInt(), anyString(), anyString(), eq("1"))).thenAnswer(new Answer<Bundle>() {
@Override
public Bundle answer(InvocationOnMock invocation) throws Throwable {
cancelWaiter.await(1, SECONDS);
return newPurchasesBundle(1, false);
}
});
Tests.setService(billing, service);
final RequestListener l = mock(RequestListener.class);
final BillingRequests requests = billing.getRequests();
requests.isPurchased(ProductTypes.IN_APP, "1", l);
requestWaiter.await(1, SECONDS);
requests.cancelAll();
cancelWaiter.countDown();
verify(l, never()).onSuccess(anyObject());
verify(l, never()).onError(anyInt(), any(Exception.class));
}
代码示例来源:origin: jberkel/sms-backup-plus
@Test public void shouldInvalidateTokenOnRefresh() throws Exception {
when(authPreferences.getOauth2Token()).thenReturn("token");
when(authPreferences.getOauth2Username()).thenReturn("username");
when(accountManager.getAuthToken(notNull(Account.class),
anyString(),
isNull(Bundle.class),
anyBoolean(),
any(AccountManagerCallback.class),
any(Handler.class))).thenReturn(mock(AccountManagerFuture.class));
try {
refresher.refreshOAuth2Token();
fail("expected error ");
} catch (TokenRefreshException e) {
assertThat(e.getMessage()).isEqualTo("no bundle received from accountmanager");
}
verify(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token");
}
代码示例来源:origin: jberkel/sms-backup-plus
@Test public void shouldHandleExceptionsThrownByFuture() throws Exception {
when(authPreferences.getOauth2Token()).thenReturn("token");
when(authPreferences.getOauth2Username()).thenReturn("username");
AccountManagerFuture<Bundle> future = mock(AccountManagerFuture.class);
when(accountManager.getAuthToken(notNull(Account.class),
anyString(),
isNull(Bundle.class),
anyBoolean(),
any(AccountManagerCallback.class),
any(Handler.class))).thenReturn(future);
AuthenticatorException exception = new AuthenticatorException();
when(future.getResult()).thenThrow(exception);
try {
refresher.refreshOAuth2Token();
fail("expected exception");
} catch (TokenRefreshException e) {
assertThat(e.getCause()).isSameAs(exception);
}
verify(accountManager).invalidateAuthToken(GOOGLE_TYPE, "token");
}
代码示例来源:origin: SwellRT/swellrt
private static Boolean isNullMarker() {
return (Boolean) Mockito.isNull();
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Test
public void testNonZeroExitCode() {
DoNothingWinRmSoftwareProcessDriver nativeWindowsScriptRunner = mock(DoNothingWinRmSoftwareProcessDriver.class);
when(nativeWindowsScriptRunner.executeNativeOrPsCommand(any(Map.class), any(String.class), Mockito.<String>isNull(), any(String.class), any(Boolean.class))).thenReturn(1);
WinRmExecuteHelper scriptHelper = new WinRmExecuteHelper(nativeWindowsScriptRunner, "test-zero-code-task")
.setCommand(NON_ZERO_CODE_COMMAND);
Assert.assertNotEquals(scriptHelper.executeInternal(), 0, "WinRmExecuteHelper return zero code for non-zero code task");
}
代码示例来源:origin: org.guvnor/guvnor-structure-client
@Test
public void testRevertNoCommitMessage() {
final VersionRecord vr = mock(VersionRecord.class);
presenter.onRevert(vr);
verify(repositoryServiceEditor,
times(1)).revertHistory(eq("repository"),
eq(root),
isNull(String.class),
eq(vr));
verify(view,
times(1)).reloadHistory(eq(repositoryHistory));
}
代码示例来源:origin: org.apache.brooklyn/brooklyn-software-base
@Test(expectedExceptions = IllegalStateException.class)
public void testNonZeroExitCodeException() {
DoNothingWinRmSoftwareProcessDriver nativeWindowsScriptRunner = mock(DoNothingWinRmSoftwareProcessDriver.class);
when(nativeWindowsScriptRunner.executeNativeOrPsCommand(any(Map.class), any(String.class), Mockito.<String>isNull(), any(String.class), any(Boolean.class))).thenReturn(1);
WinRmExecuteHelper scriptHelper = new WinRmExecuteHelper(nativeWindowsScriptRunner, "test-zero-code-task")
.failOnNonZeroResultCode()
.setCommand(NON_ZERO_CODE_COMMAND);
scriptHelper.executeInternal();
}
}
代码示例来源:origin: SwellRT/swellrt
/**
* Verifies that the listener received a marker.
*/
private static void verifyMarker(OpenListener listener, WaveId waveId) {
ArgumentCaptor<WaveletName> waveletNameCaptor = ArgumentCaptor.forClass(WaveletName.class);
verify(listener).onUpdate(waveletNameCaptor.capture(), isNullSnapshot(),
eq(DeltaSequence.empty()), isNullVersion(), eq(true), (String) Mockito.isNull());
assertEquals(waveId, waveletNameCaptor.getValue().waveId);
}
代码示例来源:origin: info.magnolia.ui/magnolia-ui-framework-compatibility
@Test
public void testBinaryDownload() throws Exception {
// GIVEN
action = new DownloadBinaryAction<DownloadBinaryActionDefinition>(definition, item);
// WHEN
action.execute();
// THEN
verify(page).open(any(StreamResource.class), (String) isNull(), eq(false));
}
内容来源于网络,如有侵权,请联系作者删除!