java - Mockito: How do I mock an instance creation? -


consider need mock following line

employee.addoffer(employee, new offer(details)); 

now need mock new offer(details) nothing

the way try is

donothing().when(employee).addoffer(any(employee.class), any(offer.class)); 

this fails nullpointerexception because tries execute new offer(details) , details nothing

how can mock new offer(details) return other mock?

you should mock offer:

offer mockoffer = mock(offer.class); employee.addoffer(employee, mockoffer); 

Comments

Popular posts from this blog

mod rewrite - Using "?" when rewriting the URL -

.htaccess: Transfer name to index.php if not directory public -

Admob integration with pygame in android -