* ONAP
* ================================================================================
* Copyright (C) 2019-2021 AT&T Intellectual Property. All rights reserved.
+ * Modifications Copyright (C) 2024 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.drools.system.internal;
-import static org.junit.Assert.assertFalse;
-import static org.junit.Assert.assertNotNull;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertFalse;
+import static org.junit.jupiter.api.Assertions.assertInstanceOf;
+import static org.junit.jupiter.api.Assertions.assertNotNull;
+import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.mockito.ArgumentMatchers.any;
import static org.mockito.Mockito.doAnswer;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import java.io.Serial;
import java.util.concurrent.ScheduledExecutorService;
-import org.junit.After;
-import org.junit.Before;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.BeforeEach;
+import org.junit.jupiter.api.Test;
import org.mockito.Mock;
import org.mockito.MockitoAnnotations;
import org.onap.policy.drools.core.lock.AlwaysFailLock;
import org.onap.policy.drools.core.lock.LockCallback;
import org.onap.policy.drools.core.lock.LockState;
-public class LockManagerTest {
+class LockManagerTest {
private static final String OWNER_KEY = "my key";
private static final String RESOURCE = "my resource";
private static final String RESOURCE2 = "my resource #2";
private MyManager mgr;
+ private AutoCloseable closeable;
+
/**
* Resets fields and creates {@link #mgr}.
*/
- @Before
+ @BeforeEach
public void setUp() {
- MockitoAnnotations.openMocks(this);
+ closeable = MockitoAnnotations.openMocks(this);
doAnswer(args -> {
args.getArgument(0, Runnable.class).run();
mgr = new MyManager();
}
- @After
- public void tearDown() {
-
+ @AfterEach
+ public void tearDown() throws Exception {
+ closeable.close();
}
@Test
- public void testIsAlive() {
+ void testIsAlive() {
assertFalse(mgr.isAlive());
assertFalse(mgr.isLocked());
}
@Test
- public void testStart() {
+ void testStart() {
assertTrue(mgr.start());
assertTrue(mgr.isAlive());
}
@Test
- public void testStop() {
+ void testStop() {
assertFalse(mgr.stop());
mgr.start();
}
@Test
- public void testShutdown() {
+ void testShutdown() {
mgr.start();
mgr.shutdown();
assertFalse(mgr.isAlive());
}
@Test
- public void testIsLocked() {
+ void testIsLocked() {
assertFalse(mgr.isLocked());
assertFalse(mgr.isAlive());
}
@Test
- public void testLock() {
+ void testLock() {
assertTrue(mgr.lock());
assertTrue(mgr.isLocked());
}
@Test
- public void testUnlock() {
+ void testUnlock() {
assertFalse(mgr.unlock());
mgr.lock();
}
@Test
- public void testCreateLock() {
+ void testCreateLock() {
Lock lock = mgr.createLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback, false);
assertTrue(lock.isActive());
verify(callback).lockAvailable(lock);
* Tests createLock() when the feature instance has changed.
*/
@Test
- public void testCreateLockInstanceChanged() {
+ void testCreateLockInstanceChanged() {
mgr = spy(mgr);
when(mgr.hasInstanceChanged()).thenReturn(true);
Lock lock = mgr.createLock(RESOURCE, OWNER_KEY, HOLD_SEC, callback, false);
- assertTrue(lock instanceof AlwaysFailLock);
+ assertInstanceOf(AlwaysFailLock.class, lock);
assertTrue(lock.isUnavailable());
verify(callback, never()).lockAvailable(lock);
}
@Test
- public void testGetResource2lock() {
+ void testGetResource2lock() {
assertNotNull(mgr.getResource2lock());
}
}
private class MyLock extends FeatureLockImpl {
+ @Serial
private static final long serialVersionUID = 1L;
public MyLock(LockState waiting, String resourceId, String ownerKey, int holdSec, LockCallback callback) {