Mocking a database DAO returning list(s) in Mockito

Posted by

If you are mocking a database dao and would like to mock a method which returns a list of objects, you can create objects in Arrays as list and mock it example shown below

 

when(dbService.getPersonnel(personnelNumber)).thenReturn(
				Arrays.asList(new Object(), new Object()));

Leave a Reply

Your email address will not be published. Required fields are marked *