java - Mockito - Spring Mvc Service test (Null pointer) -


i'm new testing side.i'm using spring mvc in application. followed tutorials write controller , service test case. i'm facing error in service test. please !

service :

@autowired private patientdao patientdao;  @autowired private prefixdao prefixdao;  public patient createpatient(patient patient) throws exception {     patient.setageordob();     return createpatientinsync(patient); }  private synchronized patient createpatientinsync(patient patient)             throws exception {         try {             prefix prefix = prefixdao.getprefixfortype(prefixtype.patient);             patient.setpatientno(prefix.getprefixednumber());             patientdao.createpatient(patient); //save patient             prefixdao.incrementprefix(prefix);         } catch (constraintviolationexception ex) {             throw new internalerrorexception("please enter valid data", ex);         } catch (nullpointerexception e) {             e.printstacktrace();             throw new internalerrorexception(                     "please create prefix patient", e);         }         return patient;     } 

service test case:

@contextconfiguration(locations = {         "classpath:/applicationcontext-resources.xml",         "classpath:/applicationcontext-service.xml",         "classpath:/applicationcontext-dao.xml",         "classpath:/applicationcontext.xml" }) @runwith(springjunit4classrunner.class) public class patientservicetest {      @autowired     @mock     private patientdao patientdao;      @injectmocks     private patientserviceimpl patientservice = new patientserviceimpl();      private prefixdao prefixdao;       @before     public void dosetup() {         patientdao = mock(patientdao.class);         prefixdao = mock(prefixdao.class);         // mockito.mock(patientdao.class);     }      @before     public void initmocks() {         mockitoannotations.initmocks(this);     }      @test     public void testsaveuser() throws exception {          patient mockpatient = new patient();         mockpatient.setfirstname("aravinth");         mockpatient.setsex(gender.male);         mockpatient.setageordob("24");          prefix prefix = new prefix();         prefix.setprefixtype(prefixtype.patient);         prefix.setprefix("pat-");         prefix.setsequenceno(23);          when(prefixdao.getprefixfortype(prefixtype.patient)).thenreturn(prefix);         system.out.println(prefix.getsequenceno());          mockpatient = patientservice.createpatient(mockpatient);          assertequals("aravinth", mockpatient.getfirstname());           verify(patientdao, times(1)).createpatient(mockpatient);     } } 

verify times works fine.i got nullpointer in assertequals.


Comments

Popular posts from this blog

html - Outlook 2010 Anchor (url/address/link) -

javascript - Why does running this loop 9 times take 100x longer than running it 8 times? -

Getting gateway time-out Rails app with Nginx + Puma running on Digital Ocean -