优化
This commit is contained in:
@@ -22,7 +22,7 @@ class FinanceWalletBehaviorTest {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
when(jdbc.query(startsWith("SELECT currency_code"), any(RowMapper.class), eq(9L))).thenReturn(List.of());
|
||||
|
||||
var account = service(jdbc, "https://pay.example/wechat.png", "").account(9L);
|
||||
var account = service(jdbc, "https://pay.example/qr.png").account(9L);
|
||||
|
||||
assertThat(account.actualBalance()).isEqualByComparingTo("0.00");
|
||||
assertThat(account.frozenBalance()).isEqualByComparingTo("0.00");
|
||||
@@ -34,28 +34,25 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void rechargeChannelsAreEnabledOnlyWhenQrCodeIsConfigured() {
|
||||
var channels = service(mock(JdbcTemplate.class), "https://pay.example/wechat.png", "").channels();
|
||||
var channel = service(mock(JdbcTemplate.class), "https://pay.example/qr.png").channel();
|
||||
|
||||
assertThat(channels).satisfiesExactly(
|
||||
wechat -> { assertThat(wechat.paymentMethod()).isEqualTo("WECHAT"); assertThat(wechat.enabled()).isTrue(); },
|
||||
alipay -> { assertThat(alipay.paymentMethod()).isEqualTo("ALIPAY"); assertThat(alipay.enabled()).isFalse(); });
|
||||
assertThat(channel.enabled()).isTrue();
|
||||
assertThat(channel.qrCodeUrl()).isEqualTo("https://pay.example/qr.png");
|
||||
}
|
||||
|
||||
@Test
|
||||
void developmentProfileUsesTheNonPayableSampleQrCode() {
|
||||
var channels = new FinanceWalletService(mock(JdbcTemplate.class), new ObjectMapper().findAndRegisterModules(),
|
||||
mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", "", "",
|
||||
"cn", "development").channels();
|
||||
mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", "",
|
||||
"cn", "development").channel();
|
||||
|
||||
assertThat(channels).allSatisfy(channel -> {
|
||||
assertThat(channel.enabled()).isTrue();
|
||||
assertThat(channel.qrCodeUrl()).isEqualTo("/customer-recharge-qr.svg");
|
||||
});
|
||||
assertThat(channels.enabled()).isTrue();
|
||||
assertThat(channels.qrCodeUrl()).isEqualTo("/customer-recharge-qr.svg");
|
||||
}
|
||||
|
||||
@Test
|
||||
void deductionMayMakeActualBalanceNegative() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
WalletAccount initial = service.accountState(new BigDecimal("10.00"), BigDecimal.ZERO,
|
||||
BigDecimal.ZERO, BigDecimal.ZERO, null, 2);
|
||||
|
||||
@@ -71,7 +68,7 @@ class FinanceWalletBehaviorTest {
|
||||
JdbcTemplate jdbc = mock(JdbcTemplate.class);
|
||||
when(jdbc.query(startsWith("SELECT currency_code"), any(RowMapper.class), eq(9L))).thenReturn(List.of());
|
||||
|
||||
var account = service(jdbc, "x", "y").account(9L);
|
||||
var account = service(jdbc, "x").account(9L);
|
||||
|
||||
assertThat(account.creditLimit()).isZero();
|
||||
assertThat(account.availableCredit()).isZero();
|
||||
@@ -82,7 +79,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void deductionUsesCashBeforeCreditAndRechargeRepaysCreditFirst() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
WalletAccount initial = service.accountState(new BigDecimal("100.00"), BigDecimal.ZERO,
|
||||
new BigDecimal("50.00"), BigDecimal.ZERO, LocalDate.now().plusDays(7), 3);
|
||||
|
||||
@@ -100,7 +97,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void deductionNeverConsumesCashReservedByAnActiveHold() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
WalletAccount initial = service.accountState(new BigDecimal("100.00"), new BigDecimal("50.00"),
|
||||
new BigDecimal("80.00"), new BigDecimal("20.00"), LocalDate.now().plusDays(7), 4);
|
||||
|
||||
@@ -116,7 +113,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void rechargeRepaysUsedCreditWithoutReleasingFrozenCredit() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
WalletAccount initial = service.accountState(new BigDecimal("5.00"), new BigDecimal("25.00"),
|
||||
new BigDecimal("100.00"), new BigDecimal("40.00"), new BigDecimal("20.00"),
|
||||
LocalDate.now().plusDays(7), 5);
|
||||
@@ -133,7 +130,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void accountStateRejectsCreditUsedAndFrozenAboveTheLimit() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
|
||||
assertThatThrownBy(() -> service.accountState(BigDecimal.ZERO, new BigDecimal("20.00"),
|
||||
new BigDecimal("50.00"), new BigDecimal("31.00"), new BigDecimal("20.00"),
|
||||
@@ -144,7 +141,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void accountStateAllowsBalanceToBecomeNegativeWhileFundsRemainFrozen() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
|
||||
WalletAccount account = service.accountState(new BigDecimal("9.99"), new BigDecimal("10.00"),
|
||||
new BigDecimal("20.00"), BigDecimal.ZERO, LocalDate.now().plusDays(7), 1);
|
||||
@@ -155,7 +152,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void accountStateRejectsCreditFrozenAboveTotalFrozenAmount() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
|
||||
assertThatThrownBy(() -> service.accountState(new BigDecimal("100.00"), new BigDecimal("10.00"),
|
||||
new BigDecimal("50.00"), new BigDecimal("10.01"), LocalDate.now().plusDays(7), 1))
|
||||
@@ -165,7 +162,7 @@ class FinanceWalletBehaviorTest {
|
||||
|
||||
@Test
|
||||
void expiredCreditNoLongerContributesToAvailableBalance() {
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x", "y");
|
||||
FinanceWalletService service = service(mock(JdbcTemplate.class), "x");
|
||||
|
||||
WalletAccount account = service.accountState(BigDecimal.ZERO, BigDecimal.ZERO,
|
||||
new BigDecimal("50.00"), new BigDecimal("20.00"), BigDecimal.ZERO,
|
||||
@@ -176,9 +173,9 @@ class FinanceWalletBehaviorTest {
|
||||
assertThat(account.availableBalance()).isEqualByComparingTo("-20.00");
|
||||
}
|
||||
|
||||
private static FinanceWalletService service(JdbcTemplate jdbc, String wechat, String alipay) {
|
||||
private static FinanceWalletService service(JdbcTemplate jdbc, String qrCodeUrl) {
|
||||
return new FinanceWalletService(jdbc, new ObjectMapper().findAndRegisterModules(),
|
||||
mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", wechat, alipay,
|
||||
mock(FinanceFileClient.class), mock(FinanceDocumentNumberGenerator.class), "token", qrCodeUrl,
|
||||
"test", "test");
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user