Skip to content

Commit ddbeda4

Browse files
committed
🎨 重构补充部分单元测试代码
1 parent 9341419 commit ddbeda4

File tree

3 files changed

+64
-48
lines changed

3 files changed

+64
-48
lines changed

weixin-java-common/src/main/java/me/chanjar/weixin/common/bean/WxNetCheckResult.java

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,6 @@
1313
*/
1414
@Data
1515
public class WxNetCheckResult implements Serializable {
16-
1716
private static final long serialVersionUID = 6918924418847404172L;
1817

1918
private List<WxNetCheckDnsInfo> dnsInfos = new ArrayList<>();
Lines changed: 58 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,58 @@
1+
package me.chanjar.weixin.common.bean;
2+
3+
import org.testng.Assert;
4+
import org.testng.annotations.Test;
5+
6+
/**
7+
*
8+
* @author <a href="https://github.com/binarywang">Binary Wang</a>
9+
* @date 2020-06-06
10+
*/
11+
public class WxNetCheckResultTest {
12+
13+
@Test
14+
public void testFromJson() {
15+
String json = "{\n" +
16+
" \"dns\": [\n" +
17+
" {\n" +
18+
" \"ip\": \"111.161.64.40\", \n" +
19+
" \"real_operator\": \"UNICOM\"\n" +
20+
" }, \n" +
21+
" {\n" +
22+
" \"ip\": \"111.161.64.48\", \n" +
23+
" \"real_operator\": \"UNICOM\"\n" +
24+
" }\n" +
25+
" ], \n" +
26+
" \"ping\": [\n" +
27+
" {\n" +
28+
" \"ip\": \"111.161.64.40\", \n" +
29+
" \"from_operator\": \"UNICOM\"," +
30+
" \"package_loss\": \"0%\", \n" +
31+
" \"time\": \"23.079ms\"\n" +
32+
" }, \n" +
33+
" {\n" +
34+
" \"ip\": \"111.161.64.48\", \n" +
35+
" \"from_operator\": \"UNICOM\", \n" +
36+
" \"package_loss\": \"0%\", \n" +
37+
" \"time\": \"21.434ms\"\n" +
38+
" }\n" +
39+
" ]\n" +
40+
"}";
41+
WxNetCheckResult result = WxNetCheckResult.fromJson(json);
42+
Assert.assertNotNull(result);
43+
Assert.assertNotNull(result.getDnsInfos());
44+
45+
WxNetCheckResult.WxNetCheckDnsInfo dnsInfo = new WxNetCheckResult.WxNetCheckDnsInfo();
46+
dnsInfo.setIp("111.161.64.40");
47+
dnsInfo.setRealOperator("UNICOM");
48+
Assert.assertEquals(result.getDnsInfos().get(0), dnsInfo);
49+
50+
WxNetCheckResult.WxNetCheckPingInfo pingInfo = new WxNetCheckResult.WxNetCheckPingInfo();
51+
pingInfo.setTime("21.434ms");
52+
pingInfo.setFromOperator("UNICOM");
53+
pingInfo.setIp("111.161.64.48");
54+
pingInfo.setPackageLoss("0%");
55+
Assert.assertEquals(result.getPingInfos().get(1), pingInfo);
56+
57+
}
58+
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/BaseWxMpServiceImplTest.java

Lines changed: 6 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
import java.util.concurrent.Executors;
88
import java.util.concurrent.TimeUnit;
99
import me.chanjar.weixin.common.api.WxConsts;
10+
import me.chanjar.weixin.common.bean.WxJsapiSignature;
1011
import me.chanjar.weixin.common.bean.WxNetCheckResult;
1112
import me.chanjar.weixin.common.error.WxErrorException;
1213
import me.chanjar.weixin.mp.api.WxMpService;
@@ -57,52 +58,6 @@ public void testNetCheck() throws WxErrorException {
5758

5859
}
5960

60-
@Test
61-
public void testNectCheckResult() {
62-
String json = "{\n" +
63-
" \"dns\": [\n" +
64-
" {\n" +
65-
" \"ip\": \"111.161.64.40\", \n" +
66-
" \"real_operator\": \"UNICOM\"\n" +
67-
" }, \n" +
68-
" {\n" +
69-
" \"ip\": \"111.161.64.48\", \n" +
70-
" \"real_operator\": \"UNICOM\"\n" +
71-
" }\n" +
72-
" ], \n" +
73-
" \"ping\": [\n" +
74-
" {\n" +
75-
" \"ip\": \"111.161.64.40\", \n" +
76-
" \"from_operator\": \"UNICOM\"," +
77-
" \"package_loss\": \"0%\", \n" +
78-
" \"time\": \"23.079ms\"\n" +
79-
" }, \n" +
80-
" {\n" +
81-
" \"ip\": \"111.161.64.48\", \n" +
82-
" \"from_operator\": \"UNICOM\", \n" +
83-
" \"package_loss\": \"0%\", \n" +
84-
" \"time\": \"21.434ms\"\n" +
85-
" }\n" +
86-
" ]\n" +
87-
"}";
88-
WxNetCheckResult result = WxNetCheckResult.fromJson(json);
89-
Assert.assertNotNull(result);
90-
Assert.assertNotNull(result.getDnsInfos());
91-
92-
WxNetCheckResult.WxNetCheckDnsInfo dnsInfo = new WxNetCheckResult.WxNetCheckDnsInfo();
93-
dnsInfo.setIp("111.161.64.40");
94-
dnsInfo.setRealOperator("UNICOM");
95-
Assert.assertEquals(result.getDnsInfos().get(0), dnsInfo);
96-
97-
WxNetCheckResult.WxNetCheckPingInfo pingInfo = new WxNetCheckResult.WxNetCheckPingInfo();
98-
pingInfo.setTime("21.434ms");
99-
pingInfo.setFromOperator("UNICOM");
100-
pingInfo.setIp("111.161.64.48");
101-
pingInfo.setPackageLoss("0%");
102-
Assert.assertEquals(result.getPingInfos().get(1), pingInfo);
103-
104-
}
105-
10661
@Test
10762
public void testGetCallbackIP() throws WxErrorException {
10863
String[] ipArray = this.wxService.getCallbackIP();
@@ -174,7 +129,11 @@ public void testTestGetJsapiTicket() {
174129
}
175130

176131
@Test
177-
public void testCreateJsapiSignature() {
132+
public void testCreateJsapiSignature() throws WxErrorException {
133+
final WxJsapiSignature jsapiSignature = this.wxService.createJsapiSignature("http://www.baidu.com");
134+
assertThat(jsapiSignature).isNotNull();
135+
assertThat(jsapiSignature.getSignature()).isNotNull();
136+
System.out.println(jsapiSignature);
178137
}
179138

180139
@Test

0 commit comments

Comments
 (0)