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 -> NetBeans Developers
View previous topic :: View next topic  
Author Message
onlinedev



Joined: 26 Nov 2016
Posts: 9

PostPosted: Sat Nov 26, 2016 4:21 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
satory



Joined: 28 May 2013
Posts: 23

PostPosted: Sun Nov 27, 2016 9:50 pm    Post subject: Mocking Iterable with List using Mockito Reply with quote

No really a Netbeans question but have a look at:http://christopher-batey.blogspot.ie/2013/06/mocking-iterable-objects-generically.html

It might help…

Regards

John
Quote:
On 26 Nov 2016, at 16:21, onlinedev <address-removed ([email]address-removed[/email])> 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:@Testpublic 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 -> NetBeans Developers 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