@Test(expected = BusinessException.class) public void testCancel03() { Reserve reserve = new Reserve("001"); reserve.setAdultCount(1); reserve.setChildCount(2); TourInfo tour = new TourInfo("01"); reserve.setTourInfo(tour); reserve.setTransfer(Reserve.NOT_TRANSFERED); when(reserveRepository.findById("001")).thenReturn(Optional.of( reserve)); when(reserveRepository.findOneForUpdate("001")).thenReturn(reserve); when(tourInfoSharedService.isOverPaymentLimit(tour)).thenReturn(true); try { reserveService.cancel("001"); fail("error route"); } catch (BusinessException e) { ResultMessages messages = e.getResultMessages(); assertThat(messages.isNotEmpty(), is(true)); assertThat(messages.getType(), is((ResultMessageType) ERROR)); assertThat(messages.getList().size(), is(1)); assertThat(messages.getList().get(0).getCode(), is( MessageId.E_TR_0002)); throw e; } }
@Override public void cancel(String reserveNo) throws BusinessException { Reserve reserve = findOne(reserveNo); String transfer = reserve.getTransfer(); if (Reserve.TRANSFERED.equals(transfer)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0001); throw new BusinessException(message); } TourInfo info = reserve.getTourInfo(); if (tourInfoSharedService.isOverPaymentLimit(info)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0002); throw new BusinessException(message); } reserve = reserveRepository.findOneForUpdate(reserveNo); if (reserve != null) { reserveRepository.deleteById(reserveNo); } else { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0003); throw new BusinessException(message); } log.debug("canceled reserveNo={}", reserveNo); }
ReserveServiceImpl implements ReserveService { @Override public void cancel(String reserveNo) throws BusinessException { Reserve reserve = findOne(reserveNo); String transfer = reserve.getTransfer(); if (Reserve.TRANSFERED.equals(transfer)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0001); throw new BusinessException(message); } TourInfo info = reserve.getTourInfo(); if (tourInfoSharedService.isOverPaymentLimit(info)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0002); throw new BusinessException(message); } reserve = reserveRepository.findOneForUpdate(reserveNo); if (reserve != null) { reserveRepository.deleteById(reserveNo); } else { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0003); throw new BusinessException(message); } log.debug("canceled reserveNo={}", reserveNo); } }
ReserveServiceImpl implements ReserveService { @Override public void cancel(String reserveNo) throws BusinessException { Reserve reserve = findOne(reserveNo); String transfer = reserve.getTransfer(); if (Reserve.TRANSFERED.equals(transfer)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0001); throw new BusinessException(message); } TourInfo info = reserve.getTourInfo(); if (tourInfoSharedService.isOverPaymentLimit(info)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0002); throw new BusinessException(message); } reserve = reserveRepository.findOneForUpdate(reserveNo); if (reserve != null) { reserveRepository.deleteById(reserveNo); } else { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0003); throw new BusinessException(message); } log.debug("canceled reserveNo={}", reserveNo); }  }
ReserveServiceImpl implements ReserveService { @Override public void cancel(String reserveNo) throws BusinessException { Reserve reserve = findOne(reserveNo); String transfer = reserve.getTransfer(); if (Reserve.TRANSFERED.equals(transfer)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0001); throw new BusinessException(message); } TourInfo info = reserve.getTourInfo(); if (tourInfoSharedService.isOverPaymentLimit(info)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0002); throw new BusinessException(message); } reserve = reserveRepository.findOneForUpdate(reserveNo); if (reserve != null) { reserveRepository.deleteById(reserveNo); } else { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0003); throw new BusinessException(message); } log.debug("canceled reserveNo={}", reserveNo); }  @Override Reserve findOne(String reserveNo); @Override List<Reserve> findAllByCustomerCode(String customerCode); @Override ReserveTourOutput reserve(
            ReserveTourInput input); @Override void cancel(String reserveNo); @Override ReservationUpdateOutput update(
            ReservationUpdateInput input); }
ReserveServiceImpl implements ReserveService { @Override public void cancel(String reserveNo) throws BusinessException { Reserve reserve = findOne(reserveNo); String transfer = reserve.getTransfer(); if (Reserve.TRANSFERED.equals(transfer)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0001); throw new BusinessException(message); } TourInfo info = reserve.getTourInfo(); if (tourInfoSharedService.isOverPaymentLimit(info)) { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0002); throw new BusinessException(message); } reserve = reserveRepository.findOneForUpdate(reserveNo); if (reserve != null) { reserveRepository.deleteById(reserveNo); } else { ResultMessages message = ResultMessages.error().add( MessageId.E_TR_0003); throw new BusinessException(message); } log.debug("canceled reserveNo={}", reserveNo); }  @Override Reserve findOne(String reserveNo); @Override List<Reserve> findAllByCustomerCode(String customerCode); @Override ReserveTourOutput reserve(
            ReserveTourInput input); @Override void cancel(String reserveNo); @Override ReservationUpdateOutput update(
            ReservationUpdateInput input);  }