| 1 | package com.rbctcsworld.ecommerce.returns; | |
| 2 | ||
| 3 | import com.rbctcsworld.ecommerce.order.CustomerOrder; | |
| 4 | ||
| 5 | import java.math.BigDecimal; | |
| 6 | import java.util.Set; | |
| 7 | ||
| 8 | /** | |
| 9 | * Decision table for approved returns: | |
| 10 | * | |
| 11 | * | Reason | Refund | Put back in stock | | |
| 12 | * |-------------------|------------------------|-------------------| | |
| 13 | * | DAMAGED | full total | NO (written off) | | |
| 14 | * | WRONG_ITEM | full total | yes | | |
| 15 | * | NOT_AS_DESCRIBED | full total | yes | | |
| 16 | * | NO_LONGER_NEEDED | total - shipping fee | yes | | |
| 17 | */ | |
| 18 | public final class ReturnPolicy { | |
| 19 | ||
| 20 | public static final String DAMAGED = "DAMAGED"; | |
| 21 | public static final String WRONG_ITEM = "WRONG_ITEM"; | |
| 22 | public static final String NOT_AS_DESCRIBED = "NOT_AS_DESCRIBED"; | |
| 23 | public static final String NO_LONGER_NEEDED = "NO_LONGER_NEEDED"; | |
| 24 | public static final Set<String> REASONS = Set.of(DAMAGED, WRONG_ITEM, NOT_AS_DESCRIBED, NO_LONGER_NEEDED); | |
| 25 | ||
| 26 | private ReturnPolicy() { | |
| 27 | } | |
| 28 | ||
| 29 | public static BigDecimal refundAmount(String reason, CustomerOrder order) { | |
| 30 |
2
1. refundAmount : replaced return value with null for com/rbctcsworld/ecommerce/returns/ReturnPolicy::refundAmount → KILLED 2. refundAmount : removed conditional - replaced equality check with false → KILLED |
return NO_LONGER_NEEDED.equals(reason) |
| 31 | ? order.getTotal().subtract(order.getShippingFee()) | |
| 32 | : order.getTotal(); | |
| 33 | } | |
| 34 | ||
| 35 | public static boolean restock(String reason) { | |
| 36 |
2
1. restock : replaced boolean return with true for com/rbctcsworld/ecommerce/returns/ReturnPolicy::restock → KILLED 2. restock : removed conditional - replaced equality check with false → KILLED |
return !DAMAGED.equals(reason); |
| 37 | } | |
| 38 | } | |
Mutations | ||
| 30 |
1.1 2.2 |
|
| 36 |
1.1 2.2 |