尽量使用接口引用 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")) { .getSystemResourceAsStream("test-config.xml")) {
WxXmlMpInMemoryConfigStorage config = this WxXmlMpInMemoryConfigStorage config = this
.fromXml(WxXmlMpInMemoryConfigStorage.class, is1); .fromXml(WxXmlMpInMemoryConfigStorage.class, is1);
WxMpServiceImpl wxService = new WxMpServiceImpl(); WxMpService wxService = new WxMpServiceImpl();
wxService.setWxMpConfigStorage(config); wxService.setWxMpConfigStorage(config);
binder.bind(WxMpServiceImpl.class).toInstance(wxService); binder.bind(WxMpService.class).toInstance(wxService);
binder.bind(WxMpConfigStorage.class).toInstance(config); binder.bind(WxMpConfigStorage.class).toInstance(config);
} catch (IOException e) { } catch (IOException e) {
e.printStackTrace(); e.printStackTrace();

View File

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

View File

@ -8,7 +8,6 @@ import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.common.util.crypto.SHA1; import me.chanjar.weixin.common.util.crypto.SHA1;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
/** /**
* 测试jsapi ticket接口 * 测试jsapi ticket接口
@ -20,7 +19,7 @@ import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
public class WxMpJsAPITest { public class WxMpJsAPITest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
public void testJsapiTicket() throws WxErrorException { 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.api.WxConsts;
import me.chanjar.weixin.common.bean.result.WxMediaUploadResult; import me.chanjar.weixin.common.bean.result.WxMediaUploadResult;
import me.chanjar.weixin.common.exception.WxErrorException; 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.WxMpMassNews;
import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage; import me.chanjar.weixin.mp.bean.WxMpMassOpenIdsMessage;
import me.chanjar.weixin.mp.bean.WxMpMassTagMessage; import me.chanjar.weixin.mp.bean.WxMpMassTagMessage;
@ -31,7 +30,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpMassUploadResult;
public class WxMpMassMessageAPITest { public class WxMpMassMessageAPITest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
@Test @Test
public void testTextMassOpenIdsMessageSend() throws WxErrorException { public void testTextMassOpenIdsMessageSend() throws WxErrorException {

View File

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

View File

@ -2,7 +2,6 @@ package me.chanjar.weixin.mp.api;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.impl.WxMpServiceImpl;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -17,7 +16,7 @@ import org.testng.annotations.Test;
public class WxMpShortUrlAPITest { public class WxMpShortUrlAPITest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
public void testShortUrl() throws WxErrorException { public void testShortUrl() throws WxErrorException {
String shortUrl = this.wxService.shortUrl("www.baidu.com"); 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 com.google.inject.Inject;
import me.chanjar.weixin.common.bean.WxCardApiSignature; import me.chanjar.weixin.common.bean.WxCardApiSignature;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpCardResult; import me.chanjar.weixin.mp.bean.result.WxMpCardResult;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
import org.testng.annotations.Test; import org.testng.annotations.Test;
@ -19,7 +20,7 @@ import static org.testng.AssertJUnit.assertNotNull;
public class WxMpCardServiceImplTest { public class WxMpCardServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
private String cardId = "123"; private String cardId = "123";
private String code = "good"; private String code = "good";
private String openid = "abc"; private String openid = "abc";

View File

@ -4,6 +4,7 @@ import java.text.ParseException;
import java.util.Date; import java.util.Date;
import java.util.List; import java.util.List;
import me.chanjar.weixin.mp.api.WxMpService;
import org.apache.commons.lang3.time.FastDateFormat; import org.apache.commons.lang3.time.FastDateFormat;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
@ -32,7 +33,7 @@ public class WxMpDataCubeServiceImplTest {
.getInstance("yyyy-MM-dd"); .getInstance("yyyy-MM-dd");
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
@DataProvider @DataProvider
public Object[][] oneDay() throws ParseException { 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.api.WxConsts;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; 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.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage; import me.chanjar.weixin.mp.bean.kefu.WxMpKefuMessage;
import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest; import me.chanjar.weixin.mp.bean.kefu.request.WxMpKfAccountRequest;
@ -27,7 +28,7 @@ import java.util.Date;
public class WxMpKefuServiceImplTest { public class WxMpKefuServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
public void testSendKefuMpNewsMessage() throws WxErrorException { public void testSendKefuMpNewsMessage() throws WxErrorException {
WxXmlMpInMemoryConfigStorage configStorage = (WxXmlMpInMemoryConfigStorage) this.wxService 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.exception.WxErrorException;
import me.chanjar.weixin.common.util.fs.FileUtils; import me.chanjar.weixin.common.util.fs.FileUtils;
import me.chanjar.weixin.mp.api.ApiTestModule; 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.WxMpMaterial;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate; import me.chanjar.weixin.mp.bean.material.WxMpMaterialArticleUpdate;
import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews; import me.chanjar.weixin.mp.bean.material.WxMpMaterialNews;
@ -32,7 +33,7 @@ import static org.junit.Assert.*;
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class WxMpMaterialServiceImplTest { public class WxMpMaterialServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
private Map<String, Map<String, Object>> mediaIds = new LinkedHashMap<>(); private Map<String, Map<String, Object>> mediaIds = new LinkedHashMap<>();
// 缩略图的id测试上传图文使用 // 缩略图的id测试上传图文使用

View File

@ -1,5 +1,6 @@
package me.chanjar.weixin.mp.api.impl; package me.chanjar.weixin.mp.api.impl;
import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.DataProvider; import org.testng.annotations.DataProvider;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
@ -24,7 +25,7 @@ import me.chanjar.weixin.mp.api.ApiTestModule;
public class WxMpMenuServiceImplTest { public class WxMpMenuServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
@Test(dataProvider = "menu") @Test(dataProvider = "menu")
public void testCreateMenu(WxMenu wxMenu) throws WxErrorException { public void testCreateMenu(WxMenu wxMenu) throws WxErrorException {

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; 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.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest; import me.chanjar.weixin.mp.bean.pay.request.WxEntPayRequest;
import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest; import me.chanjar.weixin.mp.bean.pay.request.WxPayRefundRequest;
@ -26,7 +27,7 @@ import java.io.File;
public class WxMpPayServiceImplTest { public class WxMpPayServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
@Test @Test
public void testGetPayInfo() throws Exception { 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)}. * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#unifiedOrder(WxPayUnifiedOrderRequest)}.
* @throws WxErrorException
*/ */
@Test @Test
public void testUnifiedOrder() throws WxErrorException { 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)} . * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryOrder(String, String)} .
* @throws WxErrorException
*/ */
@Test @Test
public final void testQueryOrder() throws WxErrorException { 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)} . * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#closeOrder(String)} .
* @throws WxErrorException
*/ */
@Test @Test
public final void testCloseOrder() throws WxErrorException { 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)}. * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#entPay(WxEntPayRequest, File)}.
* @throws WxErrorException
*/ */
@Test @Test
public final void testEntPay() throws WxErrorException { 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)}. * Test method for {@link me.chanjar.weixin.mp.api.impl.WxMpPayServiceImpl#queryEntPay(String, File)}.
* @throws WxErrorException
*/ */
@Test @Test
public final void testQueryEntPay() throws WxErrorException { 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 com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; import me.chanjar.weixin.mp.api.ApiTestModule;
import me.chanjar.weixin.mp.api.WxMpService;
import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket; import me.chanjar.weixin.mp.bean.result.WxMpQrCodeTicket;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
@ -20,7 +21,7 @@ import java.io.File;
public class WxMpQrCodeServiceImplTest { public class WxMpQrCodeServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
public void testQrCodeCreateTmpTicket() throws WxErrorException { public void testQrCodeCreateTmpTicket() throws WxErrorException {
WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null); WxMpQrCodeTicket ticket = this.wxService.getQrcodeService().qrCodeCreateTmpTicket(1, null);

View File

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

View File

@ -3,6 +3,7 @@ package me.chanjar.weixin.mp.api.impl;
import com.google.inject.Inject; import com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; 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.WxMpStoreBaseInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo; import me.chanjar.weixin.mp.bean.store.WxMpStoreInfo;
import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult; import me.chanjar.weixin.mp.bean.store.WxMpStoreListResult;
@ -23,7 +24,7 @@ import static org.junit.Assert.assertNotNull;
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class WxMpStoreServiceImplTest { public class WxMpStoreServiceImplTest {
@Inject @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)}. * 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 com.google.inject.Inject;
import me.chanjar.weixin.common.exception.WxErrorException; import me.chanjar.weixin.common.exception.WxErrorException;
import me.chanjar.weixin.mp.api.ApiTestModule; 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.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.template.WxMpTemplate; import me.chanjar.weixin.mp.bean.template.WxMpTemplate;
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData; import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
@ -25,7 +26,7 @@ import java.util.List;
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class WxMpTemplateMsgServiceImplTest { public class WxMpTemplateMsgServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
@Test(invocationCount = 10, threadPoolSize = 10) @Test(invocationCount = 10, threadPoolSize = 10)
public void testSendTemplateMsg() throws WxErrorException { public void testSendTemplateMsg() throws WxErrorException {

View File

@ -1,6 +1,7 @@
package me.chanjar.weixin.mp.api.impl; package me.chanjar.weixin.mp.api.impl;
import me.chanjar.weixin.mp.api.ApiTestModule; 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.api.WxXmlMpInMemoryConfigStorage;
import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult; import me.chanjar.weixin.mp.bean.result.WxMpUserBlacklistGetResult;
import org.testng.Assert; import org.testng.Assert;
@ -18,7 +19,7 @@ import java.util.List;
@Guice(modules = ApiTestModule.class) @Guice(modules = ApiTestModule.class)
public class WxMpUserBlacklistServiceImplTest { public class WxMpUserBlacklistServiceImplTest {
@Inject @Inject
protected WxMpServiceImpl wxService; protected WxMpService wxService;
@Test @Test
public void testGetBlacklist() throws Exception { 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.ArrayList;
import java.util.List; import java.util.List;
import me.chanjar.weixin.mp.api.WxMpService;
import org.testng.Assert; import org.testng.Assert;
import org.testng.annotations.BeforeTest; import org.testng.annotations.BeforeTest;
import org.testng.annotations.Guice; import org.testng.annotations.Guice;
@ -29,7 +30,7 @@ import me.chanjar.weixin.mp.bean.result.WxMpUserList;
public class WxMpUserServiceImplTest { public class WxMpUserServiceImplTest {
@Inject @Inject
private WxMpServiceImpl wxService; private WxMpService wxService;
private WxXmlMpInMemoryConfigStorage configProvider; private WxXmlMpInMemoryConfigStorage configProvider;

View File

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