1
0
mirror of synced 2026-02-17 10:47:49 +08:00

🎨 【小程序】同城配送查询门店余额接口补充了几个遗漏属性,同时优化代码,避免可能出现的NPE问题

This commit is contained in:
GeXiangDong
2024-11-06 21:29:01 +08:00
committed by Binary Wang
parent 9c6fca77e6
commit 5c266d546f
3 changed files with 138 additions and 8 deletions

View File

@@ -8,9 +8,11 @@ import cn.binarywang.wx.miniapp.bean.openapi.WxMiniGetApiQuotaResult;
import cn.binarywang.wx.miniapp.constant.WxMaApiUrlConstants;
import cn.binarywang.wx.miniapp.test.ApiTestModule;
import cn.binarywang.wx.miniapp.test.TestConfig;
import com.google.gson.JsonObject;
import com.google.inject.Inject;
import java.util.ArrayList;
import java.util.List;
import me.chanjar.weixin.common.bean.ToJson;
import me.chanjar.weixin.common.error.WxErrorException;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@@ -35,6 +37,85 @@ public class WxMaIntracityServiceImpleTest {
logger.info("apply 额度剩余 :{}", result.getQuota());
}
@Test
public void testApiGetPostNullData() throws Exception {
try {
wxService.get(WxMaApiUrlConstants.Analysis.GET_USER_PORTRAIT_URL, null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 get(url, null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
// 走加密路径url
try {
wxService.post(WxMaApiUrlConstants.OpenApi.CLEAR_QUOTA, (Object) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, Object null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
try {
wxService.post(WxMaApiUrlConstants.OpenApi.CLEAR_QUOTA, (String) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, String null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
try {
wxService.post(WxMaApiUrlConstants.OpenApi.CLEAR_QUOTA, (JsonObject) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, JsonObject null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
try {
wxService.post(WxMaApiUrlConstants.OpenApi.CLEAR_QUOTA, (ToJson) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, ToJson null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
// 不走加密路径URL
try {
wxService.post(WxMaApiUrlConstants.Intracity.APPLY_URL, (Object) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, Object null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
try {
wxService.post(WxMaApiUrlConstants.Intracity.APPLY_URL, (String) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, String null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
try {
wxService.post(WxMaApiUrlConstants.Intracity.APPLY_URL, (JsonObject) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, JsonObject null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
try {
wxService.post(WxMaApiUrlConstants.Intracity.APPLY_URL, (ToJson) null);
} catch (NullPointerException npe) {
logger.error("NullPointerException", npe);
fail("遇到空指针 post(url, ToJson null)");
} catch (WxErrorException wxErrorException) {
// 这个是正常的,因为这里的调用没按照接口规则
}
}
@Test
public void testApply() throws Exception {
logger.debug("testApply");