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.
@SuppressWarnings("serial")
static class TestException extends Exception {
- TestException( String message, Throwable cause ) {
+ TestException( final String message, final Throwable cause ) {
super( message, cause );
}
}
"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 ) {
- if( from instanceof ExecutionException ) {
- return ((ExecutionException)from).getCause();
+ public Throwable extractWrappedTestEx( final Exception from ) {
+ if (from instanceof ExecutionException ) {
+ return from.getCause();
}
return from;
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 ) {
- if( from instanceof ExecutionException ) {
- return ((ExecutionException)from).getCause();
+ public Throwable extractWrappedTestEx( final Exception from ) {
+ if (from instanceof ExecutionException ) {
+ return from.getCause();
}
return from;
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;
}
};
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 =
assertNotNull( "Expected returned exception is null", expectedTestEx );
assertEquals( "Exception type", TestException.class, expectedTestEx.getClass() );
- if( cause instanceof TestException ) {
+ if (cause instanceof TestException ) {
assertNull( "Expected null cause", expectedTestEx.getCause() );
} else {
assertSame( "TestException cause", cause, expectedTestEx.getCause() );
}
}
- private void testCancellationException( FutureInvoker invoker ) {
+ private static void testCancellationException( final FutureInvoker invoker ) {
SettableFuture<String> delegate = SettableFuture.create();
MappingCheckedFuture<String,TestException> mappingFuture =
}
}
- 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 =
thread.interrupt();
assertEquals( "get call completed", true, doneLatch.await( 5, TimeUnit.SECONDS ) );
- if( assertError.get() != null ) {
+ if (assertError.get() != null ) {
throw assertError.get();
}
}