使用Spock的PowerMockito:无法从java.util.concurrent

时间:2018-10-29 13:50:07

标签: java groovy mockito spock powermock

我需要从 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'.

有什么方法可以解决此问题?我怀疑那里有一些依赖问题。

0 个答案:

没有答案