Browse Source

单元测试代码优化

master
BinaryWang 8 years ago
parent
commit
7deb25b4bb
3 changed files with 27 additions and 19 deletions
  1. +2
    -2
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java
  2. +15
    -13
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMediaAPITest.java
  3. +10
    -4
      weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpQrCodeAPITest.java

+ 2
- 2
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpBaseAPITest.java View File

@@ -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);


+ 15
- 13
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpMediaAPITest.java View File

@@ -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


+ 10
- 4
weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/WxMpQrCodeAPITest.java View File

@@ -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…
Cancel
Save