简体   繁体   中英

how to test this method using mockito or Junit?

@Override public 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);
        }

    }

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.

  @Mock
  private INotificationDao iNotificationDao;
  private ClassName className;

  @Before
  public void init() {
    className = spy(new ClassName());
  }

  @Test
  public void storeInfoInStagingGivenStaginInfoValid() {
    Mockito.doNothing().when(className).storeInfoStaging(stagingInfo);
    className.storeInfoStaging(storeInfo);
    Mockito.verify(iNotificaDao, atLeastOnce()).storeInfoStaging(staginInfo);
  }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM