From cd15fd756738b5faff0e4ac3e392eded3c1ce82b Mon Sep 17 00:00:00 2001 From: Copilot <198982749+Copilot@users.noreply.github.com> Date: Tue, 10 Mar 2026 15:38:33 +0800 Subject: [PATCH] =?UTF-8?q?:art:=20=E9=99=8D=E7=BA=A7=20Mockito=20?= =?UTF-8?q?=E8=87=B3=204.11.0=20=E4=BB=A5=E5=85=BC=E5=AE=B9=20Java=208?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../impl/WxCpTpCustomizedServiceImplTest.java | 15 ++++++++++++++- .../impl/WxCpTpEditionServiceImplTest.java | 16 +++++++++++++++- .../impl/WxCpTpLicenseServiceImplTest.java | 16 +++++++++++++++- .../service/impl/WxCpTpOrderServiceImplTest.java | 16 +++++++++++++++- .../service/impl/WxCpTpTagServiceImplTest.java | 15 ++++++++++++++- 6 files changed, 74 insertions(+), 6 deletions(-) diff --git a/pom.xml b/pom.xml index 8a08484f0..71129a0d8 100644 --- a/pom.xml +++ b/pom.xml @@ -258,7 +258,7 @@ org.mockito mockito-core - 5.14.2 + 4.11.0 test diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpCustomizedServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpCustomizedServiceImplTest.java index 23babff41..cf0edf1c7 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpCustomizedServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpCustomizedServiceImplTest.java @@ -8,6 +8,7 @@ import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; import me.chanjar.weixin.cp.tp.service.WxCpTpCustomizedService; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -34,17 +35,29 @@ public class WxCpTpCustomizedServiceImplTest { private WxCpTpCustomizedService wxCpTpCustomizedService; + private AutoCloseable mockitoAnnotations; + /** * Sets up. */ @BeforeClass public void setUp() { - MockitoAnnotations.initMocks(this); + mockitoAnnotations = MockitoAnnotations.openMocks(this); configStorage = new WxCpTpDefaultConfigImpl(); when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); wxCpTpCustomizedService = new WxCpTpCustomizedServiceImpl(wxCpTpService); } + /** + * Tear down. + * + * @throws Exception the exception + */ + @AfterClass + public void tearDown() throws Exception { + mockitoAnnotations.close(); + } + /** * 测试获取应用模板列表 * diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpEditionServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpEditionServiceImplTest.java index 5746c1e91..6290c43c9 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpEditionServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpEditionServiceImplTest.java @@ -7,6 +7,7 @@ import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; import me.chanjar.weixin.cp.tp.service.WxCpTpEditionService; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -29,18 +30,31 @@ public class WxCpTpEditionServiceImplTest { private WxCpTpEditionService wxCpTpEditionService; + private AutoCloseable mockitoAnnotations; + /** * Sets up. */ @BeforeClass public void setUp() { - MockitoAnnotations.openMocks(this); + mockitoAnnotations = MockitoAnnotations.openMocks(this); configStorage = new WxCpTpDefaultConfigImpl(); when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); wxCpTpEditionService = new WxCpTpEditionServiceImpl(wxCpTpService); } + /** + * Tear down. + * + * @throws Exception the exception + */ + @AfterClass + public void tearDown() throws Exception { + mockitoAnnotations.close(); + } + + /** * 延长试用期 * diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java index 3398d0806..692f56fe2 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpLicenseServiceImplTest.java @@ -10,6 +10,7 @@ import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; import me.chanjar.weixin.cp.tp.service.WxCpTpLicenseService; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -36,18 +37,31 @@ public class WxCpTpLicenseServiceImplTest { private WxCpTpLicenseService wxCpTpLicenseService; + private AutoCloseable mockitoAnnotations; + /** * Sets up. */ @BeforeClass public void setUp() { - MockitoAnnotations.openMocks(this); + mockitoAnnotations = MockitoAnnotations.openMocks(this); configStorage = new WxCpTpDefaultConfigImpl(); when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); wxCpTpLicenseService = new WxCpTpLicenseServiceImpl(wxCpTpService); } + /** + * Tear down. + * + * @throws Exception the exception + */ + @AfterClass + public void tearDown() throws Exception { + mockitoAnnotations.close(); + } + + /** * Test crate new order. * diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpOrderServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpOrderServiceImplTest.java index db504fe24..04582b4f0 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpOrderServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpOrderServiceImplTest.java @@ -9,6 +9,7 @@ import me.chanjar.weixin.cp.tp.service.WxCpTpOrderService; import org.apache.commons.lang3.time.DateUtils; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; @@ -35,18 +36,31 @@ public class WxCpTpOrderServiceImplTest { private WxCpTpOrderService wxCpTpOrderService; + private AutoCloseable mockitoAnnotations; + /** * Sets up. */ @BeforeClass public void setUp() { - MockitoAnnotations.openMocks(this); + mockitoAnnotations = MockitoAnnotations.openMocks(this); configStorage = new WxCpTpDefaultConfigImpl(); when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); wxCpTpOrderService = new WxCpTpOrderServiceImpl(wxCpTpService); } + /** + * Tear down. + * + * @throws Exception the exception + */ + @AfterClass + public void tearDown() throws Exception { + mockitoAnnotations.close(); + } + + /** * 获取订单详情 * diff --git a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpTagServiceImplTest.java b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpTagServiceImplTest.java index 2939b8a8b..b446bda58 100644 --- a/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpTagServiceImplTest.java +++ b/weixin-java-cp/src/test/java/me/chanjar/weixin/cp/tp/service/impl/WxCpTpTagServiceImplTest.java @@ -9,6 +9,7 @@ import me.chanjar.weixin.cp.config.impl.WxCpTpDefaultConfigImpl; import me.chanjar.weixin.cp.tp.service.WxCpTpTagService; import org.mockito.Mock; import org.mockito.MockitoAnnotations; +import org.testng.annotations.AfterClass; import org.testng.annotations.BeforeClass; import org.testng.annotations.Test; import org.testng.collections.CollectionUtils; @@ -36,17 +37,29 @@ public class WxCpTpTagServiceImplTest { private WxCpTpTagService wxCpTpTagService; + private AutoCloseable mockitoAnnotations; + /** * Sets up. */ @BeforeClass public void setUp() { - MockitoAnnotations.openMocks(this); + mockitoAnnotations = MockitoAnnotations.openMocks(this); configStorage = new WxCpTpDefaultConfigImpl(); when(wxCpTpService.getWxCpTpConfigStorage()).thenReturn(configStorage); wxCpTpTagService = new WxCpTpTagServiceImpl(wxCpTpService); } + /** + * Tear down. + * + * @throws Exception the exception + */ + @AfterClass + public void tearDown() throws Exception { + mockitoAnnotations.close(); + } + /** * Test create. *