Mocking Iterable with List using Mockito
"onlinedev" <[email protected]> Sat, 26 Nov 2016 16:21:38 +0000
| Newsgroups | gmane.comp.java.netbeans.devel |
|---|---|
| Message-ID | <[email protected]> |
Hi all,
I want to create a test for the following code:
public List<CustomerDto> getAll() {
Iterable<Customer> ups = dao.findAll();
List<CustomerDto> dtos = new ArrayList<>();
for (Customer entity : ups) {
dtos.add(mapper.map(entity, CustomerDto.class));
}
return dtos;
}
Can you please let me know how to mock Iterable with List using Mockito?
So far I have the following code:
@Test
public void testGetAll(){
CustomerDto customerDto = mock(CustomerDto.class);
Iterable<Customer> customerIterator = mockCustomerDao.findAll();
when(mockMapper.map(eq(CustomerDto.class), same(Customer.class)))
.thenReturn(new Customer());
}
P.S. I'm using Dozer Java Bean.
Interface CustomerDao extends ElasticsearchCrudRepository<Customer, String>