Upgrade Java 17 in policy-drools-apps
[policy/drools-applications.git] / controlloop / common / eventmanager / src / test / java / org / onap / policy / controlloop / eventmanager / LockDataTest.java
index 7b02131..609de57 100644 (file)
@@ -3,6 +3,7 @@
  * ONAP
  * ================================================================================
  * Copyright (C) 2020-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2023 Nordix Foundation.
  * ================================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
 package org.onap.policy.controlloop.eventmanager;
 
 import static org.assertj.core.api.Assertions.assertThatCode;
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertNotSame;
-import static org.junit.Assert.assertSame;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertNotSame;
+import static org.junit.jupiter.api.Assertions.assertSame;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 import static org.mockito.ArgumentMatchers.any;
 import static org.mockito.Mockito.doThrow;
+import static org.mockito.Mockito.mock;
 import static org.mockito.Mockito.never;
 import static org.mockito.Mockito.verify;
 
-import java.time.Instant;
 import java.util.UUID;
-import java.util.concurrent.CompletableFuture;
 import java.util.function.Consumer;
-import org.junit.Before;
-import org.junit.Test;
-import org.junit.runner.RunWith;
-import org.mockito.Mock;
-import org.mockito.junit.MockitoJUnitRunner;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
 import org.onap.policy.controlloop.ControlLoopOperation;
 import org.onap.policy.controlloop.actorserviceprovider.OperationOutcome;
 import org.onap.policy.controlloop.actorserviceprovider.OperationResult;
 import org.onap.policy.drools.core.lock.Lock;
 
-@RunWith(MockitoJUnitRunner.class)
-public class LockDataTest {
+class LockDataTest {
 
     private static final String ENTITY = "my-entity";
     private static final UUID REQ_ID = UUID.randomUUID();
 
-    @Mock
-    private Lock lock;
-    @Mock
-    private Consumer<OperationOutcome> callback1;
-    @Mock
-    private Consumer<OperationOutcome> callback2;
-    @Mock
-    private Consumer<OperationOutcome> callback3;
+    private final Lock lock = mock(Lock.class);
+    private final Consumer<OperationOutcome> callback1 = mock();
+    private final Consumer<OperationOutcome> callback2 = mock();
+    private final Consumer<OperationOutcome> callback3 = mock();
 
     private LockData data;
 
     /**
      * Sets up.
      */
-    @Before
+    @BeforeEach
     public void setUp() {
         data = new LockData(ENTITY, REQ_ID);
     }
 
     @Test
-    public void testGetFuture() {
-        CompletableFuture<OperationOutcome> future = data.getFuture();
+    void testGetFuture() {
+        var future = data.getFuture();
         assertNotNull(future);
         assertFalse(future.isDone());
     }
 
     @Test
-    public void testAddUnavailableCallback() {
+    void testAddUnavailableCallback() {
         data.addUnavailableCallback(callback1);
         data.addUnavailableCallback(callback2);
 
@@ -96,7 +88,7 @@ public class LockDataTest {
      * Tests addUnavailableCallback() when the lock never becomes available.
      */
     @Test
-    public void testAddUnavailableCallbackNeverAvailable() {
+    void testAddUnavailableCallbackNeverAvailable() {
         data.addUnavailableCallback(callback1);
         data.addUnavailableCallback(callback2);
 
@@ -109,7 +101,7 @@ public class LockDataTest {
     }
 
     @Test
-    public void testFree() {
+    void testFree() {
         // no lock yet
         assertThatCode(() -> data.free()).doesNotThrowAnyException();
 
@@ -120,27 +112,27 @@ public class LockDataTest {
     }
 
     @Test
-    public void testLockAvailable() throws Exception {
+    void testLockAvailable() throws Exception {
         data.addUnavailableCallback(callback1);
         data.addUnavailableCallback(callback2);
 
-        CompletableFuture<OperationOutcome> future = data.getFuture();
+        var future = data.getFuture();
         data.lockAvailable(lock);
 
         assertSame(future, data.getFuture());
 
         assertTrue(future.isDone());
-        OperationOutcome outcome = future.get();
+        var outcome = future.get();
         assertEquals(ActorConstants.LOCK_ACTOR, outcome.getActor());
         assertEquals(ActorConstants.LOCK_OPERATION, outcome.getOperation());
         assertEquals(ENTITY, outcome.getTarget());
         assertEquals(OperationResult.SUCCESS, outcome.getResult());
         assertEquals(ControlLoopOperation.SUCCESS_MSG, outcome.getMessage());
 
-        Instant start = outcome.getStart();
+        var start = outcome.getStart();
         assertNotNull(start);
 
-        Instant end = outcome.getEnd();
+        var end = outcome.getEnd();
         assertNotNull(end);
         assertTrue(start.compareTo(end) <= 0);
 
@@ -149,7 +141,7 @@ public class LockDataTest {
     }
 
     @Test
-    public void testLockUnavailable() throws Exception {
+    void testLockUnavailable() throws Exception {
         data.addUnavailableCallback(callback1);
         data.addUnavailableCallback(callback2);
         data.addUnavailableCallback(callback3);
@@ -157,17 +149,17 @@ public class LockDataTest {
         // arrange for callback2 to throw an exception
         doThrow(new IllegalStateException("expected exception")).when(callback2).accept(any());
 
-        CompletableFuture<OperationOutcome> future = data.getFuture();
+        var future = data.getFuture();
         assertNotNull(future);
         data.lockUnavailable(lock);
 
-        CompletableFuture<OperationOutcome> future2 = data.getFuture();
+        var future2 = data.getFuture();
         assertNotNull(future2);
 
         assertNotSame(future, future2);
 
         assertTrue(future.isDone());
-        OperationOutcome outcome = future.get();
+        var outcome = future.get();
 
         assertTrue(future2.isDone());
         assertSame(outcome, future2.get());
@@ -178,10 +170,10 @@ public class LockDataTest {
         assertEquals(OperationResult.FAILURE, outcome.getResult());
         assertEquals(ControlLoopOperation.FAILED_MSG, outcome.getMessage());
 
-        Instant start = outcome.getStart();
+        var start = outcome.getStart();
         assertNotNull(start);
 
-        Instant end = outcome.getEnd();
+        var end = outcome.getEnd();
         assertNotNull(end);
         assertTrue(start.compareTo(end) <= 0);