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
Post a Comment