Coverage Report - org.truth0.subjects.IntegerSubject
 
Classes in this File Line Coverage Branch Coverage Complexity
IntegerSubject
0%
0/38
0%
0/28
2.154
IntegerSubject$1
0%
0/2
N/A
2.154
 
 1  
 /*
 2  
  * Copyright (c) 2011 David Saff
 3  
  * Copyright (c) 2011 Christian Gruber
 4  
  *
 5  
  * Licensed under the Apache License, Version 2.0 (the "License");
 6  
  * you may not use this file except in compliance with the License.
 7  
  * You may obtain a copy of the License at
 8  
  *
 9  
  * http://www.apache.org/licenses/LICENSE-2.0
 10  
  *
 11  
  * Unless required by applicable law or agreed to in writing, software
 12  
  * distributed under the License is distributed on an "AS IS" BASIS,
 13  
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
 14  
  * See the License for the specific language governing permissions and
 15  
  * limitations under the License.
 16  
  */
 17  
 package org.truth0.subjects;
 18  
 
 19  
 
 20  
 import org.truth0.FailureStrategy;
 21  
 
 22  
 import com.google.common.annotations.GwtCompatible;
 23  
 
 24  
 /**
 25  
  * Propositions for Integral numeric subjects
 26  
  *
 27  
  * @author David Saff
 28  
  * @author Christian Gruber (cgruber@israfil.net)
 29  
  */
 30  
 @GwtCompatible
 31  
 public class IntegerSubject extends Subject<IntegerSubject, Long> {
 32  
 
 33  
   public IntegerSubject(FailureStrategy failureStrategy, Long i) {
 34  0
     super(failureStrategy, i);
 35  0
   }
 36  
 
 37  
   public IntegerSubject(FailureStrategy failureStrategy, Integer i) {
 38  0
     super(failureStrategy, i == null ? null : Long.valueOf(i.longValue()));
 39  0
   }
 40  
 
 41  
   /**
 42  
    * Attests that a Subject<Integer> is inclusively within the {@code lower} and
 43  
    * {@code upper} bounds provided or fails.
 44  
    *
 45  
    * @throws IllegalArgumentException
 46  
    *           if the lower bound is greater than the upper.
 47  
    */
 48  
   public void isInclusivelyInRange(long lower, long upper) {
 49  0
     ensureOrderedBoundaries(lower, upper);
 50  0
     if (!(lower <= getSubject() && getSubject() <= upper)) {
 51  0
       fail("is inclusively in range", lower, upper);
 52  
     }
 53  0
   }
 54  
 
 55  
   /**
 56  
    * Attests that a Subject<Integer> is exclusively within the {@code lower} and
 57  
    * {@code upper} bounds provided or fails.
 58  
    *
 59  
    * @throws IllegalArgumentException
 60  
    *           if the lower bound is greater than the upper.
 61  
    */
 62  
   public void isBetween(long lower, long upper) {
 63  0
     ensureOrderedBoundaries(lower, upper);
 64  0
     if (!(lower < getSubject() && getSubject() < upper)) {
 65  0
       fail("is in between", lower, upper);
 66  
     }
 67  0
   }
 68  
 
 69  
   /**
 70  
    * Guards against inverted lower/upper boundaries, and throws if
 71  
    * they are so inverted.
 72  
    */
 73  
   private static void ensureOrderedBoundaries(long lower, long upper) {
 74  0
     if (lower > upper) {
 75  0
       throw new IllegalArgumentException(
 76  
           "Range inclusion parameter lower (" + lower + ") "
 77  
               + " should not be greater than upper (" + upper + ")");
 78  
     }
 79  0
   }
 80  
 
 81  
   public void isEqualTo(Integer other) {
 82  0
     isEqualTo((other == null) ? null : Long.valueOf(other.longValue()));
 83  0
   }
 84  
 
 85  
   public void isEqualTo(Long other) {
 86  0
     if (getSubject() == null) {
 87  0
       if(other != null) {
 88  0
         fail("is equal to", other);
 89  
       }
 90  
     } else {
 91  0
       if (!getSubject().equals(other)) {
 92  0
         fail("is equal to", other);
 93  
       }
 94  
     }
 95  0
   }
 96  
 
 97  
   public void isNotEqualTo(Integer other) {
 98  0
     isNotEqualTo((other == null) ? null : Long.valueOf(other.longValue()));
 99  0
   }
 100  
 
 101  
   public void isNotEqualTo(Long other) {
 102  0
     if (getSubject() == null) {
 103  0
       if(other == null) {
 104  0
         fail("is not equal to", (Object)null);
 105  
       }
 106  
     } else {
 107  0
       if (getSubject().equals(other)) {
 108  0
         fail("is not equal to", other);
 109  
       }
 110  
     }
 111  0
   }
 112  
 
 113  
   public void is(int other) {
 114  0
     super.is((long)other);
 115  0
   }
 116  
 
 117  
   public void is(short other) {
 118  0
     super.is((long)other);
 119  0
   }
 120  
 
 121  
   public void is(byte other) {
 122  0
     super.is((long)other);
 123  0
   }
 124  
 
 125  
 
 126  0
   public static final SubjectFactory<IntegerSubject, Long> INTEGER =
 127  0
       new SubjectFactory<IntegerSubject, Long>() {
 128  
         @Override public IntegerSubject getSubject(FailureStrategy fs, Long target) {
 129  0
           return new IntegerSubject(fs, target);
 130  
         }
 131  
       };
 132  
 }