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

css - Which browser returns the correct result for getBoundingClientRect of an SVG element? -

gcc - Calling fftR4() in c from assembly -

Function that returns a formatted array in VBA -