|
| 1 | +package me.chanjar.weixin.mp.api.impl; |
| 2 | + |
| 3 | +import me.chanjar.weixin.common.error.WxErrorException; |
| 4 | +import me.chanjar.weixin.mp.api.WxMpOcrService; |
| 5 | +import me.chanjar.weixin.mp.api.WxMpService; |
| 6 | +import me.chanjar.weixin.mp.api.test.ApiTestModule; |
| 7 | +import me.chanjar.weixin.mp.bean.ocr.WxMpOcrIdCardResult; |
| 8 | +import org.testng.annotations.BeforeTest; |
| 9 | +import org.testng.annotations.Guice; |
| 10 | +import org.testng.annotations.Test; |
| 11 | + |
| 12 | +import javax.inject.Inject; |
| 13 | + |
| 14 | +import static org.assertj.core.api.Assertions.assertThat; |
| 15 | +import static org.mockito.Matchers.anyString; |
| 16 | +import static org.mockito.Mockito.mock; |
| 17 | +import static org.mockito.Mockito.when; |
| 18 | + |
| 19 | +/** |
| 20 | + * 测试类. |
| 21 | + * |
| 22 | + * @author <a href="https://github.com/binarywang">Binary Wang</a> |
| 23 | + * @date 2019-06-22 |
| 24 | + */ |
| 25 | +@Test |
| 26 | +@Guice(modules = ApiTestModule.class) |
| 27 | +public class WxMpOcrServiceImplTest { |
| 28 | + @Inject |
| 29 | + private WxMpService mpService; |
| 30 | + |
| 31 | + @Test |
| 32 | + public void testIdCard() throws WxErrorException { |
| 33 | + final WxMpOcrIdCardResult result = this.mpService.getOcrService().idCard(WxMpOcrService.ImageType.PHOTO, |
| 34 | + "http://www.baidu.com"); |
| 35 | + assertThat(result).isNotNull(); |
| 36 | + System.out.println(result); |
| 37 | + } |
| 38 | + |
| 39 | + public static class MockTest { |
| 40 | + private WxMpService wxService = mock(WxMpService.class); |
| 41 | + |
| 42 | + @Test |
| 43 | + public void testIdCard() throws Exception { |
| 44 | + String returnJson = "{\"type\":\"Back\",\"name\":\"张三\",\"id\":\"110101199909090099\",\"valid_date\":\"20110101-20210201\"}"; |
| 45 | + |
| 46 | + when(wxService.get(anyString(), anyString())).thenReturn(returnJson); |
| 47 | + final WxMpOcrServiceImpl wxMpOcrService = new WxMpOcrServiceImpl(wxService); |
| 48 | + |
| 49 | + final WxMpOcrIdCardResult result = wxMpOcrService.idCard(WxMpOcrService.ImageType.PHOTO, "abc"); |
| 50 | + assertThat(result).isNotNull(); |
| 51 | + System.out.println(result); |
| 52 | + } |
| 53 | + } |
| 54 | +} |
0 commit comments