@Test public void shouldThrowExceptionIfProductCodeMissing() throws Exception { Report report = make(a(ReportBuilder.defaultReport)); String productCode = null; report.setProducts(asList(make(a(RnrLineItemBuilder.defaultRnrLineItem, with(RnrLineItemBuilder.productCode, productCode))))); expectedException.expect(DataException.class); expectedException.expectMessage("error.mandatory.fields.missing"); report.validateForApproval(); }
public void validateForApproval() { if (products == null || isEmpty(approverName)) { throw new DataException("error.mandatory.fields.missing"); } for (RnrLineItem rnrLineItem : products) { if (isEmpty(rnrLineItem.getProductCode()) || rnrLineItem.getQuantityApproved() == null) throw new DataException("error.mandatory.fields.missing"); if (rnrLineItem.getQuantityApproved() < 0) throw new DataException("error.restapi.quantity.approved.negative"); } }
Report { public void validateForApproval() { if (products == null || isEmpty(approverName)) { throw new DataException("error.mandatory.fields.missing"); } for (RnrLineItem rnrLineItem : products) { if (isEmpty(rnrLineItem.getProductCode()) || rnrLineItem.getQuantityApproved() == null) throw new DataException("error.mandatory.fields.missing"); if (rnrLineItem.getQuantityApproved() < 0) throw new DataException("error.restapi.quantity.approved.negative"); } } }
Report { public void validateForApproval() { if (products == null || isEmpty(approverName)) { throw new DataException("error.mandatory.fields.missing"); } for (RnrLineItem rnrLineItem : products) { if (isEmpty(rnrLineItem.getProductCode()) || rnrLineItem.getQuantityApproved() == null) throw new DataException("error.mandatory.fields.missing"); if (rnrLineItem.getQuantityApproved() < 0) throw new DataException("error.restapi.quantity.approved.negative"); } }  }
Report { public void validateForApproval() { if (products == null || isEmpty(approverName)) { throw new DataException("error.mandatory.fields.missing"); } for (RnrLineItem rnrLineItem : products) { if (isEmpty(rnrLineItem.getProductCode()) || rnrLineItem.getQuantityApproved() == null) throw new DataException("error.mandatory.fields.missing"); if (rnrLineItem.getQuantityApproved() < 0) throw new DataException("error.restapi.quantity.approved.negative"); } }  void validate(); Date getClientSubmittedTime(); @JsonIgnore Rnr getRequisition(Long requisitionId, Long modifiedBy); void validateForApproval(); static Report prepareForREST(final Rnr rnr); }
Report { public void validateForApproval() { if (products == null || isEmpty(approverName)) { throw new DataException("error.mandatory.fields.missing"); } for (RnrLineItem rnrLineItem : products) { if (isEmpty(rnrLineItem.getProductCode()) || rnrLineItem.getQuantityApproved() == null) throw new DataException("error.mandatory.fields.missing"); if (rnrLineItem.getQuantityApproved() < 0) throw new DataException("error.restapi.quantity.approved.negative"); } }  void validate(); Date getClientSubmittedTime(); @JsonIgnore Rnr getRequisition(Long requisitionId, Long modifiedBy); void validateForApproval(); static Report prepareForREST(final Rnr rnr);  }