Skip to content

Commit 66cd7cd

Browse files
committed
fix some warnings in test files
1 parent 585b721 commit 66cd7cd

16 files changed

+253
-170
lines changed

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpCustomMessageAPITest.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ public class WxMpCustomMessageAPITest {
2121
protected WxMpServiceImpl wxService;
2222

2323
public void testSendCustomMessage() throws WxErrorException {
24-
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
24+
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage();
2525
WxMpCustomMessage message = new WxMpCustomMessage();
2626
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
2727
message.setToUser(configStorage.getOpenId());
@@ -31,7 +31,7 @@ public void testSendCustomMessage() throws WxErrorException {
3131
}
3232

3333
public void testSendCustomMessageWithKfAccount() throws WxErrorException {
34-
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
34+
ApiTestModule.WxXmlMpInMemoryConfigStorage configStorage = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService.getWxMpConfigStorage();
3535
WxMpCustomMessage message = new WxMpCustomMessage();
3636
message.setMsgType(WxConsts.CUSTOM_MSG_TEXT);
3737
message.setToUser(configStorage.getOpenId());

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpJsAPITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -24,7 +24,7 @@ public class WxMpJsAPITest {
2424

2525

2626
public void testJsapiTicket() throws WxErrorException {
27-
String jsapiTicket = wxService.getJsapiTicket(false);
27+
String jsapiTicket = this.wxService.getJsapiTicket(false);
2828
System.out.println(jsapiTicket);
2929
Assert.assertNotNull(jsapiTicket);
3030
}

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMassMessageAPITest.java

Lines changed: 53 additions & 31 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,15 @@
11
package me.chanjar.weixin.mp.api;
22

3+
import java.io.IOException;
4+
import java.io.InputStream;
5+
6+
import org.testng.Assert;
7+
import org.testng.annotations.DataProvider;
8+
import org.testng.annotations.Guice;
9+
import org.testng.annotations.Test;
10+
311
import com.google.inject.Inject;
12+
413
import me.chanjar.weixin.common.api.WxConsts;
514
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
615
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -11,13 +20,6 @@
1120
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
1221
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
1322
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
14-
import org.testng.Assert;
15-
import org.testng.annotations.DataProvider;
16-
import org.testng.annotations.Guice;
17-
import org.testng.annotations.Test;
18-
19-
import java.io.IOException;
20-
import java.io.InputStream;
2123

2224
/**
2325
* 测试群发消息
@@ -34,27 +36,32 @@ public class WxMpMassMessageAPITest {
3436
@Test
3537
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
3638
// 发送群发消息
37-
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
39+
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
40+
.getWxMpConfigStorage();
3841
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
3942
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
4043
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
4144
massMessage.getToUsers().add(configProvider.getOpenId());
4245

43-
WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
46+
WxMpMassSendResult massResult = this.wxService
47+
.massOpenIdsMessageSend(massMessage);
4448
Assert.assertNotNull(massResult);
4549
Assert.assertNotNull(massResult.getMsgId());
4650
}
4751

4852
@Test(dataProvider="massMessages")
49-
public void testMediaMassOpenIdsMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
53+
public void testMediaMassOpenIdsMessageSend(String massMsgType,
54+
String mediaId) throws WxErrorException {
5055
// 发送群发消息
51-
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) wxService.getWxMpConfigStorage();
56+
ApiTestModule.WxXmlMpInMemoryConfigStorage configProvider = (ApiTestModule.WxXmlMpInMemoryConfigStorage) this.wxService
57+
.getWxMpConfigStorage();
5258
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
5359
massMessage.setMsgType(massMsgType);
5460
massMessage.setMediaId(mediaId);
5561
massMessage.getToUsers().add(configProvider.getOpenId());
5662

57-
WxMpMassSendResult massResult = wxService.massOpenIdsMessageSend(massMessage);
63+
WxMpMassSendResult massResult = this.wxService
64+
.massOpenIdsMessageSend(massMessage);
5865
Assert.assertNotNull(massResult);
5966
Assert.assertNotNull(massResult.getMsgId());
6067
}
@@ -64,35 +71,42 @@ public void testTextMassGroupMessageSend() throws WxErrorException {
6471
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
6572
massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT);
6673
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
67-
massMessage.setGroupId(wxService.getGroupService().groupGet().get(0).getId());
74+
massMessage
75+
.setGroupId(this.wxService.getGroupService().groupGet().get(0).getId());
6876

69-
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
77+
WxMpMassSendResult massResult = this.wxService
78+
.massGroupMessageSend(massMessage);
7079
Assert.assertNotNull(massResult);
7180
Assert.assertNotNull(massResult.getMsgId());
7281
}
7382

7483
@Test(dataProvider="massMessages")
75-
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId) throws WxErrorException, IOException {
84+
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId)
85+
throws WxErrorException {
7686
WxMpMassGroupMessage massMessage = new WxMpMassGroupMessage();
7787
massMessage.setMsgtype(massMsgType);
7888
massMessage.setMediaId(mediaId);
79-
massMessage.setGroupId(wxService.getGroupService().groupGet().get(0).getId());
89+
massMessage
90+
.setGroupId(this.wxService.getGroupService().groupGet().get(0).getId());
8091

81-
WxMpMassSendResult massResult = wxService.massGroupMessageSend(massMessage);
92+
WxMpMassSendResult massResult = this.wxService
93+
.massGroupMessageSend(massMessage);
8294
Assert.assertNotNull(massResult);
8395
Assert.assertNotNull(massResult.getMsgId());
8496
}
8597

8698
@DataProvider
8799
public Object[][] massMessages() throws WxErrorException, IOException {
88100
Object[][] messages = new Object[4][];
101+
89102
/*
90103
* 视频素材
91104
*/
92-
{
105+
try (InputStream inputStream = ClassLoader
106+
.getSystemResourceAsStream("mm.mp4")) {
93107
// 上传视频到媒体库
94-
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.mp4");
95-
WxMediaUploadResult uploadMediaRes = wxService.getMaterialService().mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream);
108+
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
109+
.mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream);
96110
Assert.assertNotNull(uploadMediaRes);
97111
Assert.assertNotNull(uploadMediaRes.getMediaId());
98112

@@ -101,38 +115,44 @@ public Object[][] massMessages() throws WxErrorException, IOException {
101115
video.setTitle("测试标题");
102116
video.setDescription("测试描述");
103117
video.setMediaId(uploadMediaRes.getMediaId());
104-
WxMpMassUploadResult uploadResult = wxService.massVideoUpload(video);
118+
WxMpMassUploadResult uploadResult = this.wxService.massVideoUpload(video);
105119
Assert.assertNotNull(uploadResult);
106120
Assert.assertNotNull(uploadResult.getMediaId());
107121
messages[0] = new Object[] { WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() };
108122
}
123+
109124
/**
110125
* 图片素材
111126
*/
112-
{
113-
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg");
114-
WxMediaUploadResult uploadMediaRes = wxService.getMaterialService().mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
127+
try (InputStream inputStream = ClassLoader
128+
.getSystemResourceAsStream("mm.jpeg")) {
129+
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
130+
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
115131
Assert.assertNotNull(uploadMediaRes);
116132
Assert.assertNotNull(uploadMediaRes.getMediaId());
117133
messages[1] = new Object[] { WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() };
118134
}
135+
119136
/**
120137
* 语音素材
121138
*/
122-
{
123-
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.mp3");
124-
WxMediaUploadResult uploadMediaRes = wxService.getMaterialService().mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream);
139+
try (InputStream inputStream = ClassLoader
140+
.getSystemResourceAsStream("mm.mp3")) {
141+
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
142+
.mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream);
125143
Assert.assertNotNull(uploadMediaRes);
126144
Assert.assertNotNull(uploadMediaRes.getMediaId());
127145
messages[2] = new Object[] { WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() };
128146
}
147+
129148
/**
130149
* 图文素材
131150
*/
132-
{
151+
try (InputStream inputStream = ClassLoader
152+
.getSystemResourceAsStream("mm.jpeg")) {
133153
// 上传照片到媒体库
134-
InputStream inputStream = ClassLoader.getSystemResourceAsStream("mm.jpeg");
135-
WxMediaUploadResult uploadMediaRes = wxService.getMaterialService().mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
154+
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
155+
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
136156
Assert.assertNotNull(uploadMediaRes);
137157
Assert.assertNotNull(uploadMediaRes.getMediaId());
138158

@@ -154,11 +174,13 @@ public Object[][] massMessages() throws WxErrorException, IOException {
154174
article2.setDigest("摘要2");
155175
news.addArticle(article2);
156176

157-
WxMpMassUploadResult massUploadResult = wxService.massNewsUpload(news);
177+
WxMpMassUploadResult massUploadResult = this.wxService
178+
.massNewsUpload(news);
158179
Assert.assertNotNull(massUploadResult);
159180
Assert.assertNotNull(uploadMediaRes.getMediaId());
160181
messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() };
161182
}
183+
162184
return messages;
163185
}
164186

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMessageRouterTest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ public WxEchoMpMessageHandler(StringBuffer sb, String echoStr) {
163163
@Override
164164
public WxMpXmlOutMessage handle(WxMpXmlMessage wxMessage, Map<String, Object> context, WxMpService wxMpService,
165165
WxSessionManager sessionManager) {
166-
sb.append(this.echoStr).append(',');
166+
this.sb.append(this.echoStr).append(',');
167167
return null;
168168
}
169169

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMiscAPITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ public class WxMpMiscAPITest {
2323

2424
@Test
2525
public void testGetCallbackIP() throws WxErrorException {
26-
String[] ipArray = wxService.getCallbackIP();
26+
String[] ipArray = this.wxService.getCallbackIP();
2727
System.out.println(Arrays.toString(ipArray));
2828
Assert.assertNotNull(ipArray);
2929
Assert.assertNotEquals(ipArray.length, 0);

weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpShortUrlAPITest.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ public class WxMpShortUrlAPITest {
2020
protected WxMpServiceImpl wxService;
2121

2222
public void testShortUrl() throws WxErrorException {
23-
String shortUrl = wxService.shortUrl("www.baidu.com");
23+
String shortUrl = this.wxService.shortUrl("www.baidu.com");
2424
Assert.assertNotNull(shortUrl);
2525
}
2626

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

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ public void testGetCardApiTicketWithParam() throws Exception {
4242
public void testCreateCardApiSignature() throws Exception {
4343
//app_id, card_id, card_type, code, openid, location_id
4444

45-
String[] param = {"123", cardId, "", code, openid, ""};
45+
String[] param = {"123", this.cardId, "", this.code, this.openid, ""};
4646
WxCardApiSignature cardApiSignature = this.wxService.getCardService().createCardApiSignature(param);
4747
assertNotNull(cardApiSignature);
4848
System.out.println(cardApiSignature);
@@ -58,34 +58,34 @@ public void testDecryptCardCode() throws Exception {
5858

5959
@Test
6060
public void testQueryCardCode() throws Exception {
61-
WxMpCardResult wxMpCardResult = this.wxService.getCardService().queryCardCode(cardId, code, false);
61+
WxMpCardResult wxMpCardResult = this.wxService.getCardService().queryCardCode(this.cardId, this.code, false);
6262
assertNotNull(wxMpCardResult);
6363
System.out.println(wxMpCardResult);
6464
}
6565

6666
@Test
6767
public void testConsumeCardCode() throws Exception {
68-
String result = this.wxService.getCardService().consumeCardCode(code);
68+
String result = this.wxService.getCardService().consumeCardCode(this.code);
6969
assertNotNull(result);
7070
System.out.println(result);
7171
}
7272

7373
@Test
7474
public void testConsumeCardCodeWithCardId() throws Exception {
75-
String result = this.wxService.getCardService().consumeCardCode(code, cardId);
75+
String result = this.wxService.getCardService().consumeCardCode(this.code, this.cardId);
7676
assertNotNull(result);
7777
System.out.println(result);
7878
}
7979

8080
@Test
8181
public void testMarkCardCode() throws Exception {
82-
this.wxService.getCardService().markCardCode(code, cardId, openid, true);
82+
this.wxService.getCardService().markCardCode(this.code, this.cardId, this.openid, true);
8383
System.out.println("done");
8484
}
8585

8686
@Test
8787
public void testGetCardDetail() throws Exception {
88-
String result = this.wxService.getCardService().getCardDetail(cardId);
88+
String result = this.wxService.getCardService().getCardDetail(this.cardId);
8989
assertNotNull(result);
9090
System.out.println(result);
9191
}

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -35,15 +35,15 @@ public void testGroupGet() throws WxErrorException {
3535
Assert.assertNotNull(groupList);
3636
Assert.assertTrue(groupList.size() > 0);
3737
for (WxMpGroup g : groupList) {
38-
group = g;
38+
this.group = g;
3939
Assert.assertNotNull(g.getName());
4040
}
4141
}
4242

4343
@Test(dependsOnMethods={"testGroupGet", "testGroupCreate"})
4444
public void getGroupUpdate() throws WxErrorException {
45-
group.setName("分组改名");
46-
this.wxService.getGroupService().groupUpdate(group);
45+
this.group.setName("分组改名");
46+
this.wxService.getGroupService().groupUpdate(this.group);
4747
}
4848

4949
}

0 commit comments

Comments
 (0)