Coverage Report - org.truth0.AbstractVerb
 
Classes in this File Line Coverage Branch Coverage Complexity
AbstractVerb
90%
9/10
N/A
1
AbstractVerb$DelegatedVerb
0%
0/4
N/A
1
 
 1  
 package org.truth0;
 2  
 
 3  
 import org.truth0.subjects.Subject;
 4  
 import org.truth0.subjects.SubjectFactory;
 5  
 
 6  
 import com.google.common.annotations.GwtCompatible;
 7  
 import com.google.common.annotations.GwtIncompatible;
 8  
 
 9  
 @GwtCompatible
 10  
 public class AbstractVerb {
 11  
 
 12  
   private final FailureStrategy failureStrategy;
 13  
 
 14  5
   public AbstractVerb(FailureStrategy failureStrategy) {
 15  5
     this.failureStrategy = failureStrategy;
 16  5
   }
 17  
 
 18  
   protected FailureStrategy getFailureStrategy() {
 19  89
     return failureStrategy;
 20  
   }
 21  
 
 22  
         /**
 23  
          * Triggers the failure strategy with an empty failure message
 24  
          */
 25  
         public void fail() {
 26  1
                 failureStrategy.fail("");
 27  1
         }
 28  
 
 29  
         /**
 30  
          * Triggers the failure strategy with the given failure message
 31  
          */
 32  
         public void fail(String message) {
 33  1
                 failureStrategy.fail(message);
 34  1
         }
 35  
 
 36  
   /**
 37  
    * The recommended method of extension of Truth to new types, which is
 38  
    * documented in {@link DelegationTest }.
 39  
    *
 40  
    * @see DelegationTest
 41  
    * @param factory a SubjectFactory<S, T> implementation
 42  
    * @returns A custom verb for the type returned by the SubjectFactory
 43  
    */
 44  
   public <S extends Subject<S,T>, T, SF extends SubjectFactory<S, T>>
 45  
       DelegatedVerb<S, T> about(SF factory) {
 46  0
       return new DelegatedVerb<S, T>(getFailureStrategy(), factory);
 47  
   }
 48  
 
 49  
   /**
 50  
    * A special Verb implementation which wraps a SubjectFactory
 51  
    */
 52  
   public static class DelegatedVerb<S extends Subject<S,T>, T>
 53  
       extends AbstractVerb {
 54  
 
 55  
     private final SubjectFactory<S, T> factory;
 56  
 
 57  
     public DelegatedVerb(FailureStrategy fs, SubjectFactory<S, T> factory) {
 58  0
       super(fs);
 59  0
       this.factory = factory;
 60  0
     }
 61  
 
 62  
     public S that(T target) {
 63  0
       return factory.getSubject(getFailureStrategy(), target);
 64  
     }
 65  
   }
 66  
 
 67  
   @GwtIncompatible("org.truth0.IteratingVerb")
 68  
   public <T> IteratingVerb<T> in(Iterable<T> data) {
 69  2
     return new IteratingVerb<T>(data, getFailureStrategy());
 70  
   }
 71  
 
 72  
 }
 73