Class AbstractFutureAssert<SELF extends AbstractFutureAssert<SELF,​ACTUAL,​RESULT>,​ACTUAL extends Future<RESULT>,​RESULT>

  • All Implemented Interfaces:
    Assert<SELF,​ACTUAL>, Descriptable<SELF>, ExtensionPoints<SELF,​ACTUAL>
    Direct Known Subclasses:
    FutureAssert

    public abstract class AbstractFutureAssert<SELF extends AbstractFutureAssert<SELF,​ACTUAL,​RESULT>,​ACTUAL extends Future<RESULT>,​RESULT>
    extends AbstractAssert<SELF,​ACTUAL>
    • Constructor Detail

      • AbstractFutureAssert

        protected AbstractFutureAssert​(ACTUAL actual,
                                       Class<?> selfType)
    • Method Detail

      • isCancelled

        public SELF isCancelled()
        Verifies that the Future is cancelled.

        Example:

         ExecutorService executorService = Executors.newSingleThreadExecutor();
                                                                                
         Future<String> future = executorService.submit(new Callable<String>() {
           @Override                                                            
           public String call() throws Exception {                              
             return "done";                                                     
           }                                                                    
         });                                                                    
                                                                                
         // assertion will fail:
         assertThat(future).isCancelled();
         
         // assertion will pass:
         future.cancel(true);
         assertThat(future).isCancelled();
        Returns:
        this assertion object.
        Since:
        2.7.0 / 3.7.0
        See Also:
        Future.isCancelled()
      • isNotCancelled

        public SELF isNotCancelled()
        Verifies that the Future is not cancelled.

        Example:

         ExecutorService executorService = Executors.newSingleThreadExecutor();
                                                                                
         Future<String> future = executorService.submit(new Callable<String>() {
           @Override                                                            
           public String call() throws Exception {                              
             return "done";                                                     
           }                                                                    
         });                                                                    
                                                                                
         // assertion will pass:
         assertThat(future).isNotCancelled();
        
         // assertion will fail:
         future.cancel(true);
         assertThat(future).isNotCancelled();
        Returns:
        this assertion object.
        Since:
        2.7.0 / 3.7.0
        See Also:
        Future.isCancelled()
      • isDone

        public SELF isDone()
        Verifies that the Future is done.

        Example:

         ExecutorService executorService = Executors.newSingleThreadExecutor();
                                                                                
         Future<String> future = executorService.submit(new Callable<String>() {
           @Override                                                            
           public String call() throws Exception {                              
             return "done";                                                     
           }                                                                    
         });                                                                    
                                                                                
         // assertion will pass:
         assertThat(future).isDone();
        
         future = executorService.submit(new Callable<String>() {
           @Override                                                            
           public String call() throws Exception {                              
             Thread.sleep(1000);
             return "done";                                                     
           }                                                                    
         });                                                                    
                                                                                
         // assertion will fail:
         assertThat(future).isDone();
        Returns:
        this assertion object.
        Since:
        2.7.0 / 3.7.0
        See Also:
        Future.isDone()
      • isNotDone

        public SELF isNotDone()
        Verifies that the Future is not done.

        Example:

         ExecutorService executorService = Executors.newSingleThreadExecutor();
                                                                                
         Future<String> future = executorService.submit(new Callable<String>() {
           @Override                                                            
           public String call() throws Exception {                              
             Thread.sleep(1000);
             return "done";                                                     
           }                                                                    
         });
                                                                             
         // assertion will pass:
         assertThat(future).isNotDone();
                                                                                
         future = executorService.submit(new Callable<String>() {
           @Override                                                            
           public String call() throws Exception {                              
             return "done";                                                     
           }                                                                    
         });                                                             
        
         // assertion will fail:
         assertThat(future).isNotDone();
        Returns:
        this assertion object.
        Since:
        2.7.0 / 3.7.0
        See Also:
        Future.isDone()