BillServiceImpl extends BaseEntityDataServiceImpl<Bill> implements IEntityAuthorizationPrivileges
        , IBillService { @Override @Authorized({ PrivilegeConstants.MANAGE_BILLS }) @Transactional public Bill save(Bill bill) { if (bill == null) { throw new NullPointerException("The bill must be defined."); } if (bill.getTotal().compareTo(BigDecimal.ZERO) < 0 && !Context.hasPrivilege(PrivilegeConstants.REFUND_MONEY)) { throw new AccessControlException("Access denied to give a refund."); } IReceiptNumberGenerator generator = ReceiptNumberGeneratorFactory.getGenerator(); if (generator == null) { LOG.warn("No receipt number generator has been defined. Bills will not be given a receipt number until one is" + " defined."); } else { if (StringUtils.isEmpty(bill.getReceiptNumber())) { bill.setReceiptNumber(generator.generateNumber(bill)); } } return super.save(bill); }  @Override @Authorized({ PrivilegeConstants.MANAGE_BILLS }) @Transactional Bill save(Bill bill); @Override @Authorized({ PrivilegeConstants.VIEW_BILLS }) @Transactional(readOnly = true) Bill getBillByReceiptNumber(String receiptNumber); @Override List<Bill> getBillsByPatient(Patient patient, PagingInfo paging); @Override List<Bill> getBillsByPatientId(int patientId, PagingInfo paging); @Override List<Bill> getBills(final BillSearch billSearch); @Override List<Bill> getBills(final BillSearch billSearch, PagingInfo pagingInfo); @Override List<Bill> getAll(boolean includeVoided, PagingInfo pagingInfo); @Override Bill getById(int entityId); @Override Bill getByUuid(String uuid); @Override List<Bill> getAll(); @Override String getVoidPrivilege(); @Override String getSavePrivilege(); @Override String getPurgePrivilege(); @Override String getGetPrivilege();  }
@Test(expected = APIException.class) public void save_shouldThrowAPIExceptionIfReceiptNumberCannotBeGenerated() throws Exception { Bill bill = createEntity(true); bill.setReceiptNumber(null); when(receiptNumberGenerator.generateNumber(bill)) .thenThrow(new APIException("Test exception")); service.save(bill); }