Stubber 类型中的方法 when(T) 不适用于参数 (void)

2022-09-02 08:59:59

我在存根 void 时收到以下错误:

Stubber 类型中的方法 when(T) 不适用于参数 (void)

这是我的示例代码:

doNothing().when(mockRegistrationPeristImpl.create(any(Registration.class)));

public void create(final T record) throws DataAccessException {
    try {
        entityManager.persist(record);
        entityManager.flush();
    } catch (PersistenceException ex) {}
}

我错过了什么?


答案 1

您的括号位置错误,请尝试以下操作:

doNothing().when(mockRegistrationPeristImpl).create(any(Registration.class));

答案 2

推荐