我需要从 java.util.concurrent 中嘲笑执行器。我的代码如下:
@RunWith(PowerMockRunner.class)
@PowerMockRunnerDelegate(Sputnik.class)
@PrepareForTest([Executors.class, ClassThatCallsExecutors.class])
class WorkerManagerSpec extends Specification {
ExecutorService executorService
def "...."() {
when:"...."
PowerMockito.mockStatic(Executors.class)
PowerMockito.when(Executors.newFixedThreadPool(2)).thenReturn(executorService)
}
}
但是我遇到 power-mockito版本1.7.4
的错误> org.mockito.exceptions.misusing.MissingMethodInvocationException:
> [Ljava.lang.Object;@6bea52d4 when() requires an argument which has to
> be 'a method call on a mock'.
有什么方法可以解决此问题?我怀疑那里有一些依赖问题。