0

I am trying to Unit Test a method for which I need to create the object of the class using a constructor.This is how the constructor looks like :

public WebformsClinEventBusiness(Webform webForm, String dataEntryModel, String obsBatId)              {
this.webformObj         = webForm;
this.eventObj           = webForm.getEvent(obsBatId);
this.progressNoteText   = webForm.getProgressNoteNext();
this.formValues         = webForm.getFormValues();
this.lastFormValues     = webForm.getLastFormValues();
this.emptyFormValues    = webForm.getEmptyFormValues();
this.formVersion        = webForm.getFormVersion();
this.dataEntryModel     = dataEntryModel;
this.headerValues       = webForm.getHeaderValues();
this.OBS_BAT_ID         = obsBatId;
this.userPreferences    =  (CompSoapUserPreferences)webForm.getRequest().getSession(false).getAttribute(userPreferences.getSESName());
}

The problem is in the last line. I have a mock webform object and have set the expectations like this:

one (mockWebForm).getRequest();
will(returnValue(mockRequest));
one (mockRequest).getSession(false);
will(returnValue(mockSession));


allowing (mockSession).getAttribute(_SES_NAME);
will(returnValue(mockCompSoapUserPreferences));
allowing (mockCompSoapUserPreferences).getSESName();
will(returnValue(_SES_NAME));

When the code hits webform.getRequest() instead of calling the mock it calls the actual method which returns null and I end up with a null pointer exception.

Any ideas ? I would really appreciate any input on this.

Thanks for your time !

4

0 回答 0