I'm trying to test methods inside my controller and one of the classes have creation of the object inside it like this:
NewPaymentModel pModel = new NewPaymentModel();
Then I have if statement:
if (pModel.getErrors().isEmpty()) {
This is exactly what I want to mock. My code is below:
Pr4Error error = Mockito.mock(Pr4Error.class);
List<Pr4Error> listOfErrors = new ArrayList<>();
listOfErrors.add(error);
final NewPaymentModel pModel =
PowerMockito.mock(NewPaymentModel.class, Mockito.RETURNS_DEEP_STUBS);
PowerMockito.whenNew(NewPaymentModel.class).withNoArguments().
thenReturn(pModel);
Mockito.doReturn(pModel).when(facade).addNewPayment(pModel);
when(pModel.getErrors().isEmpty()).thenReturn(true);
EDIT. What I got when run unit tests is nullpointerexception on last line of code.