### Question:
FutureUtils { public static <T> T resolveOrCancelFuture(Future<T> future, Duration timeout) throws ExecutionException, InterruptedException, TimeoutException { try { return future.get(timeout.toMillis(), TimeUnit.MILLISECONDS); } catch (TimeoutException te) { future.cancel(true); throw te; } }  static T resolveOrCancelFuture(Future<T> future, Duration timeout);  }### Answer:
@Test public void testTimeoutExceptionCancelsFuture() throws Exception { expectedException.expect(TimeoutException.class); when(future.get(anyLong(), any())).thenThrow(new TimeoutException("Timeout")); try { FutureUtils.resolveOrCancelFuture(future, Duration.ofSeconds(1)); } finally { verify(future).cancel(eq(true)); } }