From 76fd3a20b516dd77444c66acb5d2078f9a0567b7 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Wed, 19 Jul 2023 15:46:05 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E4=BF=AE=E5=A4=8D=E9=94=99=E8=AF=AF?= =?UTF-8?q?=E7=9A=84=E8=8E=B7=E5=8F=96=E5=88=86=E8=B4=A6=E6=8E=A5=E6=94=B6?= =?UTF-8?q?=E6=96=B9=E5=88=97=E8=A1=A8=E7=9A=84=E6=96=B9=E6=B3=95=E4=BB=A3?= =?UTF-8?q?=E7=A0=81=EF=BC=8C=E5=B9=B6=E5=A2=9E=E5=8A=A0=E5=8D=95=E5=85=83?= =?UTF-8?q?=E6=B5=8B=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../profitsharing/ProfitSharingResult.java | 25 ++++--- .../ProfitSharingResultTest.java | 71 +++++++++++++++++++ 2 files changed, 86 insertions(+), 10 deletions(-) create mode 100644 weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResultTest.java diff --git a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResult.java b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResult.java index 166a3348c..3b5107276 100644 --- a/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResult.java +++ b/weixin-java-pay/src/main/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResult.java @@ -1,16 +1,19 @@ package com.github.binarywang.wxpay.bean.profitsharing; import com.github.binarywang.wxpay.bean.result.BaseWxPayResult; +import com.google.gson.Gson; +import com.google.gson.GsonBuilder; import com.google.gson.annotations.SerializedName; +import com.google.gson.reflect.TypeToken; import com.thoughtworks.xstream.annotations.XStreamAlias; import lombok.Data; import lombok.EqualsAndHashCode; import lombok.NoArgsConstructor; +import org.apache.commons.lang3.StringUtils; import org.w3c.dom.Document; -import com.google.gson.Gson; -import com.google.gson.GsonBuilder; import java.io.Serializable; +import java.util.Collections; import java.util.List; /** @@ -65,17 +68,19 @@ public class ProfitSharingResult extends BaseWxPayResult implements Serializable /** * 获取分账接收方列表方法 * - * @return */ public List getReceiverList() { - if (receiverList == null && receivers != null && receivers.length() > 0) { - List tempList = GSON.fromJson(receivers, List.class); - for (String str : tempList) { - Receiver receiver = GSON.fromJson(str, Receiver.class); - receiverList.add(receiver); - } + if (receiverList != null) { + return receiverList; } - return receiverList; + + if (StringUtils.isNotEmpty(receivers)) { + this.receiverList = GSON.fromJson(receivers, new TypeToken>() { + }.getType()); + return receiverList; + } + + return Collections.emptyList(); } @Override diff --git a/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResultTest.java b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResultTest.java new file mode 100644 index 000000000..f9bf0e838 --- /dev/null +++ b/weixin-java-pay/src/test/java/com/github/binarywang/wxpay/bean/profitsharing/ProfitSharingResultTest.java @@ -0,0 +1,71 @@ +package com.github.binarywang.wxpay.bean.profitsharing; + +import org.testng.annotations.Test; + +import java.util.List; + +import static org.assertj.core.api.Assertions.assertThat; + +public class ProfitSharingResultTest { + + @Test + public void testGetReceiverList() { + ProfitSharingResult profitSharingResult = ProfitSharingResult.fromXML("\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "\t\n" + + "\t\t\n" + + "\t\n" + + "", ProfitSharingResult.class); + + List receiverList = profitSharingResult.getReceiverList(); + assertThat(receiverList).isNotEmpty(); + } +}