public void testWhenComplete_sourceCancelled(){
  for (  ExecutionMode m : ExecutionMode.values())   for (  boolean mayInterruptIfRunning : new boolean[]{true,false})   for (  boolean createIncomplete : new boolean[]{true,false}) {
    final AtomicInteger a=new AtomicInteger(0);
    final CompletableFuture<Integer> f=new CompletableFuture<>();
    if (!createIncomplete)     assertTrue(f.cancel(mayInterruptIfRunning));
    final CompletableFuture<Integer> g=m.whenComplete(f,null);
    if (createIncomplete)     assertTrue(f.cancel(mayInterruptIfRunning));
    checkCompletedWithWrappedCancellationException(g);
    checkCancelled(f);
    assertEquals(1,a.get());
  }
}

public void testWhenComplete_sourceCancelled ( ) { for ( ExecutionMode m : ExecutionMode . values ( ) ) for ( boolean mayInterruptIfRunning : new boolean [ ] { true , false } ) for ( boolean createIncomplete : new boolean [ ] { true , false } ) { final AtomicInteger a = new AtomicInteger ( 0 ) ; final CompletableFuture < Integer > f = new CompletableFuture < > ( ) ; if ( ! createIncomplete ) assertTrue ( f . cancel ( mayInterruptIfRunning ) ) ; final CompletableFuture < Integer > g = m . whenComplete ( f , null ) ; if ( createIncomplete ) assertTrue ( f . cancel ( mayInterruptIfRunning ) ) ; checkCompletedWithWrappedCancellationException ( g ) ; checkCancelled ( f ) ; assertEquals ( 1 , a . get ( ) ) ; } }
whencomplete action executes on cancelled source , propagating cancellationexception .
