Commit 1baa7f4aee6ab958961fa804d9adeb10c171045e
1 parent
35c1ba44
优化 AlipayPcPayClientTest 的方法命名,补全 assert 断言
Showing
1 changed file
with
38 additions
and
19 deletions
yudao-framework/yudao-spring-boot-starter-biz-pay/src/test/java/cn/iocoder/yudao/framework/pay/core/client/impl/alipay/AlipayPcPayClientTest.java
| @@ -16,8 +16,8 @@ import org.mockito.InjectMocks; | @@ -16,8 +16,8 @@ import org.mockito.InjectMocks; | ||
| 16 | import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.CLOSED; | 16 | import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.CLOSED; |
| 17 | import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.WAITING; | 17 | import static cn.iocoder.yudao.framework.pay.core.enums.order.PayOrderStatusRespEnum.WAITING; |
| 18 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; | 18 | import static cn.iocoder.yudao.framework.test.core.util.RandomUtils.*; |
| 19 | -import static org.junit.jupiter.api.Assertions.assertEquals; | ||
| 20 | -import static org.junit.jupiter.api.Assertions.assertSame; | 19 | +import static org.junit.jupiter.api.Assertions.*; |
| 20 | +import static org.junit.jupiter.api.Assertions.assertNull; | ||
| 21 | import static org.mockito.ArgumentMatchers.argThat; | 21 | import static org.mockito.ArgumentMatchers.argThat; |
| 22 | import static org.mockito.ArgumentMatchers.eq; | 22 | import static org.mockito.ArgumentMatchers.eq; |
| 23 | import static org.mockito.Mockito.when; | 23 | import static org.mockito.Mockito.when; |
| @@ -39,36 +39,40 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { | @@ -39,36 +39,40 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { | ||
| 39 | } | 39 | } |
| 40 | 40 | ||
| 41 | @Test | 41 | @Test |
| 42 | - @DisplayName("支付宝 PC 网站支付 URL Display Mode 下单成功") | ||
| 43 | - public void test_unified_order_url_display_mode_success() throws AlipayApiException { | ||
| 44 | - // 准备返回对象 | 42 | + @DisplayName("支付宝 PC 网站支付:URL Display Mode 下单成功") |
| 43 | + public void testUnifiedOrder_urlSuccess() throws AlipayApiException { | ||
| 44 | + // mock 方法 | ||
| 45 | String notifyUrl = randomURL(); | 45 | String notifyUrl = randomURL(); |
| 46 | AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); | 46 | AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); |
| 47 | - // mock | ||
| 48 | when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher<AlipayTradePagePayRequest>) request -> true), | 47 | when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher<AlipayTradePagePayRequest>) request -> true), |
| 49 | eq(Method.GET.name()))).thenReturn(response); | 48 | eq(Method.GET.name()))).thenReturn(response); |
| 50 | // 准备请求参数 | 49 | // 准备请求参数 |
| 51 | String outTradeNo = randomString(); | 50 | String outTradeNo = randomString(); |
| 52 | Integer price = randomInteger(); | 51 | Integer price = randomInteger(); |
| 53 | PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); | 52 | PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); |
| 54 | - // 设置 displayMode 为 null. | ||
| 55 | reqDTO.setDisplayMode(null); | 53 | reqDTO.setDisplayMode(null); |
| 56 | 54 | ||
| 55 | + // 调用 | ||
| 57 | PayOrderRespDTO resp = client.unifiedOrder(reqDTO); | 56 | PayOrderRespDTO resp = client.unifiedOrder(reqDTO); |
| 58 | // 断言 | 57 | // 断言 |
| 59 | assertEquals(WAITING.getStatus(), resp.getStatus()); | 58 | assertEquals(WAITING.getStatus(), resp.getStatus()); |
| 60 | - assertEquals(PayOrderDisplayModeEnum.URL.getMode(), resp.getDisplayMode()); | ||
| 61 | assertEquals(outTradeNo, resp.getOutTradeNo()); | 59 | assertEquals(outTradeNo, resp.getOutTradeNo()); |
| 60 | + assertNull(resp.getChannelOrderNo()); | ||
| 61 | + assertNull(resp.getChannelUserId()); | ||
| 62 | + assertNull(resp.getSuccessTime()); | ||
| 63 | + assertEquals(PayOrderDisplayModeEnum.URL.getMode(), resp.getDisplayMode()); | ||
| 64 | + assertEquals(response.getBody(), resp.getDisplayContent()); | ||
| 62 | assertSame(response, resp.getRawData()); | 65 | assertSame(response, resp.getRawData()); |
| 66 | + assertNull(resp.getChannelErrorCode()); | ||
| 67 | + assertNull(resp.getChannelErrorMsg()); | ||
| 63 | } | 68 | } |
| 64 | 69 | ||
| 65 | @Test | 70 | @Test |
| 66 | - @DisplayName("支付宝 PC 网站支付 FORM Display Mode 下单成功") | ||
| 67 | - public void test_unified_order_form_display_mode_success() throws AlipayApiException { | ||
| 68 | - // 准备返回对象 | 71 | + @DisplayName("支付宝 PC 网站支付:Form Display Mode 下单成功") |
| 72 | + public void testUnifiedOrder_formSuccess() throws AlipayApiException { | ||
| 73 | + // mock | ||
| 69 | String notifyUrl = randomURL(); | 74 | String notifyUrl = randomURL(); |
| 70 | AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); | 75 | AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> o.setSubCode("")); |
| 71 | - // mock | ||
| 72 | when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher<AlipayTradePagePayRequest>) request -> true), | 76 | when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher<AlipayTradePagePayRequest>) request -> true), |
| 73 | eq(Method.POST.name()))).thenReturn(response); | 77 | eq(Method.POST.name()))).thenReturn(response); |
| 74 | // 准备请求参数 | 78 | // 准备请求参数 |
| @@ -77,36 +81,51 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { | @@ -77,36 +81,51 @@ public class AlipayPcPayClientTest extends AbstractAlipayClientTest { | ||
| 77 | PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); | 81 | PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(notifyUrl, outTradeNo, price); |
| 78 | reqDTO.setDisplayMode(PayOrderDisplayModeEnum.FORM.getMode()); | 82 | reqDTO.setDisplayMode(PayOrderDisplayModeEnum.FORM.getMode()); |
| 79 | 83 | ||
| 84 | + // 调用 | ||
| 80 | PayOrderRespDTO resp = client.unifiedOrder(reqDTO); | 85 | PayOrderRespDTO resp = client.unifiedOrder(reqDTO); |
| 81 | // 断言 | 86 | // 断言 |
| 82 | assertEquals(WAITING.getStatus(), resp.getStatus()); | 87 | assertEquals(WAITING.getStatus(), resp.getStatus()); |
| 83 | - assertEquals(PayOrderDisplayModeEnum.FORM.getMode(), resp.getDisplayMode()); | ||
| 84 | assertEquals(outTradeNo, resp.getOutTradeNo()); | 88 | assertEquals(outTradeNo, resp.getOutTradeNo()); |
| 89 | + assertNull(resp.getChannelOrderNo()); | ||
| 90 | + assertNull(resp.getChannelUserId()); | ||
| 91 | + assertNull(resp.getSuccessTime()); | ||
| 92 | + assertEquals(PayOrderDisplayModeEnum.FORM.getMode(), resp.getDisplayMode()); | ||
| 93 | + assertEquals(response.getBody(), resp.getDisplayContent()); | ||
| 85 | assertSame(response, resp.getRawData()); | 94 | assertSame(response, resp.getRawData()); |
| 95 | + assertNull(resp.getChannelErrorCode()); | ||
| 96 | + assertNull(resp.getChannelErrorMsg()); | ||
| 86 | } | 97 | } |
| 87 | 98 | ||
| 88 | @Test | 99 | @Test |
| 89 | - @DisplayName("支付宝 PC 网站支付,渠道返回失败") | ||
| 90 | - public void test_unified_order_channel_failed() throws AlipayApiException { | ||
| 91 | - // 准备响应对象 | 100 | + @DisplayName("支付宝 PC 网站支付:渠道返回失败") |
| 101 | + public void testUnifiedOrder_channelFailed() throws AlipayApiException { | ||
| 102 | + // mock | ||
| 92 | String subCode = randomString(); | 103 | String subCode = randomString(); |
| 93 | String subMsg = randomString(); | 104 | String subMsg = randomString(); |
| 94 | AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> { | 105 | AlipayTradePagePayResponse response = randomPojo(AlipayTradePagePayResponse.class, o -> { |
| 95 | o.setSubCode(subCode); | 106 | o.setSubCode(subCode); |
| 96 | o.setSubMsg(subMsg); | 107 | o.setSubMsg(subMsg); |
| 97 | }); | 108 | }); |
| 98 | - // mock | ||
| 99 | when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher<AlipayTradePagePayRequest>) request -> true), | 109 | when(defaultAlipayClient.pageExecute(argThat((ArgumentMatcher<AlipayTradePagePayRequest>) request -> true), |
| 100 | eq(Method.GET.name()))).thenReturn(response); | 110 | eq(Method.GET.name()))).thenReturn(response); |
| 101 | // 准备请求参数 | 111 | // 准备请求参数 |
| 102 | - PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), randomString(), randomInteger()); | 112 | + String outTradeNo = randomString(); |
| 113 | + PayOrderUnifiedReqDTO reqDTO = buildOrderUnifiedReqDTO(randomURL(), outTradeNo, randomInteger()); | ||
| 103 | reqDTO.setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()); | 114 | reqDTO.setDisplayMode(PayOrderDisplayModeEnum.URL.getMode()); |
| 104 | 115 | ||
| 116 | + // 调用 | ||
| 105 | PayOrderRespDTO resp = client.unifiedOrder(reqDTO); | 117 | PayOrderRespDTO resp = client.unifiedOrder(reqDTO); |
| 106 | // 断言 | 118 | // 断言 |
| 107 | assertEquals(CLOSED.getStatus(), resp.getStatus()); | 119 | assertEquals(CLOSED.getStatus(), resp.getStatus()); |
| 120 | + assertEquals(outTradeNo, resp.getOutTradeNo()); | ||
| 121 | + assertNull(resp.getChannelOrderNo()); | ||
| 122 | + assertNull(resp.getChannelUserId()); | ||
| 123 | + assertNull(resp.getSuccessTime()); | ||
| 124 | + assertNull(resp.getDisplayMode()); | ||
| 125 | + assertNull(resp.getDisplayContent()); | ||
| 126 | + assertSame(response, resp.getRawData()); | ||
| 108 | assertEquals(subCode, resp.getChannelErrorCode()); | 127 | assertEquals(subCode, resp.getChannelErrorCode()); |
| 109 | assertEquals(subMsg, resp.getChannelErrorMsg()); | 128 | assertEquals(subMsg, resp.getChannelErrorMsg()); |
| 110 | - assertSame(response, resp.getRawData()); | ||
| 111 | } | 129 | } |
| 130 | + | ||
| 112 | } | 131 | } |