Skip to content

Commit d81dcc2

Browse files
committed
Add refund request funds account coverage
1 parent 79307f7 commit d81dcc2

1 file changed

Lines changed: 56 additions & 0 deletions

File tree

Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
1+
package com.github.binarywang.wxpay.bean.request;
2+
3+
import com.google.gson.Gson;
4+
import com.google.gson.JsonArray;
5+
import com.google.gson.JsonObject;
6+
import org.testng.annotations.Test;
7+
8+
import java.util.Collections;
9+
10+
import static org.assertj.core.api.Assertions.assertThat;
11+
12+
/**
13+
* {@link WxPayRefundV3Request} 单元测试
14+
*
15+
*/
16+
public class WxPayRefundV3RequestTest {
17+
18+
@Test
19+
public void testFundsAccountSerialization() {
20+
WxPayRefundV3Request request = new WxPayRefundV3Request();
21+
request.setOutRefundNo("1217752501201407033233368018");
22+
request.setFundsAccount("AVAILABLE");
23+
24+
Gson gson = new Gson();
25+
String json = gson.toJson(request);
26+
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
27+
28+
assertThat(jsonObject.has("funds_account")).isTrue();
29+
assertThat(jsonObject.get("funds_account").getAsString()).isEqualTo("AVAILABLE");
30+
}
31+
32+
@Test
33+
public void testAmountFromSerialization() {
34+
WxPayRefundV3Request.From from = new WxPayRefundV3Request.From();
35+
from.setAccount("AVAILABLE");
36+
from.setAmount(444);
37+
38+
WxPayRefundV3Request.Amount amount = new WxPayRefundV3Request.Amount();
39+
amount.setRefund(888);
40+
amount.setTotal(888);
41+
amount.setCurrency("CNY");
42+
amount.setFrom(Collections.singletonList(from));
43+
44+
WxPayRefundV3Request request = new WxPayRefundV3Request();
45+
request.setAmount(amount);
46+
47+
Gson gson = new Gson();
48+
String json = gson.toJson(request);
49+
JsonObject jsonObject = gson.fromJson(json, JsonObject.class);
50+
JsonArray fromJson = jsonObject.getAsJsonObject("amount").getAsJsonArray("from");
51+
52+
assertThat(fromJson).hasSize(1);
53+
assertThat(fromJson.get(0).getAsJsonObject().get("account").getAsString()).isEqualTo("AVAILABLE");
54+
assertThat(fromJson.get(0).getAsJsonObject().get("amount").getAsInt()).isEqualTo(444);
55+
}
56+
}

0 commit comments

Comments
 (0)