Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

The method when(T) in the type Stubber is not applicable for the arguments (void)

Tags:

java

mockito

I am getting following error when stubbing a void:

The method when(T) in the type Stubber is not applicable for the arguments (void)

Here is my sample code:

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

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

What am I missing ?

like image 302
user3123934 Avatar asked Sep 03 '15 15:09

user3123934


1 Answers

Your brackets are in the wrong place, try this:

doNothing().when(mockRegistrationPeristImpl).create(any(Registration.class));
like image 137
codebox Avatar answered Nov 20 '22 11:11

codebox