@Test public void testValidateRecompenseReportCreate() { RecompenseApplication app = new RecompenseApplication(); List<IssueItem> issueItemAddList = new ArrayList<IssueItem>(); List<GoodsTrans> goodsTransAddList = new ArrayList<GoodsTrans>(); boolean result = false; // 1. 都为空校验 try { result = RecompenseValidator.validateRecompenseReportCreate(app); fail("未抛出异常"); } catch (GeneralException e) { if (e.getErrorCode() .equals(RecompenseExceptionType.RECOMPENSE_REPORT_REQUIRE_ERROR.getErrorCode())) { assertTrue(true); } else { fail("抛出异常不正确"); } } app.setRecompenseMethod(null); app.setRecompenseType("11"); Waybill waybill = new Waybill(); waybill.setWaybillNumber("11"); app.setWaybill(waybill); app.setInsurType("111"); app.setInsurQuantity(123); app.setDeptId("123"); app.setInsurDate(new Date()); app.setClaimParty("aa"); app.setRecompenseAmount(123d); Member customer = new Member(); customer.setId("123"); app.setCustomer(customer); app.setCompanyPhone(null); // 2. app不为空,app.getRecompenseMethod()为空 try { result = RecompenseValidator.validateRecompenseReportCreate(app); fail("未抛出异常"); } catch (GeneralException e) { if (e.getErrorCode() .equals(RecompenseExceptionType.RECOMPENSE_REPORT_REQUIRE_ERROR.getErrorCode())) { assertTrue(true); } else { fail("抛出异常不正确"); } } app.setRecompenseMethod(Constants.FAST_TYPE); // 快速理賠測試 失败 try { result = RecompenseValidator.validateRecompenseReportCreate(app); fail("未抛出异常"); } catch (GeneralException e) { if (e.getErrorCode() .equals(RecompenseExceptionType.RECOMPENSE_REPORT_REQUIRE_ERROR.getErrorCode())) { assertTrue(true); } else { fail("抛出异常不正确"); } } app.setCompanyPhone("12344"); // 快速理賠測試 try { result = RecompenseValidator.validateRecompenseReportCreate(app); assertTrue(true); } catch (GeneralException e) { fail("正常数据抛出异常"); } // 列表都为空 app.setRecompenseMethod(Constants.NORMAL_TYPE); try { result = RecompenseValidator.validateRecompenseReportCreate(app); fail("未抛出异常"); } catch (GeneralException e) { if (e.getErrorCode() .equals(RecompenseExceptionType.RECOMPENSE_REPORT_REQUIRE_ERROR.getErrorCode())) { assertTrue(true); } else { fail("抛出异常不正确"); } } GoodsTrans goodsTrans = new GoodsTrans(); goodsTransAddList.add(goodsTrans); app.setGoodsTransList(goodsTransAddList); // 一个列表为空校验 try { result = RecompenseValidator.validateRecompenseReportCreate(app); fail("未抛出异常"); } catch (GeneralException e) { if (e.getErrorCode() .equals(RecompenseExceptionType.RECOMPENSE_REPORT_REQUIRE_ERROR.getErrorCode())) { assertTrue(true); } else { fail("抛出异常不正确"); } } app.setGoodsTransList(null); IssueItem issueItem = new IssueItem(); issueItemAddList.add(issueItem); app.setIssueItemList(issueItemAddList); // 一个列表不为空校验 try { result = RecompenseValidator.validateRecompenseReportCreate(app); assertTrue(true); } catch (GeneralException e) { if (e.getErrorCode() .equals(RecompenseExceptionType.RECOMPENSE_REPORT_REQUIRE_ERROR.getErrorCode())) { assertTrue(true); } else { fail("抛出异常不正确"); } } app.setGoodsTransList(goodsTransAddList); // 列表不为空校验 try { result = RecompenseValidator.validateRecompenseReportCreate(app); assertTrue(true); } catch (GeneralException e) { fail("正常数据抛出异常"); } }