You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@cxf.apache.org by re...@apache.org on 2023/08/27 14:31:13 UTC
[cxf] branch 3.6.x-fixes updated: CXF-8871: Get rid of EasyMock in cxf-rt-rs-mp-client (#1392)
This is an automated email from the ASF dual-hosted git repository.
reta pushed a commit to branch 3.6.x-fixes
in repository https://gitbox.apache.org/repos/asf/cxf.git
The following commit(s) were added to refs/heads/3.6.x-fixes by this push:
new 5ba413ef9d CXF-8871: Get rid of EasyMock in cxf-rt-rs-mp-client (#1392)
5ba413ef9d is described below
commit 5ba413ef9da90b9c78ee365dff892db67aa50063
Author: Andriy Redko <dr...@gmail.com>
AuthorDate: Sun Aug 27 09:20:30 2023 -0400
CXF-8871: Get rid of EasyMock in cxf-rt-rs-mp-client (#1392)
(cherry picked from commit b6be915bb3e5c53c680c7e081154034475c046d8)
---
rt/rs/microprofile-client/pom.xml | 5 +-
.../microprofile/client/cdi/RestClientCdiTest.java | 83 +++++++++-------------
2 files changed, 38 insertions(+), 50 deletions(-)
diff --git a/rt/rs/microprofile-client/pom.xml b/rt/rs/microprofile-client/pom.xml
index 60a92e04cb..b19e648a4c 100644
--- a/rt/rs/microprofile-client/pom.xml
+++ b/rt/rs/microprofile-client/pom.xml
@@ -92,8 +92,9 @@
<scope>test</scope>
</dependency>
<dependency>
- <groupId>org.easymock</groupId>
- <artifactId>easymock</artifactId>
+ <groupId>org.mockito</groupId>
+ <artifactId>mockito-core</artifactId>
+ <version>${cxf.mockito.version}</version>
<scope>test</scope>
</dependency>
<dependency>
diff --git a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/cdi/RestClientCdiTest.java b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/cdi/RestClientCdiTest.java
index 1db34c0bc7..d4d54ce92b 100644
--- a/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/cdi/RestClientCdiTest.java
+++ b/rt/rs/microprofile-client/src/test/java/org/apache/cxf/microprofile/client/cdi/RestClientCdiTest.java
@@ -43,12 +43,14 @@ import org.apache.cxf.microprofile.client.mock.MockConfigProviderResolver;
import org.eclipse.microprofile.config.spi.ConfigProviderResolver;
import org.eclipse.microprofile.rest.client.tck.interfaces.InterfaceWithoutProvidersDefined;
-import org.easymock.EasyMock;
-import org.easymock.IMocksControl;
import org.junit.Test;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertTrue;
+import static org.mockito.Mockito.mock;
+import static org.mockito.Mockito.times;
+import static org.mockito.Mockito.verify;
+import static org.mockito.Mockito.when;
public class RestClientCdiTest {
@@ -63,15 +65,10 @@ public class RestClientCdiTest {
+ LowPriorityClientReqFilter.class.getName() + "/priority", "3");
((MockConfigProviderResolver)ConfigProviderResolver.instance()).setConfigValues(configValues);
- IMocksControl control = EasyMock.createNiceControl();
- BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
- mockedBeanMgr.isScope(Path.class);
- EasyMock.expectLastCall().andReturn(false);
- mockedBeanMgr.isScope(Produces.class);
- EasyMock.expectLastCall().andReturn(false);
- mockedBeanMgr.isScope(Consumes.class);
- EasyMock.expectLastCall().andReturn(false);
- control.replay();
+ BeanManager mockedBeanMgr = mock(BeanManager.class);
+ when(mockedBeanMgr.isScope(Path.class)).thenReturn(false);
+ when(mockedBeanMgr.isScope(Produces.class)).thenReturn(false);
+ when(mockedBeanMgr.isScope(Consumes.class)).thenReturn(false);
RestClientBean bean = new RestClientBean(InterfaceWithoutProvidersDefined.class, mockedBeanMgr);
List<Class<?>> registeredProviders = bean.getConfiguredProviders();
@@ -85,32 +82,26 @@ public class RestClientCdiTest {
assertEquals(3, (int) priorities.get(LowPriorityClientReqFilter.class));
assertEquals(10, (int) priorities.get(HighPriorityClientReqFilter.class));
assertEquals(Priorities.USER, (int) priorities.get(InvokedMethodClientRequestFilter.class));
-
- control.verify();
}
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testCreationalContextsReleasedOnClientClose() throws Exception {
- IMocksControl control = EasyMock.createStrictControl();
- BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
- CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
- Bean<?> mockedBean = control.createMock(Bean.class);
+ BeanManager mockedBeanMgr = mock(BeanManager.class);
+ CreationalContext<?> mockedCreationalCtx = mock(CreationalContext.class);
+ Bean<?> mockedBean = mock(Bean.class);
List<String> stringList = new ArrayList<>(Collections.singleton("abc"));
- EasyMock.expect(mockedBeanMgr.getBeans(List.class))
- .andReturn(Collections.singleton(mockedBean));
- EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean))
- .andReturn((CreationalContext) mockedCreationalCtx);
- EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
- .andReturn(stringList);
- EasyMock.expect(mockedBean.getScope())
- .andReturn((Class) ApplicationScoped.class);
- EasyMock.expect(mockedBeanMgr.isNormalScope(ApplicationScoped.class))
- .andReturn(false);
- mockedCreationalCtx.release();
- EasyMock.expectLastCall().once();
- control.replay();
+ when(mockedBeanMgr.getBeans(List.class))
+ .thenReturn(Collections.singleton(mockedBean));
+ when(mockedBeanMgr.createCreationalContext(mockedBean))
+ .thenReturn((CreationalContext) mockedCreationalCtx);
+ when(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
+ .thenReturn(stringList);
+ when(mockedBean.getScope())
+ .thenReturn((Class) ApplicationScoped.class);
+ when(mockedBeanMgr.isNormalScope(ApplicationScoped.class))
+ .thenReturn(false);
Bus bus = new ExtensionManagerBus();
bus.setExtension(mockedBeanMgr, BeanManager.class);
@@ -119,29 +110,27 @@ public class RestClientCdiTest {
assertEquals(stringList, i.getValue());
i.release();
- control.verify();
+ verify(mockedCreationalCtx, times(1)).release();
}
@Test
@SuppressWarnings({"unchecked", "rawtypes"})
public void testCreationalContextsNotReleasedOnClientCloseUsingNormalScope() throws Exception {
- IMocksControl control = EasyMock.createStrictControl();
- BeanManager mockedBeanMgr = control.createMock(BeanManager.class);
- CreationalContext<?> mockedCreationalCtx = control.createMock(CreationalContext.class);
- Bean<?> mockedBean = control.createMock(Bean.class);
+ BeanManager mockedBeanMgr = mock(BeanManager.class);
+ CreationalContext<?> mockedCreationalCtx = mock(CreationalContext.class);
+ Bean<?> mockedBean = mock(Bean.class);
List<String> stringList = new ArrayList<>(Collections.singleton("xyz"));
- EasyMock.expect(mockedBeanMgr.getBeans(List.class))
- .andReturn(Collections.singleton(mockedBean));
- EasyMock.expect(mockedBeanMgr.createCreationalContext(mockedBean))
- .andReturn((CreationalContext) mockedCreationalCtx);
- EasyMock.expect(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
- .andReturn(stringList);
- EasyMock.expect(mockedBean.getScope())
- .andReturn((Class) NormalScope.class);
- EasyMock.expect(mockedBeanMgr.isNormalScope(NormalScope.class))
- .andReturn(true);
- control.replay();
+ when(mockedBeanMgr.getBeans(List.class))
+ .thenReturn(Collections.singleton(mockedBean));
+ when(mockedBeanMgr.createCreationalContext(mockedBean))
+ .thenReturn((CreationalContext) mockedCreationalCtx);
+ when(mockedBeanMgr.getReference(mockedBean, List.class, mockedCreationalCtx))
+ .thenReturn(stringList);
+ when(mockedBean.getScope())
+ .thenReturn((Class) NormalScope.class);
+ when(mockedBeanMgr.isNormalScope(NormalScope.class))
+ .thenReturn(true);
Bus bus = new ExtensionManagerBus();
bus.setExtension(mockedBeanMgr, BeanManager.class);
@@ -149,7 +138,5 @@ public class RestClientCdiTest {
Instance<List> i = CDIUtils.getInstanceFromCDI(List.class, bus);
i.release();
-
- control.verify();
}
}
\ No newline at end of file