From b44f9b315f0413289cc50fdf3aa896cb637bae15 Mon Sep 17 00:00:00 2001 From: Binary Wang Date: Sat, 27 Jan 2018 14:48:27 +0800 Subject: [PATCH] =?UTF-8?q?=E4=BC=98=E5=8C=96=E9=83=A8=E5=88=86=E6=B5=8B?= =?UTF-8?q?=E8=AF=95=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- weixin-java-mp/pom.xml | 5 + .../mp/api/impl/WxMpKefuServiceImplTest.java | 97 ++++++++----------- 2 files changed, 46 insertions(+), 56 deletions(-) diff --git a/weixin-java-mp/pom.xml b/weixin-java-mp/pom.xml index 8e1ccdf36..964798aba 100644 --- a/weixin-java-mp/pom.xml +++ b/weixin-java-mp/pom.xml @@ -65,6 +65,11 @@ logback-classic test + + org.assertj + assertj-guava + test + org.projectlombok lombok diff --git a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java index 309d38180..d0c3aac83 100644 --- a/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java +++ b/weixin-java-mp/src/test/java/me/chanjar/weixin/mp/api/impl/WxMpKefuServiceImplTest.java @@ -10,12 +10,13 @@ import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.result.*; import org.joda.time.DateTime; -import org.testng.*; import org.testng.annotations.*; import java.io.File; import java.util.Date; +import static org.assertj.core.api.Assertions.assertThat; + /** * 测试客服相关接口 * @@ -29,53 +30,50 @@ public class WxMpKefuServiceImplTest { protected WxMpService wxService; public void testSendKefuMpNewsMessage() throws WxErrorException { - TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.KefuMsgType.MPNEWS); message.setToUser(configStorage.getOpenid()); message.setMpNewsMediaId("52R6dL2FxDpM9N1rCY3sYBqHwq-L7K_lz1sPI71idMg"); - this.wxService.getKefuService().sendKefuMessage(message); + boolean result = this.wxService.getKefuService().sendKefuMessage(message); + assertThat(result).isTrue(); } public void testSendKefuMessage() throws WxErrorException { - TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getOpenid()); - message.setContent( - "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); + message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); - this.wxService.getKefuService().sendKefuMessage(message); + boolean result = this.wxService.getKefuService().sendKefuMessage(message); + assertThat(result).isTrue(); } public void testSendKefuMessageWithKfAccount() throws WxErrorException { - TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); WxMpKefuMessage message = new WxMpKefuMessage(); message.setMsgType(WxConsts.KefuMsgType.TEXT); message.setToUser(configStorage.getOpenid()); message.setKfAccount(configStorage.getKfAccount()); - message.setContent( - "欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); + message.setContent("欢迎欢迎,热烈欢迎\n换行测试\n超链接:Hello World"); - this.wxService.getKefuService().sendKefuMessage(message); + boolean result = this.wxService.getKefuService().sendKefuMessage(message); + assertThat(result).isTrue(); } public void testKfList() throws WxErrorException { WxMpKfList kfList = this.wxService.getKefuService().kfList(); - Assert.assertNotNull(kfList); + assertThat(kfList).isNotNull(); for (WxMpKfInfo k : kfList.getKfList()) { System.err.println(k); } } public void testKfOnlineList() throws WxErrorException { - WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService() - .kfOnlineList(); - Assert.assertNotNull(kfOnlineList); + WxMpKfOnlineList kfOnlineList = this.wxService.getKefuService().kfOnlineList(); + assertThat(kfOnlineList).isNotNull(); for (WxMpKfInfo k : kfOnlineList.getKfOnlineList()) { System.err.println(k); } @@ -83,8 +81,7 @@ public class WxMpKefuServiceImplTest { @DataProvider public Object[][] getKfAccount() { - TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); + TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); return new Object[][]{{configStorage.getKfAccount()}}; } @@ -92,7 +89,7 @@ public class WxMpKefuServiceImplTest { public void testKfAccountAdd(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() .kfAccount(kfAccount).nickName("我晕").build(); - Assert.assertTrue(this.wxService.getKefuService().kfAccountAdd(request)); + assertThat(this.wxService.getKefuService().kfAccountAdd(request)).isTrue(); } @Test(dependsOnMethods = { @@ -100,7 +97,7 @@ public class WxMpKefuServiceImplTest { public void testKfAccountUpdate(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() .kfAccount(kfAccount).nickName("我晕").build(); - Assert.assertTrue(this.wxService.getKefuService().kfAccountUpdate(request)); + assertThat(this.wxService.getKefuService().kfAccountUpdate(request)).isTrue(); } @Test(dependsOnMethods = { @@ -108,71 +105,59 @@ public class WxMpKefuServiceImplTest { public void testKfAccountInviteWorker(String kfAccount) throws WxErrorException { WxMpKfAccountRequest request = WxMpKfAccountRequest.builder() .kfAccount(kfAccount).inviteWx(" ").build(); - Assert.assertTrue(this.wxService.getKefuService().kfAccountInviteWorker(request)); + assertThat(this.wxService.getKefuService().kfAccountInviteWorker(request)).isTrue(); } - @Test(dependsOnMethods = { - "testKfAccountUpdate"}, dataProvider = "getKfAccount") - public void testKfAccountUploadHeadImg(String kfAccount) - throws WxErrorException { + @Test(dependsOnMethods = {"testKfAccountUpdate", "testKfAccountAdd"}, dataProvider = "getKfAccount") + public void testKfAccountUploadHeadImg(String kfAccount) throws WxErrorException { File imgFile = new File("src\\test\\resources\\mm.jpeg"); - boolean result = this.wxService.getKefuService() - .kfAccountUploadHeadImg(kfAccount, imgFile); - Assert.assertTrue(result); + boolean result = this.wxService.getKefuService().kfAccountUploadHeadImg(kfAccount, imgFile); + assertThat(result).isTrue(); } @Test(dataProvider = "getKfAccount") public void testKfAccountDel(String kfAccount) throws WxErrorException { boolean result = this.wxService.getKefuService().kfAccountDel(kfAccount); - Assert.assertTrue(result); + assertThat(result).isTrue(); } @DataProvider public Object[][] getKfAccountAndOpenid() { - TestConfigStorage configStorage = (TestConfigStorage) this.wxService - .getWxMpConfigStorage(); - return new Object[][]{ - {configStorage.getKfAccount(), configStorage.getOpenid()}}; + TestConfigStorage configStorage = (TestConfigStorage) this.wxService.getWxMpConfigStorage(); + return new Object[][]{{configStorage.getKfAccount(), configStorage.getOpenid()}}; } @Test(dataProvider = "getKfAccountAndOpenid") - public void testKfSessionCreate(String kfAccount, String openid) - throws WxErrorException { - boolean result = this.wxService.getKefuService().kfSessionCreate(openid, - kfAccount); - Assert.assertTrue(result); + public void testKfSessionCreate(String kfAccount, String openid) throws WxErrorException { + boolean result = this.wxService.getKefuService().kfSessionCreate(openid, kfAccount); + assertThat(result).isTrue(); } @Test(dataProvider = "getKfAccountAndOpenid") public void testKfSessionClose(String kfAccount, String openid) throws WxErrorException { - boolean result = this.wxService.getKefuService().kfSessionClose(openid, - kfAccount); - Assert.assertTrue(result); + boolean result = this.wxService.getKefuService().kfSessionClose(openid, kfAccount); + assertThat(result).isTrue(); } @Test(dataProvider = "getKfAccountAndOpenid") - public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, - String openid) throws WxErrorException { - WxMpKfSessionGetResult result = this.wxService.getKefuService() - .kfSessionGet(openid); - Assert.assertNotNull(result); + public void testKfSessionGet(@SuppressWarnings("unused") String kfAccount, String openid) throws WxErrorException { + WxMpKfSessionGetResult result = this.wxService.getKefuService().kfSessionGet(openid); + assertThat(result).isNotNull(); System.err.println(result); } @Test(dataProvider = "getKfAccount") public void testKfSessionList(String kfAccount) throws WxErrorException { - WxMpKfSessionList result = this.wxService.getKefuService() - .kfSessionList(kfAccount); - Assert.assertNotNull(result); + WxMpKfSessionList result = this.wxService.getKefuService().kfSessionList(kfAccount); + assertThat(result).isNotNull(); System.err.println(result); } @Test public void testKfSessionGetWaitCase() throws WxErrorException { - WxMpKfSessionWaitCaseList result = this.wxService.getKefuService() - .kfSessionGetWaitCase(); - Assert.assertNotNull(result); + WxMpKfSessionWaitCaseList result = this.wxService.getKefuService().kfSessionGetWaitCase(); + assertThat(result).isNotNull(); System.err.println(result); } @@ -181,7 +166,7 @@ public class WxMpKefuServiceImplTest { Date startTime = DateTime.now().minusDays(1).toDate(); Date endTime = DateTime.now().minusDays(0).toDate(); WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime, 1L, 50); - Assert.assertNotNull(result); + assertThat(result).isNotNull(); System.err.println(result); } @@ -190,7 +175,7 @@ public class WxMpKefuServiceImplTest { Date startTime = DateTime.now().minusDays(1).toDate(); Date endTime = DateTime.now().minusDays(0).toDate(); WxMpKfMsgList result = this.wxService.getKefuService().kfMsgList(startTime, endTime); - Assert.assertNotNull(result); + assertThat(result).isNotNull(); System.err.println(result); } }