|
|
@@ -1,6 +1,7 @@
|
|
|
package com.ruoyi.system.omgpay.service;
|
|
|
|
|
|
import com.ruoyi.common.exception.ServiceException;
|
|
|
+import com.ruoyi.common.utils.MessageUtils;
|
|
|
import com.ruoyi.system.omgpay.domain.OmgPaymentAttempt;
|
|
|
import com.ruoyi.system.omgpay.mapper.OmgPaymentAttemptMapper;
|
|
|
import com.ruoyi.system.omgpay.service.impl.OmgPaymentAttemptServiceImpl;
|
|
|
@@ -14,6 +15,7 @@ import static org.junit.jupiter.api.Assertions.assertEquals;
|
|
|
import static org.junit.jupiter.api.Assertions.assertNull;
|
|
|
import static org.junit.jupiter.api.Assertions.assertThrows;
|
|
|
import static org.mockito.ArgumentMatchers.any;
|
|
|
+import static org.mockito.Mockito.mockStatic;
|
|
|
import static org.mockito.Mockito.verifyNoInteractions;
|
|
|
import static org.mockito.Mockito.when;
|
|
|
|
|
|
@@ -27,10 +29,33 @@ class OmgPaymentAttemptServiceTest {
|
|
|
private OmgPaymentAttemptServiceImpl service;
|
|
|
|
|
|
@Test
|
|
|
- void createCreatedRejectsInvalidSnapshotsBeforeInsert() {
|
|
|
- assertThrows(ServiceException.class,
|
|
|
+ void createCreatedRejectsBlankDdIdUsingMessageUtils() {
|
|
|
+ assertLocalizedValidationFailure("omg.payment.ddid.required",
|
|
|
+ () -> service.createCreated(" ", "OMG123", 10L, "M1", 100));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createCreatedRejectsBlankMerchantTradeNoUsingMessageUtils() {
|
|
|
+ assertLocalizedValidationFailure("omg.payment.merchantTradeNo.required",
|
|
|
+ () -> service.createCreated("DD-1", " ", 10L, "M1", 100));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createCreatedRejectsNullStoreIdUsingMessageUtils() {
|
|
|
+ assertLocalizedValidationFailure("omg.payment.storeId.required",
|
|
|
+ () -> service.createCreated("DD-1", "OMG123", null, "M1", 100));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createCreatedRejectsBlankMerchantIdUsingMessageUtils() {
|
|
|
+ assertLocalizedValidationFailure("omg.payment.merchantId.required",
|
|
|
+ () -> service.createCreated("DD-1", "OMG123", 10L, " ", 100));
|
|
|
+ }
|
|
|
+
|
|
|
+ @Test
|
|
|
+ void createCreatedRejectsNonPositiveAmountUsingMessageUtils() {
|
|
|
+ assertLocalizedValidationFailure("omg.payment.amount.invalid",
|
|
|
() -> service.createCreated("DD-1", "OMG123", 10L, "M1", 0));
|
|
|
- verifyNoInteractions(mapper);
|
|
|
}
|
|
|
|
|
|
@Test
|
|
|
@@ -47,4 +72,20 @@ class OmgPaymentAttemptServiceTest {
|
|
|
assertEquals(7L, row.getId());
|
|
|
assertNull(row.getActiveDdId());
|
|
|
}
|
|
|
+
|
|
|
+ private void assertLocalizedValidationFailure(String key, ThrowingRunnable runnable) {
|
|
|
+ try (var messages = mockStatic(MessageUtils.class)) {
|
|
|
+ messages.when(() -> MessageUtils.message(key)).thenReturn("localized-" + key);
|
|
|
+
|
|
|
+ ServiceException exception = assertThrows(ServiceException.class, runnable::run);
|
|
|
+
|
|
|
+ assertEquals("localized-" + key, exception.getMessage());
|
|
|
+ verifyNoInteractions(mapper);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @FunctionalInterface
|
|
|
+ private interface ThrowingRunnable {
|
|
|
+ void run();
|
|
|
+ }
|
|
|
}
|