本文整理了Java中org.mockito.Mockito.verifyZeroInteractions()
方法的一些代码示例,展示了Mockito.verifyZeroInteractions()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.verifyZeroInteractions()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:verifyZeroInteractions
[英]Verifies that no interactions happened on given mocks.
verifyZeroInteractions(mockOne, mockTwo);
This method will also detect invocations that occurred before the test method, for example: in setUp()
, @Before
method or in constructor. Consider writing nice code that makes interactions only in test methods.
See also Mockito#never() - it is more explicit and communicates the intent well.
See examples in javadoc for Mockito class
[中]验证给定模拟上没有发生交互
verifyZeroInteractions(mockOne, mockTwo);
此方法还将检测在测试方法之前发生的调用,例如setUp()
、@Before
方法或构造函数中的调用。考虑编写好代码,只在测试方法中进行交互。
另请参见Mockito#never()-它更明确,能够很好地传达意图。
有关Mockito类,请参见javadoc中的示例
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldNotInvokeFuncUntilSubscription() throws Exception {
Callable<Object> func = mock(Callable.class);
when(func.call()).thenReturn(new Object());
Single<Object> fromCallableSingle = Single.fromCallable(func);
verifyZeroInteractions(func);
fromCallableSingle.subscribe();
verify(func).call();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void settingSameDisposableTwiceDoesUnsubscribeIt() {
Disposable underlying = mock(Disposable.class);
serialDisposable.update(underlying);
verifyZeroInteractions(underlying);
serialDisposable.update(underlying);
verify(underlying).dispose();
}
代码示例来源:origin: robolectric/robolectric
@Test
public void shouldRemoveRegisteredListenersOnUnresgister() {
SharedPreferences anotherSharedPreferences = context.getSharedPreferences("bazBang", Context.MODE_PRIVATE);
SharedPreferences.OnSharedPreferenceChangeListener mockListener = mock(SharedPreferences.OnSharedPreferenceChangeListener.class);
anotherSharedPreferences.registerOnSharedPreferenceChangeListener(mockListener);
anotherSharedPreferences.unregisterOnSharedPreferenceChangeListener(mockListener);
anotherSharedPreferences.edit().putString("key", "value");
verifyZeroInteractions(mockListener);
}
代码示例来源:origin: airbnb/lottie-android
@Test
public void testException() {
final IllegalStateException exception = new IllegalStateException("foo");
LottieTask<Integer> task = new LottieTask<>(new Callable<LottieResult<Integer>>() {
@Override public LottieResult<Integer> call() {
throw exception;
}
}, true)
.addListener(successListener)
.addFailureListener(failureListener);
verifyZeroInteractions(successListener);
verify(failureListener, times(1)).onResult(exception);
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void ignoreMessage() {
// no destination
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", null));
Mockito.verifyZeroInteractions(this.brokerChannel);
// not a user destination
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/queue/foo"));
Mockito.verifyZeroInteractions(this.brokerChannel);
// subscribe + not a user destination
this.handler.handleMessage(createWith(SimpMessageType.SUBSCRIBE, "joe", "123", "/queue/foo"));
Mockito.verifyZeroInteractions(this.brokerChannel);
// no match on message type
this.handler.handleMessage(createWith(SimpMessageType.CONNECT, "joe", "123", "user/joe/queue/foo"));
Mockito.verifyZeroInteractions(this.brokerChannel);
}
代码示例来源:origin: neo4j/neo4j
@Test
void closeVerifiesUniquenessOfChangedValues() throws Exception
{
SchemaIndex index = mock( SchemaIndex.class );
UniqueLuceneIndexPopulatingUpdater updater = newUpdater( index );
updater.process( change( 1, descriptor, "foo1", "foo2" ) );
updater.process( change( 1, descriptor, "bar1", "bar2" ) );
updater.process( change( 1, descriptor, "baz1", "baz2" ) );
verifyZeroInteractions( index );
updater.close();
verifyVerifyUniqueness( index, descriptor, "foo2", "bar2", "baz2" );
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldNotInvokeFuncUntilSubscription() throws Exception {
Callable<Object> func = mock(Callable.class);
when(func.call()).thenReturn(new Object());
Observable<Object> fromCallableObservable = Observable.fromCallable(func);
verifyZeroInteractions(func);
fromCallableObservable.subscribe();
verify(func).call();
}
代码示例来源:origin: roughike/BottomBar
@Test
public void setOnTabSelectListener_WhenShouldFireInitiallySetToFalse_DoesNotFireWhenSet() {
OnTabSelectListener listener = mock(OnTabSelectListener.class);
bottomBar.setOnTabSelectListener(listener, false);
verifyZeroInteractions(listener);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void settingSameDisposableTwiceDoesUnsubscribeIt() {
Disposable underlying = mock(Disposable.class);
serialDisposable.set(underlying);
verifyZeroInteractions(underlying);
serialDisposable.set(underlying);
verify(underlying).dispose();
}
代码示例来源:origin: airbnb/lottie-android
@Test
public void testListener() {
LottieTask<Integer> task = new LottieTask<>(new Callable<LottieResult<Integer>>() {
@Override public LottieResult<Integer> call() {
return new LottieResult<>(5);
}
}, true)
.addListener(successListener)
.addFailureListener(failureListener);
verify(successListener, times(1)).onResult(5);
verifyZeroInteractions(failureListener);
}
代码示例来源:origin: square/picasso
@Test public void performNetworkStateChangeWithNullInfoIgnores() {
Dispatcher dispatcher = createDispatcher(serviceMock);
dispatcher.performNetworkStateChange(null);
verifyZeroInteractions(service);
}
代码示例来源:origin: neo4j/neo4j
@Test
void closeVerifiesUniquenessOfAddedValues() throws Exception
{
SchemaIndex index = mock( SchemaIndex.class );
UniqueLuceneIndexPopulatingUpdater updater = newUpdater( index );
updater.process( add( 1, descriptor, "foo" ) );
updater.process( add( 1, descriptor, "bar" ) );
updater.process( add( 1, descriptor, "baz" ) );
verifyZeroInteractions( index );
updater.close();
verifyVerifyUniqueness( index, descriptor, "foo", "bar", "baz" );
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldNotInvokeFuncUntilSubscription() throws Exception {
Callable<Object> func = mock(Callable.class);
when(func.call()).thenReturn(new Object());
Flowable<Object> fromCallableFlowable = Flowable.fromCallable(func);
verifyZeroInteractions(func);
fromCallableFlowable.subscribe();
verify(func).call();
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void onStart_has_no_effect() {
CeTask ceTask = mock(CeTask.class);
underTest.onStart(ceTask);
verifyZeroInteractions(ceTask);
}
代码示例来源:origin: android10/Android-CleanArchitecture
@Test
public void testGetUserListUseCaseObservableHappyCase() {
getUserList.buildUseCaseObservable(null);
verify(mockUserRepository).users();
verifyNoMoreInteractions(mockUserRepository);
verifyZeroInteractions(mockThreadExecutor);
verifyZeroInteractions(mockPostExecutionThread);
}
}
代码示例来源:origin: airbnb/lottie-android
@Test
public void testAddListenerAfter() {
LottieTask<Integer> task = new LottieTask<>(new Callable<LottieResult<Integer>>() {
@Override public LottieResult<Integer> call() {
return new LottieResult<>(5);
}
}, true);
task.addListener(successListener);
task.addFailureListener(failureListener);
verify(successListener, times(1)).onResult(5);
verifyZeroInteractions(failureListener);
}
}
代码示例来源:origin: square/picasso
@Test public void performNetworkStateChangeWithConnectedInfoDifferentInstanceIgnores() {
Dispatcher dispatcher = createDispatcher(serviceMock);
NetworkInfo info = mockNetworkInfo(true);
dispatcher.performNetworkStateChange(info);
verifyZeroInteractions(service);
}
代码示例来源:origin: neo4j/neo4j
@Test
void closeVerifiesUniquenessOfAddedAndChangedValues() throws Exception
{
SchemaIndex index = mock( SchemaIndex.class );
UniqueLuceneIndexPopulatingUpdater updater = newUpdater( index );
updater.process( add( 1, descriptor, "added1" ) );
updater.process( add( 2, descriptor, "added2" ) );
updater.process( change( 3, descriptor, "before1", "after1" ) );
updater.process( change( 4, descriptor, "before2", "after2" ) );
updater.process( remove( 5, descriptor, "removed1" ) );
verifyZeroInteractions( index );
updater.close();
verifyVerifyUniqueness( index, descriptor, "added1", "added2", "after1", "after2" );
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void return_400_on_get_request() throws Exception {
when(request.getMethod()).thenReturn("GET");
underTest.doFilter(request, response, chain);
verifyZeroInteractions(jwtHttpHandler, chain);
verify(response).setStatus(400);
}
代码示例来源:origin: SonarSource/sonarqube
@Test
public void onStart_has_no_effect() {
CeTask mockedCeTask = mock(CeTask.class);
fullMockedUnderTest.onStart(mockedCeTask);
verifyZeroInteractions(mockedCeTask, notificationService, dbClientMock, serializer, system2);
}
内容来源于网络,如有侵权,请联系作者删除!