PointRecCalculator { public PointRecPo refundPoint(PointRecPo rec, BigDecimal delta, BigDecimal cost) { rec.setAvailable(rec.getAvailable().subtract(delta)) .setRefund(rec.getRefund().add(delta)) .setRefundCost(rec.getRefundCost().add(cost)); if (DecimalUtils.lte(rec.getAvailable(), DecimalUtils.ZERO) && DecimalUtils.lte(rec.getFrozen(), DecimalUtils.ZERO)) { rec.setEnable(false); } PointRecPo rec4Update = new PointRecPo(); rec4Update.setAvailable(rec.getAvailable()) .setRefund(rec.getRefund()) .setRefundCost(rec.getRefundCost()) .setEnable(rec.getEnable()) .setId(rec.getId()); return rec4Update; }  PointRecCalcResult freezePoint(PointRecPo rec, BigDecimal delta); PointRecCalcResult unfreezePoint(PointRecPo rec, BigDecimal delta, BigDecimal deltaCost); PointRecCalcResult decreasePoint(PointRecPo rec, BigDecimal delta); PointRecPo refundPoint(PointRecPo rec, BigDecimal delta, BigDecimal cost); PointRecCalcResult cancelPoint(PointRecPo rec, BigDecimal delta);  }
@Test public void test_refundPoint() { BigDecimal refund = BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2); BigDecimal cost = BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2); rec.setAvailable(BigDecimal.valueOf(150L).setScale(DecimalUtils.SCALE_2)) .setRefund(DecimalUtils.ZERO) .setRefundCost(DecimalUtils.ZERO) .setFrozen(DecimalUtils.ZERO); PointRecPo result = this.calculator.refundPoint(rec, refund, cost); log.info("result = {}", result); Assertions.assertEquals(rec.getId(), result.getId()); Assertions.assertEquals(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2), rec.getAvailable()); Assertions.assertEquals(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2), result.getAvailable()); Assertions.assertEquals(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2), rec.getRefund()); Assertions.assertEquals(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2), result.getRefund()); Assertions.assertEquals(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2), rec.getRefundCost()); Assertions.assertEquals(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2), result.getRefundCost()); Assertions.assertTrue(rec.getEnable()); Assertions.assertTrue(result.getEnable()); rec.setAvailable(BigDecimal.valueOf(100L)) .setRefund(DecimalUtils.ZERO) .setRefundCost(DecimalUtils.ZERO); result = this.calculator.refundPoint(rec, refund, cost); log.info("result = {}", result); Assertions.assertEquals(rec.getId(), result.getId()); Assertions.assertEquals(DecimalUtils.ZERO, rec.getAvailable()); Assertions.assertEquals(DecimalUtils.ZERO, result.getAvailable()); Assertions.assertEquals(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2), rec.getRefund()); Assertions.assertEquals(BigDecimal.valueOf(100L).setScale(DecimalUtils.SCALE_2), result.getRefund()); Assertions.assertEquals(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2), rec.getRefundCost()); Assertions.assertEquals(BigDecimal.valueOf(50L).setScale(DecimalUtils.SCALE_2), result.getRefundCost()); Assertions.assertFalse(rec.getEnable()); Assertions.assertFalse(result.getEnable()); }