Migrate common/util to JUnit5
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / concurrent / CountingRejectedExecutionHandlerTest.java
index d69565166c993074a0bd54511dd6e3b951650307..a9342646140a9c19ecfa5115afe3d719798a986d 100644 (file)
@@ -7,17 +7,17 @@
  */
 package org.opendaylight.yangtools.util.concurrent;
 
-import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.assertThrows;
-import static org.junit.Assert.assertTrue;
+import static org.junit.jupiter.api.Assertions.assertEquals;
+import static org.junit.jupiter.api.Assertions.assertThrows;
+import static org.junit.jupiter.api.Assertions.assertTrue;
 
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.LinkedBlockingQueue;
 import java.util.concurrent.RejectedExecutionException;
 import java.util.concurrent.ThreadPoolExecutor;
 import java.util.concurrent.TimeUnit;
-import org.junit.After;
-import org.junit.Test;
+import org.junit.jupiter.api.AfterEach;
+import org.junit.jupiter.api.Test;
 import org.opendaylight.yangtools.util.ExecutorServiceUtil;
 import org.opendaylight.yangtools.util.concurrent.ThreadPoolExecutorTest.Task;
 
@@ -26,66 +26,66 @@ import org.opendaylight.yangtools.util.concurrent.ThreadPoolExecutorTest.Task;
  *
  * @author Thomas Pantelis
  */
-public class CountingRejectedExecutionHandlerTest {
+class CountingRejectedExecutionHandlerTest {
 
     private ThreadPoolExecutor executor;
 
-    @After
-    public void tearDown() {
+    @AfterEach
+    void tearDown() {
         if (executor != null) {
             executor.shutdownNow();
         }
     }
 
     @Test
-    public void testCallerRunsPolicyHandler() throws InterruptedException {
+    void testCallerRunsPolicyHandler() throws InterruptedException {
 
-        CountDownLatch tasksRunLatch = new CountDownLatch(1);
-        CountDownLatch blockLatch = new CountDownLatch(1);
+        final var tasksRunLatch = new CountDownLatch(1);
+        final var blockLatch = new CountDownLatch(1);
 
         executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS,
                 ExecutorServiceUtil.offerFailingBlockingQueue(new LinkedBlockingQueue<>()));
 
-        CountingRejectedExecutionHandler countingHandler = CountingRejectedExecutionHandler.newCallerRunsPolicy();
+        final var countingHandler = CountingRejectedExecutionHandler.newCallerRunsPolicy();
         executor.setRejectedExecutionHandler(countingHandler);
 
         executor.execute(new Task(tasksRunLatch, blockLatch));
 
-        int tasks = 5;
+        final var tasks = 5;
         for (int i = 0; i < tasks - 1; i++) {
             executor.execute(new Task(null, null, null, null, 0));
         }
 
-        assertEquals("getRejectedTaskCount", tasks - 1, countingHandler.getRejectedTaskCount());
+        assertEquals(tasks - 1, countingHandler.getRejectedTaskCount(), "getRejectedTaskCount");
 
         blockLatch.countDown();
 
-        assertTrue("Tasks complete", tasksRunLatch.await(5, TimeUnit.SECONDS));
+        assertTrue(tasksRunLatch.await(5, TimeUnit.SECONDS), "Tasks complete");
     }
 
     @Test
-    public void testAbortPolicyHandler() throws InterruptedException {
+    void testAbortPolicyHandler() throws InterruptedException {
 
-        CountDownLatch tasksRunLatch = new CountDownLatch(1);
-        CountDownLatch blockLatch = new CountDownLatch(1);
+        final var tasksRunLatch = new CountDownLatch(1);
+        final var blockLatch = new CountDownLatch(1);
 
         executor = new ThreadPoolExecutor(1, 1, 0, TimeUnit.SECONDS,
                 ExecutorServiceUtil.offerFailingBlockingQueue(new LinkedBlockingQueue<>()));
 
-        CountingRejectedExecutionHandler countingHandler = CountingRejectedExecutionHandler.newAbortPolicy();
+        final var countingHandler = CountingRejectedExecutionHandler.newAbortPolicy();
         executor.setRejectedExecutionHandler(countingHandler);
 
         executor.execute(new Task(tasksRunLatch, blockLatch));
 
-        int tasks = 5;
+        final var tasks = 5;
         for (int i = 0; i < tasks - 1; i++) {
             assertThrows(RejectedExecutionException.class, () -> executor.execute(new Task(null, null, null, null, 0)));
         }
 
-        assertEquals("getRejectedTaskCount", tasks - 1, countingHandler.getRejectedTaskCount());
+        assertEquals(tasks - 1, countingHandler.getRejectedTaskCount(), "getRejectedTaskCount");
 
         blockLatch.countDown();
 
-        assertTrue("Tasks complete", tasksRunLatch.await(5, TimeUnit.SECONDS));
+        assertTrue(tasksRunLatch.await(5, TimeUnit.SECONDS), "Tasks complete");
     }
 }