私はScheduledExecutorService
をモックしようとしていますが、ジェネリックに問題があります。私はジェネリックなしScheduledFuture
を宣言する場合は、警告をコンパイルし、Java Generics:<?>対キャプチャ<?>
Error:(20, 109) java: no suitable method found for
thenReturn(java.util.concurrent.ScheduledFuture<capture#1 of ?>)
method org.mockito.stubbing.OngoingStubbing.thenReturn(java.util.concurrent.ScheduledFuture<capture#2 of ?>) is not applicable
(argument mismatch; java.util.concurrent.ScheduledFuture<capture#1 of ?> cannot be converted to java.util.concurrent.ScheduledFuture<capture#2 of ?>)
method org.mockito.stubbing.OngoingStubbing.thenReturn(java.util.concurrent.ScheduledFuture<capture#2 of ?>,java.util.concurrent.ScheduledFuture<capture#2 of ?>...) is not applicable
(argument mismatch; java.util.concurrent.ScheduledFuture<capture#1 of ?> cannot be converted to java.util.concurrent.ScheduledFuture<capture#2 of ?>)
:
ScheduledFuture<?> future = mock(ScheduledFuture.class);
ScheduledExecutorService scheduledExecutorService =
Mockito.mock(ScheduledExecutorService.class);
when(scheduledExecutorService.schedule(Mockito.any(Runnable.class), anyLong(), any(TimeUnit.class))).thenReturn(future);
これは、次のエラーでコンパイルできません:
はここでスニペットです。
ScheduledFuture future
正しい方法はありますか?つまり、警告なしでコンパイルするようなワイルドカードはありますか?