|
| 1 | +package com.github.binarywang.wxpay.bean.request; |
| 2 | + |
| 3 | +import com.google.gson.Gson; |
| 4 | +import com.google.gson.JsonObject; |
| 5 | +import org.testng.annotations.Test; |
| 6 | + |
| 7 | +import static org.assertj.core.api.Assertions.assertThat; |
| 8 | + |
| 9 | +/** |
| 10 | + * {@link WxPayPartnerRefundV3Request} 单元测试 |
| 11 | + * |
| 12 | + */ |
| 13 | +public class WxPayPartnerRefundV3RequestTest { |
| 14 | + |
| 15 | + @Test |
| 16 | + public void testSpAppidAndSubAppidSerialization() { |
| 17 | + WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request(); |
| 18 | + request.setSpAppid("wx8888888888888888"); |
| 19 | + request.setSubAppid("wxd678efh567hg6999"); |
| 20 | + request.setSubMchid("1230000109"); |
| 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("sp_appid")).isTrue(); |
| 29 | + assertThat(jsonObject.get("sp_appid").getAsString()).isEqualTo("wx8888888888888888"); |
| 30 | + assertThat(jsonObject.has("sub_appid")).isTrue(); |
| 31 | + assertThat(jsonObject.get("sub_appid").getAsString()).isEqualTo("wxd678efh567hg6999"); |
| 32 | + assertThat(jsonObject.has("sub_mchid")).isTrue(); |
| 33 | + assertThat(jsonObject.get("sub_mchid").getAsString()).isEqualTo("1230000109"); |
| 34 | + assertThat(jsonObject.has("out_refund_no")).isTrue(); |
| 35 | + assertThat(jsonObject.get("out_refund_no").getAsString()).isEqualTo("1217752501201407033233368018"); |
| 36 | + assertThat(jsonObject.has("funds_account")).isTrue(); |
| 37 | + assertThat(jsonObject.get("funds_account").getAsString()).isEqualTo("AVAILABLE"); |
| 38 | + } |
| 39 | + |
| 40 | + @Test |
| 41 | + public void testSubAppidIsOptional() { |
| 42 | + WxPayPartnerRefundV3Request request = new WxPayPartnerRefundV3Request(); |
| 43 | + request.setSpAppid("wx8888888888888888"); |
| 44 | + request.setSubMchid("1230000109"); |
| 45 | + request.setOutRefundNo("1217752501201407033233368018"); |
| 46 | + |
| 47 | + Gson gson = new Gson(); |
| 48 | + String json = gson.toJson(request); |
| 49 | + JsonObject jsonObject = gson.fromJson(json, JsonObject.class); |
| 50 | + |
| 51 | + assertThat(jsonObject.has("sp_appid")).isTrue(); |
| 52 | + assertThat(jsonObject.get("sp_appid").getAsString()).isEqualTo("wx8888888888888888"); |
| 53 | + assertThat(jsonObject.has("sub_appid")).isFalse(); |
| 54 | + } |
| 55 | +} |
0 commit comments