mirror of
https://gitee.com/binary/weixin-java-tools.git
synced 2025-11-01 20:13:12 +08:00
🎨 #1189 优化错误异常输出,移除冗余代码
This commit is contained in:
@ -1,34 +1,34 @@
|
||||
package me.chanjar.weixin.common.error;
|
||||
|
||||
import org.testng.Assert;
|
||||
import me.chanjar.weixin.common.WxType;
|
||||
import org.testng.annotations.Test;
|
||||
|
||||
import static org.testng.Assert.*;
|
||||
import static org.testng.Assert.assertEquals;
|
||||
import static org.testng.Assert.assertNull;
|
||||
|
||||
@Test
|
||||
public class WxErrorTest {
|
||||
|
||||
public void testFromJson() {
|
||||
String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\" }";
|
||||
WxError wxError = WxError.fromJson(json);
|
||||
WxError wxError = WxError.fromJson(json, WxType.MP);
|
||||
assertEquals(40003, wxError.getErrorCode());
|
||||
assertEquals(wxError.getErrorMsg(), "invalid openid");
|
||||
assertEquals(wxError.getErrorMsgEn(), "invalid openid");
|
||||
|
||||
}
|
||||
|
||||
public void testFromBadJson1() {
|
||||
String json = "{ \"errcode\": 40003, \"errmsg\": \"invalid openid\", \"media_id\": \"12323423dsfafsf232f\" }";
|
||||
WxError wxError = WxError.fromJson(json);
|
||||
WxError wxError = WxError.fromJson(json, WxType.MP);
|
||||
assertEquals(40003, wxError.getErrorCode());
|
||||
assertEquals(wxError.getErrorMsg(), "invalid openid");
|
||||
assertEquals(wxError.getErrorMsgEn(), "invalid openid");
|
||||
|
||||
}
|
||||
|
||||
public void testFromBadJson2() {
|
||||
String json = "{\"access_token\":\"ACCESS_TOKEN\",\"expires_in\":7200}";
|
||||
WxError wxError = WxError.fromJson(json);
|
||||
WxError wxError = WxError.fromJson(json, WxType.MP);
|
||||
assertEquals(0, wxError.getErrorCode());
|
||||
assertEquals(wxError.getErrorMsg(), null);
|
||||
assertNull(wxError.getErrorMsg());
|
||||
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user