I would like to make fun of the call ScheduledExecutorServiceto return the mock of the class ScheduledFuturewhen the method is called schedule. This code works beautifully:
ScheduledExecutorService executor = Mockito.mock(ScheduledExecutorService.class);
ScheduledFuture future = Mockito.mock(ScheduledFuture.class);
Mockito.when(executor.schedule(
Mockito.any(Runnable.class),
Mockito.anyLong(),
Mockito.any(TimeUnit.class))
).thenReturn(future); // <-- warning here
except that in the last line I get an unverified warning:
found raw type: java.util.concurrent.ScheduledFuture
missing type arguments for generic class java.util.concurrent.ScheduledFuture<V>
unchecked method invocation: method thenReturn in interface org.mockito.stubbing.OngoingStubbing is applied to given types
required: T
found: java.util.concurrent.ScheduledFuture
unchecked conversion
required: T
found: java.util.concurrent.ScheduledFuture
Can these warnings be avoided somehow?
Type code ScheduledFuture<?> future = Mockito.mock(ScheduledFuture.class);does not compile.
source
share