Re: Mocking Iterable with List using Mockito
John McDonnell <[email protected]> Sun, 27 Nov 2016 21:48:51 +0000
| Newsgroups | gmane.comp.java.netbeans.devel |
|---|---|
| Message-ID | <[email protected]> |
No really a Netbeans question but have a look at: http://christopher-batey.blogspot.ie/2013/06/mocking-iterable-objects-generically.html <http://christopher-batey.blogspot.ie/2013/06/mocking-iterable-objects-generically.html> It might help… Regards John > On 26 Nov 2016, at 16:21, onlinedev <[email protected]> wrote: > > 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> > > > >