1

I want to test method returning the void. What i should correct ?

public class ServicesTest 
{
@Mock
ClientDao clientDaoMock;

@InjectMocks
@Autowired
ClientService clientService;

@Before
public void setUp() throws Exception {
    MockitoAnnotations.initMocks(this);
}
//FixMe
@Test
public void saveClient() {
    when(clientDaoMock.saveClient(any(Client.class))).thenReturn(true);

    }
Kalamarico
  • 5,466
  • 22
  • 53
  • 70

1 Answers1

0

You should interact with your mock in the test method, either directly or indirectly through your clientService. You got the exception in your comment because there were no calls to saveClient during the test.

After that, you can verify if a method is called with specific parameters. It should look something like the following:

@Test
public void saveClient() {
   // Any interaction with the mock, like:
   clientDaoMock.saveClient(aClient)
   verify(clientDaoMock, times(1)).saveClient(any(Client.class));
}
Oresztesz
  • 2,294
  • 1
  • 15
  • 26