Remove redundant modifiers
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / concurrent / DeadlockDetectingListeningExecutorServiceTest.java
index 6bba351dcabb28a56a7c3cf434c32f29b63adfae..8e50b5873f58919d4db528bc9ccf3884cdd6cef5 100644 (file)
@@ -8,8 +8,19 @@
 
 package org.opendaylight.yangtools.util.concurrent;
 
-import static org.junit.Assert.*;
-
+import static org.junit.Assert.assertEquals;
+import static org.junit.Assert.assertNotNull;
+import static org.junit.Assert.assertTrue;
+import static org.opendaylight.yangtools.util.concurrent.AsyncNotifyingListeningExecutorServiceTest.testListenerCallback;
+import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_CALLABLE;
+import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE;
+import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE_WITH_RESULT;
+import com.google.common.base.Supplier;
+import com.google.common.util.concurrent.FutureCallback;
+import com.google.common.util.concurrent.Futures;
+import com.google.common.util.concurrent.ListenableFuture;
+import com.google.common.util.concurrent.ListeningExecutorService;
+import com.google.common.util.concurrent.ThreadFactoryBuilder;
 import java.util.concurrent.Callable;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
@@ -17,23 +28,10 @@ import java.util.concurrent.ExecutorService;
 import java.util.concurrent.Executors;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
-
 import org.junit.After;
 import org.junit.Before;
 import org.junit.Test;
-
-import com.google.common.base.Function;
-import com.google.common.util.concurrent.FutureCallback;
-import com.google.common.util.concurrent.Futures;
-import com.google.common.util.concurrent.ListenableFuture;
-import com.google.common.util.concurrent.ListeningExecutorService;
-import com.google.common.util.concurrent.ThreadFactoryBuilder;
-
-import static org.opendaylight.yangtools.util.concurrent.AsyncNotifyingListeningExecutorServiceTest.testListenerCallback;
-import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.Invoker;
-import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_CALLABLE;
-import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE;
-import static org.opendaylight.yangtools.util.concurrent.CommonTestUtils.SUBMIT_RUNNABLE_WITH_RESULT;
+import org.opendaylight.yangtools.util.concurrent.CommonTestUtils.Invoker;
 
 /**
  * Unit tests for DeadlockDetectingListeningExecutorService.
@@ -44,18 +42,18 @@ public class DeadlockDetectingListeningExecutorServiceTest {
 
     interface InitialInvoker {
         void invokeExecutor( ListeningExecutorService executor, Runnable task );
-    };
+    }
 
     static final InitialInvoker SUBMIT = new InitialInvoker() {
         @Override
-        public void invokeExecutor( ListeningExecutorService executor, Runnable task ) {
+        public void invokeExecutor( final ListeningExecutorService executor, final Runnable task ) {
             executor.submit( task );
         }
     };
 
     static final InitialInvoker EXECUTE = new InitialInvoker() {
         @Override
-        public void invokeExecutor( ListeningExecutorService executor, Runnable task ) {
+        public void invokeExecutor( final ListeningExecutorService executor, final Runnable task ) {
             executor.execute( task );
         }
     };
@@ -64,9 +62,9 @@ public class DeadlockDetectingListeningExecutorServiceTest {
     public static class TestDeadlockException extends Exception {
     }
 
-    public static Function<Void, Exception> DEADLOCK_EXECUTOR_FUNCTION = new Function<Void, Exception>() {
+    private static final Supplier<Exception> DEADLOCK_EXECUTOR_SUPPLIER = new Supplier<Exception>() {
         @Override
-        public Exception apply( Void notUsed ) {
+        public Exception get() {
             return new TestDeadlockException();
         }
     };
@@ -86,7 +84,7 @@ public class DeadlockDetectingListeningExecutorServiceTest {
 
     DeadlockDetectingListeningExecutorService newExecutor() {
         return new DeadlockDetectingListeningExecutorService( Executors.newSingleThreadExecutor(),
-                DEADLOCK_EXECUTOR_FUNCTION );
+                DEADLOCK_EXECUTOR_SUPPLIER );
     }
 
     @Test
@@ -136,8 +134,8 @@ public class DeadlockDetectingListeningExecutorServiceTest {
         testNonBlockingSubmitOnExecutorThread( EXECUTE, SUBMIT_CALLABLE );
     }
 
-    void testNonBlockingSubmitOnExecutorThread( InitialInvoker initialInvoker,
-                                                final Invoker invoker ) throws Throwable {
+    void testNonBlockingSubmitOnExecutorThread( final InitialInvoker initialInvoker,
+            final Invoker invoker ) throws Throwable {
 
         final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
         final CountDownLatch futureCompletedLatch = new CountDownLatch( 1 );
@@ -149,12 +147,12 @@ public class DeadlockDetectingListeningExecutorServiceTest {
 
                 Futures.addCallback( invoker.invokeExecutor( executor, null ), new FutureCallback() {
                     @Override
-                    public void onSuccess( Object result ) {
+                    public void onSuccess( final Object result ) {
                         futureCompletedLatch.countDown();
                     }
 
                     @Override
-                    public void onFailure( Throwable t ) {
+                    public void onFailure( final Throwable t ) {
                         caughtEx.set( t );
                         futureCompletedLatch.countDown();
                     }
@@ -166,7 +164,7 @@ public class DeadlockDetectingListeningExecutorServiceTest {
         initialInvoker.invokeExecutor( executor, task );
 
         assertTrue( "Task did not complete - executor likely deadlocked",
-                    futureCompletedLatch.await( 5, TimeUnit.SECONDS ) );
+                futureCompletedLatch.await( 5, TimeUnit.SECONDS ) );
 
         if( caughtEx.get() != null ) {
             throw caughtEx.get();
@@ -185,8 +183,8 @@ public class DeadlockDetectingListeningExecutorServiceTest {
         testBlockingSubmitOnExecutorThread( EXECUTE, SUBMIT_CALLABLE );
     }
 
-    void testBlockingSubmitOnExecutorThread( InitialInvoker initialInvoker,
-                                             final Invoker invoker ) throws Exception {
+    void testBlockingSubmitOnExecutorThread( final InitialInvoker initialInvoker,
+            final Invoker invoker ) throws Exception {
 
         final AtomicReference<Throwable> caughtEx = new AtomicReference<>();
         final CountDownLatch latch = new CountDownLatch( 1 );
@@ -211,7 +209,7 @@ public class DeadlockDetectingListeningExecutorServiceTest {
         initialInvoker.invokeExecutor( executor, task );
 
         assertTrue( "Task did not complete - executor likely deadlocked",
-                    latch.await( 5, TimeUnit.SECONDS ) );
+                latch.await( 5, TimeUnit.SECONDS ) );
 
         assertNotNull( "Expected exception thrown", caughtEx.get() );
         assertEquals( "Caught exception type", TestDeadlockException.class, caughtEx.get().getClass() );
@@ -227,7 +225,7 @@ public class DeadlockDetectingListeningExecutorServiceTest {
         executor = new DeadlockDetectingListeningExecutorService(
                 Executors.newSingleThreadExecutor(
                         new ThreadFactoryBuilder().setNameFormat( "SingleThread" ).build() ),
-                DEADLOCK_EXECUTOR_FUNCTION, listenerExecutor );
+                        DEADLOCK_EXECUTOR_SUPPLIER, listenerExecutor );
 
         try {
             testListenerCallback( executor, SUBMIT_CALLABLE, listenerThreadPrefix );