本文整理了Java中org.mockito.Mockito.any()
方法的一些代码示例,展示了Mockito.any()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。Mockito.any()
方法的具体详情如下:
包路径:org.mockito.Mockito
类名称:Mockito
方法名:any
暂无
代码示例来源:origin: spring-projects/spring-framework
private <T> HandlerMethodArgumentResolver stubResolver(Mono<Object> stubValue) {
HandlerMethodArgumentResolver resolver = mock(HandlerMethodArgumentResolver.class);
when(resolver.supportsParameter(any())).thenReturn(true);
when(resolver.resolveArgument(any(), any(), any())).thenReturn(stubValue);
return resolver;
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testToMultimap() {
Observable<String> source = Observable.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 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: 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 testComplete() {
Observable<String> source = Observable.empty();
Observable<List<String>> buffered = source.buffer(3, 3);
buffered.subscribe(observer);
Mockito.verify(observer, Mockito.never()).onNext(Mockito.<String>anyList());
Mockito.verify(observer, Mockito.never()).onError(Mockito.any(Throwable.class));
Mockito.verify(observer, Mockito.times(1)).onComplete();
}
代码示例来源:origin: spring-projects/spring-framework
@Test
public void handleMessage() {
TestSimpUser simpUser = new TestSimpUser("joe");
simpUser.addSessions(new TestSimpSession("123"));
when(this.registry.getUser("joe")).thenReturn(simpUser);
given(this.brokerChannel.send(Mockito.any(Message.class))).willReturn(true);
this.handler.handleMessage(createWith(SimpMessageType.MESSAGE, "joe", "123", "/user/joe/queue/foo"));
ArgumentCaptor<Message> captor = ArgumentCaptor.forClass(Message.class);
Mockito.verify(this.brokerChannel).send(captor.capture());
SimpMessageHeaderAccessor accessor = SimpMessageHeaderAccessor.wrap(captor.getValue());
assertEquals("/queue/foo-user123", accessor.getDestination());
assertEquals("/user/queue/foo", accessor.getFirstNativeHeader(ORIGINAL_DESTINATION));
}
代码示例来源:origin: spring-projects/spring-framework
@Before
public void setup() throws Exception {
when(this.connection.getResponse(any(WebRequest.class))).thenThrow(new IOException(""));
}
代码示例来源:origin: spring-projects/spring-framework
private ExtensionContext buildExtensionContext(String methodName) {
Class<?> testClass = SpringTestCase.class;
Method method = ReflectionUtils.findMethod(getClass(), methodName);
Store store = mock(Store.class);
when(store.getOrComputeIfAbsent(any(), any(), any())).thenReturn(new TestContextManager(testClass));
ExtensionContext extensionContext = mock(ExtensionContext.class);
when(extensionContext.getTestClass()).thenReturn(Optional.of(testClass));
when(extensionContext.getElement()).thenReturn(Optional.of(method));
when(extensionContext.getStore(any())).thenReturn(store);
return extensionContext;
}
代码示例来源: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 testFirstOrElseWithPredicateOfSome() {
Observable<String> src = Observable.just("a", "b", "c", "d", "e", "f");
src.filter(IS_D).first("default").subscribe(wo);
verify(wo, times(1)).onSuccess(anyString());
verify(wo, times(1)).onSuccess("d");
verify(wo, never()).onError(any(Throwable.class));
}
代码示例来源: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
@Test
public void testComplete() {
Flowable<String> source = Flowable.empty();
Flowable<List<String>> buffered = source.buffer(3, 3);
buffered.subscribe(subscriber);
Mockito.verify(subscriber, Mockito.never()).onNext(Mockito.<String>anyList());
Mockito.verify(subscriber, Mockito.never()).onError(Mockito.any(Throwable.class));
Mockito.verify(subscriber, Mockito.times(1)).onComplete();
}
代码示例来源: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 testToMultimapWithValueSelector() {
Flowable<String> source = Flowable.just("a", "b", "cc", "dd");
Single<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc, duplicate);
Map<Integer, Collection<String>> expected = new HashMap<Integer, Collection<String>>();
expected.put(1, Arrays.asList("aa", "bb"));
expected.put(2, Arrays.asList("cccc", "dddd"));
mapped.subscribe(singleObserver);
verify(singleObserver, never()).onError(any(Throwable.class));
verify(singleObserver, times(1)).onSuccess(expected);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseOfNone() {
Observable<String> src = Observable.empty();
src.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 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: spring-projects/spring-framework
@SuppressWarnings("unchecked")
@Test
public void brokerUnavailableEvent() throws Exception {
ScheduledFuture future = Mockito.mock(ScheduledFuture.class);
when(this.taskScheduler.scheduleWithFixedDelay(any(Runnable.class), any(Long.class))).thenReturn(future);
BrokerAvailabilityEvent event = new BrokerAvailabilityEvent(true, this);
this.handler.onApplicationEvent(event);
verifyNoMoreInteractions(future);
event = new BrokerAvailabilityEvent(false, this);
this.handler.onApplicationEvent(event);
verify(future).cancel(true);
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testToMultimapObservable() {
Observable<String> source = Observable.just("a", "b", "cc", "dd");
Observable<Map<Integer, Collection<String>>> mapped = source.toMultimap(lengthFunc).toObservable();
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(objectObserver);
verify(objectObserver, never()).onError(any(Throwable.class));
verify(objectObserver, times(1)).onNext(expected);
verify(objectObserver, times(1)).onComplete();
}
代码示例来源:origin: ReactiveX/RxJava
@Test
public void testFirstOrElseWithPredicateOfNoneMatchingThePredicate() {
Flowable<String> src = Flowable.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 testSkipEverything() {
Flowable<Integer> src = Flowable.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();
}
内容来源于网络,如有侵权,请联系作者删除!