Skip to content

Commit 9246243

Browse files
committed
fix test code
1 parent dc33436 commit 9246243

File tree

1 file changed

+36
-38
lines changed

1 file changed

+36
-38
lines changed

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

Lines changed: 36 additions & 38 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,6 @@
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-
113
import com.google.inject.Inject;
12-
134
import me.chanjar.weixin.common.api.WxConsts;
145
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
156
import me.chanjar.weixin.common.exception.WxErrorException;
@@ -19,13 +10,20 @@
1910
import me.chanjar.weixin.mp.bean.WxMpMassVideo;
2011
import me.chanjar.weixin.mp.bean.result.WxMpMassSendResult;
2112
import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
13+
import org.testng.Assert;
14+
import org.testng.annotations.DataProvider;
15+
import org.testng.annotations.Guice;
16+
import org.testng.annotations.Test;
17+
18+
import java.io.IOException;
19+
import java.io.InputStream;
2220

2321
/**
2422
* 测试群发消息
25-
* @author chanjarster
2623
*
24+
* @author chanjarster
2725
*/
28-
@Test(groups = "massAPI", dependsOnGroups = { "baseAPI", "mediaAPI", "groupAPI"})
26+
@Test(groups = "massAPI", dependsOnGroups = {"baseAPI", "mediaAPI", "groupAPI"})
2927
@Guice(modules = ApiTestModule.class)
3028
public class WxMpMassMessageAPITest {
3129

@@ -36,60 +34,60 @@ public class WxMpMassMessageAPITest {
3634
public void testTextMassOpenIdsMessageSend() throws WxErrorException {
3735
// 发送群发消息
3836
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService
39-
.getWxMpConfigStorage();
37+
.getWxMpConfigStorage();
4038
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
4139
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
4240
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
4341
massMessage.getToUsers().add(configProvider.getOpenid());
4442

4543
WxMpMassSendResult massResult = this.wxService
46-
.massOpenIdsMessageSend(massMessage);
44+
.massOpenIdsMessageSend(massMessage);
4745
Assert.assertNotNull(massResult);
4846
Assert.assertNotNull(massResult.getMsgId());
4947
}
5048

51-
@Test(dataProvider="massMessages")
49+
@Test(dataProvider = "massMessages")
5250
public void testMediaMassOpenIdsMessageSend(String massMsgType,
53-
String mediaId) throws WxErrorException {
51+
String mediaId) throws WxErrorException {
5452
// 发送群发消息
5553
WxXmlMpInMemoryConfigStorage configProvider = (WxXmlMpInMemoryConfigStorage) this.wxService
56-
.getWxMpConfigStorage();
54+
.getWxMpConfigStorage();
5755
WxMpMassOpenIdsMessage massMessage = new WxMpMassOpenIdsMessage();
5856
massMessage.setMsgType(massMsgType);
5957
massMessage.setMediaId(mediaId);
6058
massMessage.getToUsers().add(configProvider.getOpenid());
6159

6260
WxMpMassSendResult massResult = this.wxService
63-
.massOpenIdsMessageSend(massMessage);
61+
.massOpenIdsMessageSend(massMessage);
6462
Assert.assertNotNull(massResult);
6563
Assert.assertNotNull(massResult.getMsgId());
6664
}
6765

6866
@Test
6967
public void testTextMassGroupMessageSend() throws WxErrorException {
7068
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
71-
massMessage.setMsgtype(WxConsts.MASS_MSG_TEXT);
69+
massMessage.setMsgType(WxConsts.MASS_MSG_TEXT);
7270
massMessage.setContent("测试群发消息\n欢迎欢迎,热烈欢迎\n换行测试\n超链接:<a href=\"http://www.baidu.com\">Hello World</a>");
7371
massMessage
74-
.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
72+
.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
7573

7674
WxMpMassSendResult massResult = this.wxService
77-
.massGroupMessageSend(massMessage);
75+
.massGroupMessageSend(massMessage);
7876
Assert.assertNotNull(massResult);
7977
Assert.assertNotNull(massResult.getMsgId());
8078
}
8179

82-
@Test(dataProvider="massMessages")
80+
@Test(dataProvider = "massMessages")
8381
public void testMediaMassGroupMessageSend(String massMsgType, String mediaId)
84-
throws WxErrorException {
82+
throws WxErrorException {
8583
WxMpMassTagMessage massMessage = new WxMpMassTagMessage();
86-
massMessage.setMsgtype(massMsgType);
84+
massMessage.setMsgType(massMsgType);
8785
massMessage.setMediaId(mediaId);
8886
massMessage
89-
.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
87+
.setTagId(this.wxService.getUserTagService().tagGet().get(0).getId());
9088

9189
WxMpMassSendResult massResult = this.wxService
92-
.massGroupMessageSend(massMessage);
90+
.massGroupMessageSend(massMessage);
9391
Assert.assertNotNull(massResult);
9492
Assert.assertNotNull(massResult.getMsgId());
9593
}
@@ -102,10 +100,10 @@ public Object[][] massMessages() throws WxErrorException, IOException {
102100
* 视频素材
103101
*/
104102
try (InputStream inputStream = ClassLoader
105-
.getSystemResourceAsStream("mm.mp4")) {
103+
.getSystemResourceAsStream("mm.mp4")) {
106104
// 上传视频到媒体库
107105
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
108-
.mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream);
106+
.mediaUpload(WxConsts.MEDIA_VIDEO, WxConsts.FILE_MP4, inputStream);
109107
Assert.assertNotNull(uploadMediaRes);
110108
Assert.assertNotNull(uploadMediaRes.getMediaId());
111109

@@ -117,41 +115,41 @@ public Object[][] massMessages() throws WxErrorException, IOException {
117115
WxMpMassUploadResult uploadResult = this.wxService.massVideoUpload(video);
118116
Assert.assertNotNull(uploadResult);
119117
Assert.assertNotNull(uploadResult.getMediaId());
120-
messages[0] = new Object[] { WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId() };
118+
messages[0] = new Object[]{WxConsts.MASS_MSG_VIDEO, uploadResult.getMediaId()};
121119
}
122120

123121
/**
124122
* 图片素材
125123
*/
126124
try (InputStream inputStream = ClassLoader
127-
.getSystemResourceAsStream("mm.jpeg")) {
125+
.getSystemResourceAsStream("mm.jpeg")) {
128126
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
129-
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
127+
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
130128
Assert.assertNotNull(uploadMediaRes);
131129
Assert.assertNotNull(uploadMediaRes.getMediaId());
132-
messages[1] = new Object[] { WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId() };
130+
messages[1] = new Object[]{WxConsts.MASS_MSG_IMAGE, uploadMediaRes.getMediaId()};
133131
}
134132

135133
/**
136134
* 语音素材
137135
*/
138136
try (InputStream inputStream = ClassLoader
139-
.getSystemResourceAsStream("mm.mp3")) {
137+
.getSystemResourceAsStream("mm.mp3")) {
140138
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
141-
.mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream);
139+
.mediaUpload(WxConsts.MEDIA_VOICE, WxConsts.FILE_MP3, inputStream);
142140
Assert.assertNotNull(uploadMediaRes);
143141
Assert.assertNotNull(uploadMediaRes.getMediaId());
144-
messages[2] = new Object[] { WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId() };
142+
messages[2] = new Object[]{WxConsts.MASS_MSG_VOICE, uploadMediaRes.getMediaId()};
145143
}
146144

147145
/**
148146
* 图文素材
149147
*/
150148
try (InputStream inputStream = ClassLoader
151-
.getSystemResourceAsStream("mm.jpeg")) {
149+
.getSystemResourceAsStream("mm.jpeg")) {
152150
// 上传照片到媒体库
153151
WxMediaUploadResult uploadMediaRes = this.wxService.getMaterialService()
154-
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
152+
.mediaUpload(WxConsts.MEDIA_IMAGE, WxConsts.FILE_JPG, inputStream);
155153
Assert.assertNotNull(uploadMediaRes);
156154
Assert.assertNotNull(uploadMediaRes.getMediaId());
157155

@@ -174,10 +172,10 @@ public Object[][] massMessages() throws WxErrorException, IOException {
174172
news.addArticle(article2);
175173

176174
WxMpMassUploadResult massUploadResult = this.wxService
177-
.massNewsUpload(news);
175+
.massNewsUpload(news);
178176
Assert.assertNotNull(massUploadResult);
179177
Assert.assertNotNull(uploadMediaRes.getMediaId());
180-
messages[3] = new Object[] { WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId() };
178+
messages[3] = new Object[]{WxConsts.MASS_MSG_NEWS, massUploadResult.getMediaId()};
181179
}
182180

183181
return messages;

0 commit comments

Comments
 (0)