### Question:
FutureUtil { public static <T> Future<T> getFirstFromCollection(final Future<RestfulCollection<T>> collection) { return new Future<T>() { public boolean cancel(boolean mayInterruptIfRunning) { return collection.cancel(mayInterruptIfRunning); } public T get() throws InterruptedException, ExecutionException { return getFirstFromCollection(collection.get()); } public T get(long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException { return getFirstFromCollection(collection.get(timeout, unit)); } public boolean isCancelled() { return collection.isCancelled(); } public boolean isDone() { return collection.isDone(); } private T getFirstFromCollection(RestfulCollection<T> collection) { if (collection.getTotalResults() > 0) { return collection.getEntry().get(0); } return null; } }; } private  FutureUtil(); static Future<T> getFirstFromCollection(final Future<RestfulCollection<T>> collection);  }### Answer:
@Test public void testGetFirstOfMany() throws Exception { List<String> words = Lists.newArrayList(firstWord, "goodbye", "blah"); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertEquals(firstWord, futureWord.get()); }
@Test public void testGetFirstOfSingle() throws Exception { List<String> words = Lists.newArrayList(firstWord); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertEquals(firstWord, futureWord.get()); }
@Test public void testGetFirstOfNone() throws Exception { List<String> words = Lists.newArrayList(new String[]{}); Future<RestfulCollection<String>> collection = ImmediateFuture.newInstance( new RestfulCollection<String>(words)); Future<String> futureWord = FutureUtil.getFirstFromCollection(collection); assertNull(futureWord.get()); }