@Overridepublic void storeInfoInStaging(StagingInfo stagingInfo) throws BusinessException {

 INotificaDao iNotificaDao=NotificaDaoFactory.getInstance().getNotificaDao();try {iNotificaDao.storeInfoInStaging(stagingInfo);} catch (DataException e) {LOGGER.error(e.getMessage(), e);throw new BusinessException(NotificaConstants.DB_ERROR_CODE, NotificaConstants.DB_ERROR_MESSAGE);}}
  • 2
    first you decide what you want to test, then you write the test, then you run it. if it's strictly about 'how to use Mockito', that depends on what you want to do with it, there are enough Mockito tutorials/documentation around to help starting with that– StultuskeMay 18 at 6:54
  • This method is pure boiler-plate. I'd just test the implementation of INotificaDao instead and call it a day.– ThiloMay 18 at 6:56
  • 1
    Better you take care of such methods in Integration Test– Yati SawhneyMay 18 at 6:58
  • 1
    If you did want to test it, you should inject iNotificaDao instead of looking it up from the global factory. Failing that, you'd have to instrument that global factory to return your mock implementation.– ThiloMay 18 at 6:58
  • Thank u Stultuske,Thilo ,Yati Sawhney– charlie rawoolMay 18 at 7:06

I do not know your className, you need to replace your className your own className. Maybe, you can do something like that just check for the method really invoke method.

 @Mockprivate INotificationDao iNotificationDao;private ClassName className;@Beforepublic void init() {className=spy(new ClassName());}@Testpublic void storeInfoInStagingGivenStaginInfoValid() {Mockito.doNothing().when(className).storeInfoStaging(stagingInfo);className.storeInfoStaging(storeInfo);Mockito.verify(iNotificaDao, atLeastOnce()).storeInfoStaging(staginInfo);}
  • yes, it is working. Thanxx @haticeSigirci– charlie rawoolMay 18 at 9:09
  • you're welcome, please could you accept my answer ? @charlierawool– haticeSigirciMay 18 at 10:23

Your Answer

 

By clicking "Post Your Answer", you acknowledge that you have read our updated terms of service, privacy policy and cookie policy, and that your continued use of the website is subject to these policies.

Not the answer you're looking for? Browse other questions tagged or ask your own question.