本文整理了Java中org.mockito.Mockito.never()
方法的一些代码示例,展示了Mockito.never()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.never()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:never
[英]Alias to times(0)
, see Mockito#times(int)
Verifies that interaction did not happen. E.g:
verify(mock, never()).someMethod();
If you want to verify there were NO interactions with the mock check out Mockito#verifyZeroInteractions(Object...)or Mockito#verifyNoMoreInteractions(Object...)
See examples in javadoc for Mockito class
[中]化名为[$0$],请参阅Mockito#时报(int)
验证没有发生交互。例如:
verify(mock, never()).someMethod();
如果要验证与模拟没有交互,请检查Mockito#verifyZeroInteractions(对象…)或Mockito#verifyNoMoreInteractions(对象…)
有关Mockito类,请参见javadoc中的示例
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldCallOnError() throws Exception {
Callable<Object> func = mock(Callable.class);
Throwable throwable = new IllegalStateException("Test exception");
when(func.call()).thenThrow(throwable);
Observable<Object> fromCallableObservable = Observable.fromCallable(func);
Observer<Object> observer = TestHelper.mockObserver();
fromCallableObservable.subscribe(observer);
verify(observer, never()).onNext(any());
verify(observer, never()).onComplete();
verify(observer).onError(throwable);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipEverything() {
Observable<Integer> src = Observable.just(1, 2, 3, 4, 3, 2, 1);
src.skipWhile(LESS_THAN_FIVE).subscribe(w);
verify(w, never()).onNext(anyInt());
verify(w, never()).onError(any(Throwable.class));
verify(w, times(1)).onComplete();
}
代码示例来源:origin: google/guava
public void testAddDelayedShutdownHook_success() throws InterruptedException {
TestApplication application = new TestApplication();
ExecutorService service = mock(ExecutorService.class);
application.addDelayedShutdownHook(service, 2, TimeUnit.SECONDS);
verify(service, Mockito.never()).shutdown();
application.shutdown();
InOrder shutdownFirst = Mockito.inOrder(service);
shutdownFirst.verify(service).shutdown();
shutdownFirst.verify(service).awaitTermination(2, TimeUnit.SECONDS);
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldCallOnNextAndOnCompleted() throws Exception {
Callable<String> func = mock(Callable.class);
when(func.call()).thenReturn("test_value");
Observable<String> fromCallableObservable = Observable.fromCallable(func);
Observer<Object> observer = TestHelper.mockObserver();
fromCallableObservable.subscribe(observer);
verify(observer).onNext("test_value");
verify(observer).onComplete();
verify(observer, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testToMultimap() {
Flowable<String> source = Flowable.just("a", "b", "cc", "dd");
Single<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc);
Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>();
expected.put(1, Arrays.asList("a", "b"));
expected.put(2, Arrays.asList("cc", "dd"));
mapped.subscribe(singleObserver);
verify(singleObserver, never()).onError(any(Throwable.class));
verify(singleObserver, times(1)).onSuccess(expected);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDeferFunctionThrows() throws Exception {
Callable<Observable<String>> factory = mock(Callable.class);
when(factory.call()).thenThrow(new TestException());
Observable<String> result = Observable.defer(factory);
Observer<String> o = TestHelper.mockObserver();
result.subscribe(o);
verify(o).onError(any(TestException.class));
verify(o, never()).onNext(any(String.class));
verify(o, never()).onComplete();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipTwoElements() {
Observable<String> skip = Observable.just("one", "two", "three").skip(2);
Observer<String> observer = TestHelper.mockObserver();
skip.subscribe(observer);
verify(observer, never()).onNext("one");
verify(observer, never()).onNext("two");
verify(observer, times(1)).onNext("three");
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testUnsubscribeSource() throws Exception {
Action unsubscribe = mock(Action.class);
Observable<Integer> o = Observable.just(1).doOnDispose(unsubscribe).cache();
o.subscribe();
o.subscribe();
o.subscribe();
verify(unsubscribe, never()).run();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSkipEmpty() {
Observable<Integer> src = Observable.empty();
src.skipWhile(LESS_THAN_FIVE).subscribe(w);
verify(w, never()).onNext(anyInt());
verify(w, never()).onError(any(Throwable.class));
verify(w, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testSuccess() throws Exception {
@SuppressWarnings("unchecked")
Future<Object> future = mock(Future.class);
Object value = new Object();
when(future.get()).thenReturn(value);
Observer<Object> o = TestHelper.mockObserver();
TestObserver<Object> to = new TestObserver<Object>(o);
Observable.fromFuture(future).subscribe(to);
to.dispose();
verify(o, times(1)).onNext(value);
verify(o, times(1)).onComplete();
verify(o, never()).onError(any(Throwable.class));
verify(future, never()).cancel(true);
}
代码示例来源:origin: ReactiveX/RxJava
@Test(timeout = 2000)
public void testRepeatZero() {
Observer<Object> o = TestHelper.mockObserver();
Observable.just(1).repeat(0).subscribe(o);
verify(o).onComplete();
verify(o, never()).onNext(any());
verify(o, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void fromSubscription() {
Subscription s = mock(Subscription.class);
Disposables.fromSubscription(s).dispose();
verify(s).cancel();
verify(s, never()).request(anyInt());
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTake2() {
Observable<String> w = Observable.fromIterable(Arrays.asList("one", "two", "three"));
Observable<String> take = w.take(1);
Observer<String> observer = TestHelper.mockObserver();
take.subscribe(observer);
verify(observer, times(1)).onNext("one");
verify(observer, never()).onNext("two");
verify(observer, never()).onNext("three");
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFailure() throws Exception {
@SuppressWarnings("unchecked")
Future<Object> future = mock(Future.class);
RuntimeException e = new RuntimeException();
when(future.get()).thenThrow(e);
Observer<Object> o = TestHelper.mockObserver();
TestObserver<Object> to = new TestObserver<Object>(o);
Observable.fromFuture(future).subscribe(to);
to.dispose();
verify(o, never()).onNext(null);
verify(o, never()).onComplete();
verify(o, times(1)).onError(e);
verify(future, never()).cancel(true);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testTakeLastEmpty() {
Observable<String> w = Observable.empty();
Observable<String> take = w.takeLast(2);
Observer<String> observer = TestHelper.mockObserver();
take.subscribe(observer);
verify(observer, never()).onNext(any(String.class));
verify(observer, never()).onError(any(Throwable.class));
verify(observer, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldCallOnError() throws Exception {
Callable<Object> func = mock(Callable.class);
Throwable throwable = new IllegalStateException("Test exception");
when(func.call()).thenThrow(throwable);
Flowable<Object> fromCallableFlowable = Flowable.fromCallable(func);
Subscriber<Object> subscriber = TestHelper.mockSubscriber();
fromCallableFlowable.subscribe(subscriber);
verify(subscriber, never()).onNext(any());
verify(subscriber, never()).onComplete();
verify(subscriber).onError(throwable);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() {
Observable<String> src = Observable.just("a", "b", "c");
src.filter(IS_D).first("default").subscribe(wo);
verify(wo, times(1)).onSuccess(anyString());
verify(wo, times(1)).onSuccess("default");
verify(wo, never()).onError(any(Throwable.class));
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testDeferFunctionThrows() throws Exception {
Callable<Flowable<String>> factory = mock(Callable.class);
when(factory.call()).thenThrow(new TestException());
Flowable<String> result = Flowable.defer(factory);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
result.subscribe(subscriber);
verify(subscriber).onError(any(TestException.class));
verify(subscriber, never()).onNext(any(String.class));
verify(subscriber, never()).onComplete();
}
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testCountError() {
Flowable<String> f = Flowable.error(new Callable<Throwable>() {
@Override
public Throwable call() {
return new RuntimeException();
}
});
f.count().subscribe(wo);
verify(wo, never()).onSuccess(anyInt());
verify(wo, times(1)).onError(any(RuntimeException.class));
}
代码示例来源:origin: ReactiveX/RxJava
@SuppressWarnings("unchecked")
@Test
public void shouldCallOnNextAndOnCompleted() throws Exception {
Callable<String> func = mock(Callable.class);
when(func.call()).thenReturn("test_value");
Flowable<String> fromCallableFlowable = Flowable.fromCallable(func);
Subscriber<String> subscriber = TestHelper.mockSubscriber();
fromCallableFlowable.subscribe(subscriber);
verify(subscriber).onNext("test_value");
verify(subscriber).onComplete();
verify(subscriber, never()).onError(any(Throwable.class));
}
内容来源于网络,如有侵权,请联系作者删除!