Convert OSGiEncryptionServiceConfiguratorTest 15/109915/1
authorRobert Varga <robert.varga@pantheon.tech>
Mon, 22 Jan 2024 18:23:55 +0000 (19:23 +0100)
committerRobert Varga <robert.varga@pantheon.tech>
Mon, 22 Jan 2024 18:26:41 +0000 (19:26 +0100)
This is a simple test and we can ditch use of Hamcrest by taking
advantage of assertInstanceOf().

Change-Id: I7ebfcecda1d687fc6f51d9fc730a4a5734450c01
Signed-off-by: Robert Varga <robert.varga@pantheon.tech>
aaa-encrypt-service/impl/pom.xml
aaa-encrypt-service/impl/src/test/java/org/opendaylight/aaa/encrypt/impl/OSGiEncryptionServiceConfiguratorTest.java

index 8ac6ef150282938751cd61495370ae24c250e0ad..817607f89d7317255fff8b40356db266375f9f0b 100644 (file)
@@ -62,6 +62,11 @@ and is available at http://www.eclipse.org/legal/epl-v10.html
       <artifactId>org.osgi.service.component.annotations</artifactId>
     </dependency>
 
+    <dependency>
+      <groupId>org.opendaylight.yangtools</groupId>
+      <artifactId>mockito-configuration</artifactId>
+      <scope>test</scope>
+    </dependency>
     <dependency>
       <groupId>org.opendaylight.yangtools</groupId>
       <artifactId>util</artifactId>
index e2ae73810530029a2748d93e868ce79478cbd158..c86e2078910d9c6f94d98e51105cd441f5fc4008 100644 (file)
@@ -7,12 +7,11 @@
  */
 package org.opendaylight.aaa.encrypt.impl;
 
-import static org.hamcrest.CoreMatchers.instanceOf;
-import static org.hamcrest.MatcherAssert.assertThat;
-import static org.junit.Assert.assertArrayEquals;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertSame;
+import static org.junit.jupiter.api.Assertions.assertArrayEquals;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertSame;
 import static org.mockito.ArgumentMatchers.eq;
 import static org.mockito.Mockito.doNothing;
 import static org.mockito.Mockito.doReturn;
@@ -21,13 +20,13 @@ import java.util.Base64;
 import java.util.Dictionary;
 import java.util.Optional;
 import org.eclipse.jdt.annotation.NonNull;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
+import org.junit.jupiter.api.extension.ExtendWith;
 import org.mockito.ArgumentCaptor;
 import org.mockito.Captor;
 import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.mockito.junit.jupiter.MockitoExtension;
 import org.opendaylight.mdsal.binding.api.DataBroker;
 import org.opendaylight.mdsal.binding.api.DataListener;
 import org.opendaylight.mdsal.binding.api.DataTreeIdentifier;
@@ -42,11 +41,10 @@ import org.opendaylight.yangtools.yang.binding.InstanceIdentifier;
 import org.osgi.service.component.ComponentFactory;
 import org.osgi.service.component.ComponentInstance;
 
-@RunWith(MockitoJUnitRunner.StrictStubs.class)
-public class OSGiEncryptionServiceConfiguratorTest {
+@ExtendWith(MockitoExtension.class)
+class OSGiEncryptionServiceConfiguratorTest {
     private static final @NonNull InstanceIdentifier<AaaEncryptServiceConfig> IID =
         InstanceIdentifier.create(AaaEncryptServiceConfig.class);
-
     @Mock
     private DataBroker dataBroker;
     @Mock
@@ -68,8 +66,8 @@ public class OSGiEncryptionServiceConfiguratorTest {
 
     private OSGiEncryptionServiceConfigurator configurator;
 
-    @Before
-    public void before() {
+    @BeforeEach
+    void before() {
         doReturn(registration).when(dataBroker).registerDataListener(treeIdCaptor.capture(), listenerCaptor.capture());
 
         configurator = new OSGiEncryptionServiceConfigurator(dataBroker, factory);
@@ -79,13 +77,13 @@ public class OSGiEncryptionServiceConfiguratorTest {
     }
 
     @Test
-    public void testImmediateDeactivate() {
+    void testImmediateDeactivate() {
         doNothing().when(registration).close();
         configurator.deactivate();
     }
 
     @Test
-    public void testEmptyDatastore() {
+    void testEmptyDatastore() {
         // Config datastore write is expected: capture what gets written
         doReturn(transaction).when(dataBroker).newReadWriteTransaction();
         doReturn(FluentFutures.immediateFluentFuture(Optional.empty())).when(transaction)
@@ -118,10 +116,7 @@ public class OSGiEncryptionServiceConfiguratorTest {
         final var props = propertiesCaptor.getValue();
         assertNotNull(props);
         assertEquals(1, props.size());
-        final var configObj = props.elements().nextElement();
-        assertNotNull(configObj);
-        assertThat(configObj, instanceOf(EncryptServiceConfig.class));
-        final var serviceConfig = (EncryptServiceConfig) configObj;
+        final var serviceConfig = assertInstanceOf(EncryptServiceConfig.class, props.elements().nextElement());
         assertArrayEquals(salt, serviceConfig.getEncryptSalt());
         assertEquals(key, serviceConfig.getEncryptKey());