@Override protected void setUp() throws Exception { super.setUp(); hasher = mock(Hasher.class); hashFunction = mock(HashFunction.class); when(hashFunction.newHasher()).thenReturn(hasher); }
@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(); }
@Test public void entryEqualsSameInstance() { AnnotationMetadata metadata = mock(AnnotationMetadata.class); Group.Entry entry = new Group.Entry(metadata, "com.example.Test"); assertEquals(entry, entry); }
@Test public void interceptShouldAddHeader() throws Exception { SimpleClientHttpRequestFactory requestFactory = new SimpleClientHttpRequestFactory(); ClientHttpRequest request = requestFactory.createRequest(new URI("http://example.com"), HttpMethod.GET); ClientHttpRequestExecution execution = mock(ClientHttpRequestExecution.class); byte[] body = new byte[] {}; new BasicAuthorizationInterceptor("spring", "boot").intercept(request, body, execution); verify(execution).execute(request, body); assertEquals("Basic c3ByaW5nOmJvb3Q=", request.getHeaders().getFirst("Authorization")); }
@Test public void testCancelledBeforeSubscribe() throws Exception { @SuppressWarnings("unchecked") Future<Object> future = mock(Future.class); CancellationException e = new CancellationException("unit test synthetic cancellation"); when(future.get()).thenThrow(e); Observer<Object> o = TestHelper.mockObserver(); TestObserver<Object> to = new TestObserver<Object>(o); to.dispose(); Observable.fromFuture(future).subscribe(to); to.assertNoErrors(); to.assertNotComplete(); }
private void supportsEventType( boolean match, Class<? extends ApplicationListener> listenerType, ResolvableType eventType) { ApplicationListener<?> listener = mock(listenerType); GenericApplicationListenerAdapter adapter = new GenericApplicationListenerAdapter(listener); assertEquals("Wrong match for event '" + eventType + "' on " + listenerType.getClass().getName(), match, adapter.supportsEventType(eventType)); }
public void testAddDelayedShutdownHook_interrupted() throws InterruptedException { TestApplication application = new TestApplication(); ExecutorService service = mock(ExecutorService.class); application.addDelayedShutdownHook(service, 2, TimeUnit.SECONDS); when(service.awaitTermination(2, TimeUnit.SECONDS)).thenThrow(new InterruptedException()); application.shutdown(); verify(service).shutdown(); }
@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(); }
@Test public void getCronTasks() { CronTask mockCronTask = mock(CronTask.class); List<CronTask> cronTaskList = Collections.singletonList(mockCronTask); this.taskRegistrar.setCronTasksList(cronTaskList); List<CronTask> retrievedList = this.taskRegistrar.getCronTaskList(); assertEquals(1, retrievedList.size()); assertEquals(mockCronTask, retrievedList.get(0)); }
@Test public void testCancelledBeforeSubscribe() throws Exception { @SuppressWarnings("unchecked") Future<Object> future = mock(Future.class); CancellationException e = new CancellationException("unit test synthetic cancellation"); when(future.get()).thenThrow(e); Subscriber<Object> subscriber = TestHelper.mockSubscriber(); TestSubscriber<Object> ts = new TestSubscriber<Object>(subscriber); ts.dispose(); Flowable.fromFuture(future).subscribe(ts); ts.assertNoErrors(); ts.assertNotComplete(); }
private void testSupports(MethodParameter returnType, boolean supports) { ViewResolutionResultHandler resultHandler = resultHandler(mock(ViewResolver.class)); HandlerResult handlerResult = new HandlerResult(new Object(), null, returnType, this.bindingContext); assertEquals(supports, resultHandler.supports(handlerResult)); }
@Override protected void setUp() throws Exception { super.setUp(); hasher = mock(Hasher.class); hashFunction = mock(HashFunction.class); buffer = new ByteArrayInputStream(testBytes); when(hashFunction.newHasher()).thenReturn(hasher); }
@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(); }
@Test public void getFixedRateTasks() { IntervalTask mockFixedRateTask = mock(IntervalTask.class); List<IntervalTask> fixedRateTaskList = Collections.singletonList(mockFixedRateTask); this.taskRegistrar.setFixedRateTasksList(fixedRateTaskList); List<IntervalTask> retrievedList = this.taskRegistrar.getFixedRateTaskList(); assertEquals(1, retrievedList.size()); assertEquals(mockFixedRateTask, retrievedList.get(0)); }
@SuppressWarnings("unchecked") @Override protected void setUp() { backingMap = mock(ConcurrentMap.class); when(backingMap.isEmpty()).thenReturn(true); multiset = new ConcurrentHashMultiset<>(backingMap); }