mirror of
				https://gitee.com/binary/weixin-java-tools.git
				synced 2025-10-31 02:28:25 +08:00 
			
		
		
		
	🎨 重构补充部分单元测试代码
This commit is contained in:
		| @ -13,7 +13,6 @@ import java.util.List; | |||||||
|  */ |  */ | ||||||
| @Data | @Data | ||||||
| public class WxNetCheckResult implements Serializable { | public class WxNetCheckResult implements Serializable { | ||||||
|  |  | ||||||
|   private static final long serialVersionUID = 6918924418847404172L; |   private static final long serialVersionUID = 6918924418847404172L; | ||||||
|  |  | ||||||
|   private List<WxNetCheckDnsInfo> dnsInfos = new ArrayList<>(); |   private List<WxNetCheckDnsInfo> dnsInfos = new ArrayList<>(); | ||||||
|  | |||||||
| @ -0,0 +1,58 @@ | |||||||
|  | package me.chanjar.weixin.common.bean; | ||||||
|  |  | ||||||
|  | import org.testng.Assert; | ||||||
|  | import org.testng.annotations.Test; | ||||||
|  |  | ||||||
|  | /** | ||||||
|  |  * | ||||||
|  |  * @author <a href="https://github.com/binarywang">Binary Wang</a> | ||||||
|  |  * @date 2020-06-06 | ||||||
|  |  */ | ||||||
|  | public class WxNetCheckResultTest { | ||||||
|  |  | ||||||
|  |   @Test | ||||||
|  |   public void testFromJson() { | ||||||
|  |     String json = "{\n" + | ||||||
|  |       "    \"dns\": [\n" + | ||||||
|  |       "        {\n" + | ||||||
|  |       "            \"ip\": \"111.161.64.40\", \n" + | ||||||
|  |       "            \"real_operator\": \"UNICOM\"\n" + | ||||||
|  |       "        }, \n" + | ||||||
|  |       "        {\n" + | ||||||
|  |       "            \"ip\": \"111.161.64.48\", \n" + | ||||||
|  |       "            \"real_operator\": \"UNICOM\"\n" + | ||||||
|  |       "        }\n" + | ||||||
|  |       "    ], \n" + | ||||||
|  |       "    \"ping\": [\n" + | ||||||
|  |       "        {\n" + | ||||||
|  |       "            \"ip\": \"111.161.64.40\", \n" + | ||||||
|  |       "            \"from_operator\": \"UNICOM\"," + | ||||||
|  |       "            \"package_loss\": \"0%\", \n" + | ||||||
|  |       "            \"time\": \"23.079ms\"\n" + | ||||||
|  |       "        }, \n" + | ||||||
|  |       "        {\n" + | ||||||
|  |       "            \"ip\": \"111.161.64.48\", \n" + | ||||||
|  |       "            \"from_operator\": \"UNICOM\", \n" + | ||||||
|  |       "            \"package_loss\": \"0%\", \n" + | ||||||
|  |       "            \"time\": \"21.434ms\"\n" + | ||||||
|  |       "        }\n" + | ||||||
|  |       "    ]\n" + | ||||||
|  |       "}"; | ||||||
|  |     WxNetCheckResult result = WxNetCheckResult.fromJson(json); | ||||||
|  |     Assert.assertNotNull(result); | ||||||
|  |     Assert.assertNotNull(result.getDnsInfos()); | ||||||
|  |  | ||||||
|  |     WxNetCheckResult.WxNetCheckDnsInfo dnsInfo = new WxNetCheckResult.WxNetCheckDnsInfo(); | ||||||
|  |     dnsInfo.setIp("111.161.64.40"); | ||||||
|  |     dnsInfo.setRealOperator("UNICOM"); | ||||||
|  |     Assert.assertEquals(result.getDnsInfos().get(0), dnsInfo); | ||||||
|  |  | ||||||
|  |     WxNetCheckResult.WxNetCheckPingInfo pingInfo = new WxNetCheckResult.WxNetCheckPingInfo(); | ||||||
|  |     pingInfo.setTime("21.434ms"); | ||||||
|  |     pingInfo.setFromOperator("UNICOM"); | ||||||
|  |     pingInfo.setIp("111.161.64.48"); | ||||||
|  |     pingInfo.setPackageLoss("0%"); | ||||||
|  |     Assert.assertEquals(result.getPingInfos().get(1), pingInfo); | ||||||
|  |  | ||||||
|  |   } | ||||||
|  | } | ||||||
| @ -7,6 +7,7 @@ import java.util.concurrent.ExecutorService; | |||||||
| import java.util.concurrent.Executors; | import java.util.concurrent.Executors; | ||||||
| import java.util.concurrent.TimeUnit; | import java.util.concurrent.TimeUnit; | ||||||
| import me.chanjar.weixin.common.api.WxConsts; | import me.chanjar.weixin.common.api.WxConsts; | ||||||
|  | import me.chanjar.weixin.common.bean.WxJsapiSignature; | ||||||
| import me.chanjar.weixin.common.bean.WxNetCheckResult; | import me.chanjar.weixin.common.bean.WxNetCheckResult; | ||||||
| import me.chanjar.weixin.common.error.WxErrorException; | import me.chanjar.weixin.common.error.WxErrorException; | ||||||
| import me.chanjar.weixin.mp.api.WxMpService; | import me.chanjar.weixin.mp.api.WxMpService; | ||||||
| @ -57,52 +58,6 @@ public class BaseWxMpServiceImplTest { | |||||||
|  |  | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Test |  | ||||||
|   public void testNectCheckResult() { |  | ||||||
|     String json = "{\n" + |  | ||||||
|       "    \"dns\": [\n" + |  | ||||||
|       "        {\n" + |  | ||||||
|       "            \"ip\": \"111.161.64.40\", \n" + |  | ||||||
|       "            \"real_operator\": \"UNICOM\"\n" + |  | ||||||
|       "        }, \n" + |  | ||||||
|       "        {\n" + |  | ||||||
|       "            \"ip\": \"111.161.64.48\", \n" + |  | ||||||
|       "            \"real_operator\": \"UNICOM\"\n" + |  | ||||||
|       "        }\n" + |  | ||||||
|       "    ], \n" + |  | ||||||
|       "    \"ping\": [\n" + |  | ||||||
|       "        {\n" + |  | ||||||
|       "            \"ip\": \"111.161.64.40\", \n" + |  | ||||||
|       "            \"from_operator\": \"UNICOM\"," + |  | ||||||
|       "            \"package_loss\": \"0%\", \n" + |  | ||||||
|       "            \"time\": \"23.079ms\"\n" + |  | ||||||
|       "        }, \n" + |  | ||||||
|       "        {\n" + |  | ||||||
|       "            \"ip\": \"111.161.64.48\", \n" + |  | ||||||
|       "            \"from_operator\": \"UNICOM\", \n" + |  | ||||||
|       "            \"package_loss\": \"0%\", \n" + |  | ||||||
|       "            \"time\": \"21.434ms\"\n" + |  | ||||||
|       "        }\n" + |  | ||||||
|       "    ]\n" + |  | ||||||
|       "}"; |  | ||||||
|     WxNetCheckResult result = WxNetCheckResult.fromJson(json); |  | ||||||
|     Assert.assertNotNull(result); |  | ||||||
|     Assert.assertNotNull(result.getDnsInfos()); |  | ||||||
|  |  | ||||||
|     WxNetCheckResult.WxNetCheckDnsInfo dnsInfo = new WxNetCheckResult.WxNetCheckDnsInfo(); |  | ||||||
|     dnsInfo.setIp("111.161.64.40"); |  | ||||||
|     dnsInfo.setRealOperator("UNICOM"); |  | ||||||
|     Assert.assertEquals(result.getDnsInfos().get(0), dnsInfo); |  | ||||||
|  |  | ||||||
|     WxNetCheckResult.WxNetCheckPingInfo pingInfo = new WxNetCheckResult.WxNetCheckPingInfo(); |  | ||||||
|     pingInfo.setTime("21.434ms"); |  | ||||||
|     pingInfo.setFromOperator("UNICOM"); |  | ||||||
|     pingInfo.setIp("111.161.64.48"); |  | ||||||
|     pingInfo.setPackageLoss("0%"); |  | ||||||
|     Assert.assertEquals(result.getPingInfos().get(1), pingInfo); |  | ||||||
|  |  | ||||||
|   } |  | ||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
|   public void testGetCallbackIP() throws WxErrorException { |   public void testGetCallbackIP() throws WxErrorException { | ||||||
|     String[] ipArray = this.wxService.getCallbackIP(); |     String[] ipArray = this.wxService.getCallbackIP(); | ||||||
| @ -174,7 +129,11 @@ public class BaseWxMpServiceImplTest { | |||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
|   public void testCreateJsapiSignature() { |   public void testCreateJsapiSignature() throws WxErrorException { | ||||||
|  |     final WxJsapiSignature jsapiSignature = this.wxService.createJsapiSignature("http://www.baidu.com"); | ||||||
|  |     assertThat(jsapiSignature).isNotNull(); | ||||||
|  |     assertThat(jsapiSignature.getSignature()).isNotNull(); | ||||||
|  |     System.out.println(jsapiSignature); | ||||||
|   } |   } | ||||||
|  |  | ||||||
|   @Test |   @Test | ||||||
|  | |||||||
		Reference in New Issue
	
	Block a user
	 Binary Wang
					Binary Wang