Java 8: use lambdas and function references
[yangtools.git] / common / util / src / test / java / org / opendaylight / yangtools / util / concurrent / MappingCheckedFutureTest.java
index 45b9e3c41140a531a20b26a6877a440f39340e7f..deeafc1c1b747b3412387a308abb9b4036548cd1 100644 (file)
@@ -10,20 +10,19 @@ package org.opendaylight.yangtools.util.concurrent;
 
 
 import static org.junit.Assert.assertEquals;
-import static org.junit.Assert.fail;
 import static org.junit.Assert.assertNotNull;
 import static org.junit.Assert.assertNull;
 import static org.junit.Assert.assertSame;
+import static org.junit.Assert.fail;
 
+import com.google.common.util.concurrent.CheckedFuture;
+import com.google.common.util.concurrent.SettableFuture;
 import java.util.concurrent.CancellationException;
 import java.util.concurrent.CountDownLatch;
 import java.util.concurrent.ExecutionException;
 import java.util.concurrent.TimeUnit;
 import java.util.concurrent.atomic.AtomicReference;
-
 import org.junit.Test;
-import com.google.common.util.concurrent.CheckedFuture;
-import com.google.common.util.concurrent.SettableFuture;
 
 /**
  * Unit tests for MappingCheckedFuture.
@@ -39,7 +38,7 @@ public class MappingCheckedFutureTest {
 
     @SuppressWarnings("serial")
     static class TestException extends Exception {
-        TestException( String message, Throwable cause ) {
+        TestException( final String message, final Throwable cause ) {
             super( message, cause );
         }
     }
@@ -48,21 +47,21 @@ public class MappingCheckedFutureTest {
                                                                       "Test", TestException.class ) {
 
         @Override
-        protected TestException newWithCause( String message, Throwable cause ) {
+        protected TestException newWithCause( final String message, final Throwable cause ) {
             return new TestException( message, cause );
         }
     };
 
     static final FutureInvoker GET = new FutureInvoker() {
         @Override
-        public void invokeGet( CheckedFuture<?,?> future ) throws Exception {
+        public void invokeGet( final CheckedFuture<?,?> future ) throws Exception {
             future.get();
         }
 
         @Override
-        public Throwable extractWrappedTestEx( Exception from ) {
-            iffrom instanceof ExecutionException ) {
-                return ((ExecutionException)from).getCause();
+        public Throwable extractWrappedTestEx( final Exception from ) {
+            if (from instanceof ExecutionException ) {
+                return from.getCause();
             }
 
             return from;
@@ -71,14 +70,14 @@ public class MappingCheckedFutureTest {
 
     static final FutureInvoker TIMED_GET = new FutureInvoker() {
         @Override
-        public void invokeGet( CheckedFuture<?,?> future ) throws Exception {
+        public void invokeGet( final CheckedFuture<?,?> future ) throws Exception {
             future.get( 1, TimeUnit.HOURS );
         }
 
         @Override
-        public Throwable extractWrappedTestEx( Exception from ) {
-            iffrom instanceof ExecutionException ) {
-                return ((ExecutionException)from).getCause();
+        public Throwable extractWrappedTestEx( final Exception from ) {
+            if (from instanceof ExecutionException ) {
+                return from.getCause();
             }
 
             return from;
@@ -87,24 +86,24 @@ public class MappingCheckedFutureTest {
 
     static final FutureInvoker CHECKED_GET = new FutureInvoker() {
         @Override
-        public void invokeGet( CheckedFuture<?,?> future ) throws Exception {
+        public void invokeGet( final CheckedFuture<?,?> future ) throws Exception {
             future.checkedGet();
         }
 
         @Override
-        public Throwable extractWrappedTestEx( Exception from ) {
+        public Throwable extractWrappedTestEx( final Exception from ) {
             return from;
         }
     };
 
     static final FutureInvoker TIMED_CHECKED_GET = new FutureInvoker() {
         @Override
-        public void invokeGet( CheckedFuture<?,?> future ) throws Exception {
+        public void invokeGet( final CheckedFuture<?,?> future ) throws Exception {
             future.checkedGet( 50, TimeUnit.MILLISECONDS );
         }
 
         @Override
-        public Throwable extractWrappedTestEx( Exception from ) {
+        public Throwable extractWrappedTestEx( final Exception from ) {
             return from;
         }
     };
@@ -160,7 +159,7 @@ public class MappingCheckedFutureTest {
         testInterruptedException( TIMED_CHECKED_GET );
     }
 
-    private void testExecutionException( FutureInvoker invoker, Throwable cause ) {
+    private static void testExecutionException( final FutureInvoker invoker, final Throwable cause ) {
 
         SettableFuture<String> delegate = SettableFuture.create();
         MappingCheckedFuture<String,TestException> mappingFuture =
@@ -176,7 +175,7 @@ public class MappingCheckedFutureTest {
             assertNotNull( "Expected returned exception is null", expectedTestEx );
             assertEquals( "Exception type", TestException.class, expectedTestEx.getClass() );
 
-            ifcause instanceof TestException ) {
+            if (cause instanceof TestException ) {
                 assertNull( "Expected null cause", expectedTestEx.getCause() );
             } else {
                 assertSame( "TestException cause", cause, expectedTestEx.getCause() );
@@ -184,7 +183,7 @@ public class MappingCheckedFutureTest {
         }
     }
 
-    private void testCancellationException( FutureInvoker invoker ) {
+    private static void testCancellationException( final FutureInvoker invoker ) {
 
         SettableFuture<String> delegate = SettableFuture.create();
         MappingCheckedFuture<String,TestException> mappingFuture =
@@ -204,7 +203,7 @@ public class MappingCheckedFutureTest {
         }
     }
 
-    private void testInterruptedException( final FutureInvoker invoker ) throws Exception {
+    private static void testInterruptedException( final FutureInvoker invoker ) throws Exception {
 
         SettableFuture<String> delegate = SettableFuture.create();
         final MappingCheckedFuture<String,TestException> mappingFuture =
@@ -243,7 +242,7 @@ public class MappingCheckedFutureTest {
         thread.interrupt();
         assertEquals( "get call completed", true, doneLatch.await( 5, TimeUnit.SECONDS ) );
 
-        ifassertError.get() != null ) {
+        if (assertError.get() != null ) {
             throw assertError.get();
         }
     }