When I unit test with a mock @Service, I notice that in the Mockito.when() statement, when I save the real object, I get null as return; and I have to use any().
So, instead of using:
@Mock
private BinInfoService service;
...
@Test
public void testSave() {
SomeBean bean = new SomeBean();
Mockito.when(service.saveBinInfo(bean).thenReturn(bean);
}
I have to use:
Mockito.when(service.saveBinInfo(Mockito.any(SomeBean.class))).thenReturn(bean);
The first form returns null. While the second form returns the saved entity.
Why?
Aucun commentaire:
Enregistrer un commentaire