NetBeans Forums

 FAQFAQ   SearchSearch   MemberlistMemberlist   RegisterRegister   ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 
  

Mocking Iterable with List using Mockito

 
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users
View previous topic :: View next topic  
Author Message
onlinedev



Joined: 26 Nov 2016
Posts: 9

PostPosted: Sat Nov 26, 2016 4:18 pm    Post subject: Mocking Iterable with List using Mockito Reply with quote

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>
Back to top
Display posts from previous:   
Post new topic   Reply to topic    NetBeans Forums -> Java EE Users All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum
You cannot attach files in this forum
You can download files in this forum


Powered by phpBB
By use of this website, you agree to the NetBeans Policies and Terms of Use. © 2012, Oracle Corporation and/or its affiliates. Sponsored by Oracle logo