尽量使用接口引用 use interface where possible

This commit is contained in:
Binary Wang 2016-10-29 16:59:53 +08:00
parent 639206ca1a
commit 1ceb4bf707
19 changed files with 52 additions and 49 deletions

View File

@ -18,10 +18,10 @@ public class ApiTestModule implements Module {
.getSystemResourceAsStream("test-config.xml")) {
WxXmlMpInMemoryConfigStorage config = this
.fromXml(WxXmlMpInMemoryConfigStorage.class, is1);
WxMpServiceImpl wxService = new WxMpServiceImpl();
WxMpService wxService = new WxMpServiceImpl();
wxService.setWxMpConfigStorage(config);
binder.bind(WxMpServiceImpl.class).toInstance(wxService);
binder.bind(WxMpService.class).toInstance(wxService);
binder.bind(WxMpConfigStorage.class).toInstance(config);
} catch (IOException e) {
e.printStackTrace();

View File

@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.apache.commons.lang3.StringUtils;
import org.testng.Assert;
import org.testng.annotations.Guice;
@ -18,7 +17,7 @@ import org.testng.annotations.Test;
public class WxMpBaseAPITest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
public void testRefreshAccessToken() throws WxErrorException {
WxMpConfigStorage configStorage = this.wxService.getWxMpConfigStorage();

View File

@ -8,11 +8,10 @@ import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
/**
* 测试jsapi ticket接口
*
*
* @author chanjarster
*/
@Test(groups = "jsAPI", dependsOnGroups = "baseAPI")
@ -20,7 +19,7 @@ import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
public class WxMpJsAPITest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
public void testJsapiTicket() throws WxErrorException {

View File

@ -13,7 +13,6 @@ import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import me.chanjar.weixin.mp.bean.WxMpMassNews;
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
@ -31,7 +30,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
public class WxMpMassMessageAPITest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException {

View File

@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@ -19,7 +18,7 @@ import java.util.Arrays;
public class WxMpMiscAPITest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@Test
public void testGetCallbackIP() throws WxErrorException {

View File

@ -2,14 +2,13 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
/**
* 测试短连接
*
*
* @author chanjarster
*/
@Test(groups = "shortURLAPI")
@ -17,7 +16,7 @@ import org.testng.annotations.Test;
public class WxMpShortUrlAPITest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
public void testShortUrl() throws WxErrorException {
String shortUrl = this.wxService.shortUrl("www.baidu.com");

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@ -19,7 +20,7 @@ import static org.testng.AssertJUnit.assertNotNull;
public class WxMpCardServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
private String cardId = "123";
private String code = "good";
private String openid = "abc";
@ -90,4 +91,4 @@ public class WxMpCardServiceImplTest {
System.out.println(result);
}
}
}

View File

@ -4,6 +4,7 @@ import java.text.ParseException;
import java.util.Date;
import java.util.List;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.commons.lang3.time.FastDateFormat;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
@ -32,7 +33,7 @@ public class WxMpDataCubeServiceImplTest {
.getInstance("yyyy-MM-dd");
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@DataProvider
public Object[][] oneDay() throws ParseException {

View File

@ -4,6 +4,7 @@ import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
@ -27,7 +28,7 @@ import java.util.Date;
public class WxMpKefuServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
public void testSendKefuMpNewsMessage() throws WxErrorException {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService

View File

@ -6,6 +6,7 @@ import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.material.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
@ -32,7 +33,7 @@ import static org.junit.Assert.*;
@Guice(modules = ApiTestModule.class)
public class WxMpMaterialServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
private Map<String, Map<String, Object>> mediaIds = new LinkedHashMap<>();
// 缩略图的id测试上传图文使用

View File

@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.api.impl;
import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert;
import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice;
@ -24,8 +25,8 @@ import me.chanjar.weixin.mp.api.ApiTestModule;
public class WxMpMenuServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@Test(dataProvider = "menu")
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {
System.out.println(wxMenu.toJson());
@ -82,12 +83,12 @@ public class WxMpMenuServiceImplTest {
Assert.assertNotNull(wxMenu);
System.out.println(wxMenu.toJson());
}
@Test(dependsOnMethods = { "testGetMenu"})
public void testDeleteMenu() throws WxErrorException {
this.wxService.getMenuService().menuDelete();
}
@DataProvider(name="menu")
public Object[][] getMenu() {
WxMenu menu = new WxMenu();
@ -95,45 +96,45 @@ public class WxMpMenuServiceImplTest {
button1.setType(WxConsts.BUTTON_CLICK);
button1.setName("今日歌曲");
button1.setKey("V1001_TODAY_MUSIC");
WxMenuButton button2 = new WxMenuButton();
button2.setType(WxConsts.BUTTON_CLICK);
button2.setName("歌手简介");
button2.setKey("V1001_TODAY_SINGER");
WxMenuButton button3 = new WxMenuButton();
button3.setName("菜单");
menu.getButtons().add(button1);
menu.getButtons().add(button2);
menu.getButtons().add(button3);
WxMenuButton button31 = new WxMenuButton();
button31.setType(WxConsts.BUTTON_VIEW);
button31.setName("搜索");
button31.setUrl("http://www.soso.com/");
WxMenuButton button32 = new WxMenuButton();
button32.setType(WxConsts.BUTTON_VIEW);
button32.setName("视频");
button32.setUrl("http://v.qq.com/");
WxMenuButton button33 = new WxMenuButton();
button33.setType(WxConsts.BUTTON_CLICK);
button33.setName("赞一下我们");
button33.setKey("V1001_GOOD");
button3.getSubButtons().add(button31);
button3.getSubButtons().add(button32);
button3.getSubButtons().add(button33);
return new Object[][] {
new Object[] {
menu
}
};
}
}

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest;
import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest;
@ -26,7 +27,7 @@ import java.io.File;
public class WxMpPayServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@Test
public void testGetPayInfo() throws Exception {
@ -65,7 +66,6 @@ public class WxMpPayServiceImplTest {
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#unifiedOrder(WxPayUnifiedOrderRequest)}.
* @throws WxErrorException
*/
@Test
public void testUnifiedOrder() throws WxErrorException {
@ -78,7 +78,6 @@ public class WxMpPayServiceImplTest {
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryOrder(String, String)} .
* @throws WxErrorException
*/
@Test
public final void testQueryOrder() throws WxErrorException {
@ -89,7 +88,6 @@ public class WxMpPayServiceImplTest {
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#closeOrder(String)} .
* @throws WxErrorException
*/
@Test
public final void testCloseOrder() throws WxErrorException {
@ -98,7 +96,6 @@ public class WxMpPayServiceImplTest {
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest, File)}.
* @throws WxErrorException
*/
@Test
public final void testEntPay() throws WxErrorException {
@ -109,7 +106,6 @@ public class WxMpPayServiceImplTest {
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String, File)}.
* @throws WxErrorException
*/
@Test
public final void testQueryEntPay() throws WxErrorException {

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.testng.Assert;
import org.testng.annotations.Guice;
@ -12,7 +13,7 @@ import java.io.File;
/**
* 测试用户相关的接口
*
*
* @author chanjarster
*/
@Test(groups = "qrCodeAPI")
@ -20,7 +21,7 @@ import java.io.File;
public class WxMpQrCodeServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
public void testQrCodeCreateTmpTicket() throws WxErrorException {
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);
@ -44,7 +45,7 @@ public class WxMpQrCodeServiceImplTest {
Assert.assertNotNull(file);
System.out.println(file.getAbsolutePath());
}
public void testQrCodePictureUrl() throws WxErrorException {
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateLastTicket(1);
String url = this.wxService.getQrcodeService().qrCodePictureUrl(ticket.getTicket());

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.api.WxConsts;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import org.testng.Assert;
import org.testng.annotations.Guice;
@ -13,7 +14,7 @@ import org.testng.annotations.Test;
public class WxMpServiceImplTest {
@Inject
private WxMpServiceImpl wxService;
private WxMpService wxService;
@Test
public void testCheckSignature() {

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
@ -23,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
@Guice(modules = ApiTestModule.class)
public class WxMpStoreServiceImplTest {
@Inject
private WxMpServiceImpl wxMpService;
private WxMpService wxMpService;
/**
* Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpStoreServiceImpl#add(me.chanjar.weixin.mp.bean.store.WxMpStoreBaseInfo)}.

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
@ -25,7 +26,7 @@ import java.util.List;
@Guice(modules = ApiTestModule.class)
public class WxMpTemplateMsgServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@Test(invocationCount = 10, threadPoolSize = 10)
public void testSendTemplateMsg() throws WxErrorException {

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api.impl;
import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
import org.testng.Assert;
@ -18,7 +19,7 @@ import java.util.List;
@Guice(modules = ApiTestModule.class)
public class WxMpUserBlacklistServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
@Test
public void testGetBlacklist() throws Exception {

View File

@ -4,6 +4,7 @@ package me.chanjar.weixin.mp.api.impl;
import java.util.ArrayList;
import java.util.List;
import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert;
import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice;
@ -29,7 +30,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpUserList;
public class WxMpUserServiceImplTest {
@Inject
private WxMpServiceImpl wxService;
private WxMpService wxService;
private WxXmlMpInMemoryConfigStorage configProvider;

View File

@ -2,6 +2,7 @@ package me.chanjar.weixin.mp.api.impl;
import java.util.List;
import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert;
import org.testng.annotations.Guice;
import org.testng.annotations.Test;
@ -22,7 +23,7 @@ import me.chanjar.weixin.mp.bean.tag.WxUserTag;
@Guice(modules = ApiTestModule.class)
public class WxMpUserTagServiceImplTest {
@Inject
protected WxMpServiceImpl wxService;
protected WxMpService wxService;
private Long tagId = 2L;