Ditch powermock from util.servicehelper 69/98269/2
authorRobert Varga <robert.varga@pantheon.tech>
Tue, 2 Nov 2021 13:30:16 +0000 (14:30 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Tue, 2 Nov 2021 16:46:38 +0000 (17:46 +0100)
We have static mocking here, rework it in terms of Mockito.

Change-Id: I2ee329b67fe0f4261337b009d4d36c84e77ecb71
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
utils/servicehelper/pom.xml
utils/servicehelper/src/test/java/org/opendaylight/ovsdb/utils/servicehelper/ServiceHelperTest.java
utils/servicehelper/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker [new file with mode: 0644]

index d0df8284008009988f0dd26ffe19b027829d7ae6..094b37a07aff0fcffabb3192a83f0d9dd4c11515 100644 (file)
@@ -33,14 +33,6 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <groupId>org.slf4j</groupId>
       <artifactId>slf4j-api</artifactId>
     </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-api-mockito2</artifactId>
-    </dependency>
-    <dependency>
-      <groupId>org.powermock</groupId>
-      <artifactId>powermock-module-junit4</artifactId>
-    </dependency>
     <dependency>
       <groupId>org.springframework.osgi</groupId>
       <artifactId>spring-osgi-mock</artifactId>
index b5cc7b07590b1c47f6f30326ea1a557014744c57..7fb78f1807d6539642befde43f35aeb3e7c394ba 100644 (file)
@@ -9,40 +9,30 @@ package org.opendaylight.ovsdb.utils.servicehelper;
 
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
-import static org.mockito.Matchers.any;
+import static org.mockito.Mockito.mockStatic;
 
-import org.junit.Ignore;
 import org.junit.Test;
 import org.junit.runner.RunWith;
+import org.mockito.junit.MockitoJUnitRunner;
 import org.osgi.framework.FrameworkUtil;
-import org.powermock.api.mockito.PowerMockito;
-import org.powermock.core.classloader.annotations.PrepareForTest;
-import org.powermock.modules.junit4.PowerMockRunner;
 import org.springframework.osgi.mock.MockBundle;
 
 /**
  * JUnit test for {@link ServiceHelper}.
  */
-@Ignore
-@RunWith(PowerMockRunner.class)
-@PrepareForTest(FrameworkUtil.class)
+@RunWith(MockitoJUnitRunner.StrictStubs.class)
 public class ServiceHelperTest {
-    @Test
     /**
-     * Test method for
-     * {@link ServiceHelper#getGlobalInstance(Class, Object)}
+     * Test method for {@link ServiceHelper#getGlobalInstance(Class, Object)}.
      */
+    @Test
     public void getGlobalInstanceTest() {
-        PowerMockito.mockStatic(FrameworkUtil.class);
-
-        PowerMockito.when(FrameworkUtil.getBundle(any(Class.class)))
-                .thenReturn(null);
-        Object object = ServiceHelper.getGlobalInstance(Test.class, this);
-        assertNull("Service should be null", object);
+        try (var frameworkUtil = mockStatic(FrameworkUtil.class)) {
+            final var mockBundle = new MockBundle();
+            frameworkUtil.when(() -> FrameworkUtil.getBundle(ServiceHelperTest.class)).thenReturn(null, mockBundle);
 
-        PowerMockito.when(FrameworkUtil.getBundle(any(Class.class)))
-                .thenReturn(new MockBundle());
-        object = ServiceHelper.getGlobalInstance(Test.class, this);
-        assertNotNull("Service should not be null", object);
+            assertNull(ServiceHelper.getGlobalInstance(Test.class, this));
+            assertNotNull(ServiceHelper.getGlobalInstance(Test.class, this));
+        }
     }
 }
diff --git a/utils/servicehelper/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker b/utils/servicehelper/src/test/resources/mockito-extensions/org.mockito.plugins.MockMaker
new file mode 100644 (file)
index 0000000..1f0955d
--- /dev/null
@@ -0,0 +1 @@
+mock-maker-inline