mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-08-23 13:06:54 +08:00
单元测试代码优化
This commit is contained in:
parent
ed80cece22
commit
7deb25b4bb
@ -20,9 +20,9 @@ public class WxMpBaseAPITest {
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testRefreshAccessToken() throws WxErrorException {
|
||||
WxMpConfigStorage configStorage = wxService.wxMpConfigStorage;
|
||||
WxMpConfigStorage configStorage = this.wxService.wxMpConfigStorage;
|
||||
String before = configStorage.getAccessToken();
|
||||
wxService.getAccessToken(false);
|
||||
this.wxService.getAccessToken(false);
|
||||
|
||||
String after = configStorage.getAccessToken();
|
||||
Assert.assertNotEquals(before, after);
|
||||
|
@ -26,21 +26,23 @@ public class WxMpMediaAPITest {
|
||||
@Inject
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
private List<String> media_ids = new ArrayList<String>();
|
||||
private List<String> media_ids = new ArrayList<>();
|
||||
|
||||
@Test(dataProvider="uploadMedia")
|
||||
public void testUploadMedia(String mediaType, String fileType, String fileName) throws WxErrorException, IOException {
|
||||
InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName);
|
||||
WxMediaUploadResult res = wxService.mediaUpload(mediaType, fileType, inputStream);
|
||||
Assert.assertNotNull(res.getType());
|
||||
Assert.assertNotNull(res.getCreatedAt());
|
||||
Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null);
|
||||
|
||||
if (res.getMediaId() != null) {
|
||||
media_ids.add(res.getMediaId());
|
||||
}
|
||||
if (res.getThumbMediaId() != null) {
|
||||
media_ids.add(res.getThumbMediaId());
|
||||
try(InputStream inputStream = ClassLoader.getSystemResourceAsStream(fileName)){
|
||||
WxMediaUploadResult res = this.wxService.mediaUpload(mediaType, fileType, inputStream);
|
||||
Assert.assertNotNull(res.getType());
|
||||
Assert.assertNotNull(res.getCreatedAt());
|
||||
Assert.assertTrue(res.getMediaId() != null || res.getThumbMediaId() != null);
|
||||
|
||||
if (res.getMediaId() != null) {
|
||||
this.media_ids.add(res.getMediaId());
|
||||
}
|
||||
|
||||
if (res.getThumbMediaId() != null) {
|
||||
this.media_ids.add(res.getThumbMediaId());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -56,7 +58,7 @@ public class WxMpMediaAPITest {
|
||||
|
||||
@Test(dependsOnMethods = { "testUploadMedia" }, dataProvider="downloadMedia")
|
||||
public void testDownloadMedia(String media_id) throws WxErrorException {
|
||||
wxService.mediaDownload(media_id);
|
||||
this.wxService.mediaDownload(media_id);
|
||||
}
|
||||
|
||||
@DataProvider
|
||||
|
@ -22,23 +22,29 @@ public class WxMpQrCodeAPITest {
|
||||
protected WxMpServiceImpl wxService;
|
||||
|
||||
public void testQrCodeCreateTmpTicket() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = wxService.qrCodeCreateTmpTicket(1, null);
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateTmpTicket(1, null);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() != -1);
|
||||
}
|
||||
|
||||
public void testQrCodeCreateLastTicket() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1);
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
Assert.assertNotNull(ticket.getUrl());
|
||||
Assert.assertNotNull(ticket.getTicket());
|
||||
Assert.assertTrue(ticket.getExpire_seconds() == -1);
|
||||
}
|
||||
|
||||
public void testQrCodePicture() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = wxService.qrCodeCreateLastTicket(1);
|
||||
File file = wxService.qrCodePicture(ticket);
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
File file = this.wxService.qrCodePicture(ticket);
|
||||
Assert.assertNotNull(file);
|
||||
}
|
||||
|
||||
public void testQrCodePictureUrl() throws WxErrorException {
|
||||
WxMpQrCodeTicket ticket = this.wxService.qrCodeCreateLastTicket(1);
|
||||
String url = this.wxService.qrCodePictureUrl(ticket.getTicket());
|
||||
Assert.assertNotNull(url);
|
||||
}
|
||||
|
||||
}
|
||||
|
Loading…
Reference in New Issue
Block a user