Mocking a database DAO returning list(s) in Mockito

Reading Time: < 1 minute

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()));