| 1 | |
|
| 2 | |
|
| 3 | |
|
| 4 | |
|
| 5 | |
|
| 6 | |
|
| 7 | |
|
| 8 | |
|
| 9 | |
|
| 10 | |
|
| 11 | |
|
| 12 | |
|
| 13 | |
|
| 14 | |
|
| 15 | |
|
| 16 | |
|
| 17 | |
package org.truth0.subjects; |
| 18 | |
|
| 19 | |
|
| 20 | |
import org.truth0.FailureStrategy; |
| 21 | |
|
| 22 | |
import com.google.common.annotations.GwtCompatible; |
| 23 | |
|
| 24 | |
|
| 25 | |
|
| 26 | |
|
| 27 | |
|
| 28 | |
|
| 29 | |
|
| 30 | |
@GwtCompatible |
| 31 | |
public class IntegerSubject extends Subject<IntegerSubject, Long> { |
| 32 | |
|
| 33 | |
public IntegerSubject(FailureStrategy failureStrategy, Long i) { |
| 34 | 11 | super(failureStrategy, i); |
| 35 | 11 | } |
| 36 | |
|
| 37 | |
public IntegerSubject(FailureStrategy failureStrategy, Integer i) { |
| 38 | 33 | super(failureStrategy, i == null ? null : Long.valueOf(i.longValue())); |
| 39 | 33 | } |
| 40 | |
|
| 41 | |
|
| 42 | |
|
| 43 | |
|
| 44 | |
|
| 45 | |
|
| 46 | |
|
| 47 | |
|
| 48 | |
public void isInclusivelyInRange(long lower, long upper) { |
| 49 | 6 | ensureOrderedBoundaries(lower, upper); |
| 50 | 5 | if (!(lower <= getSubject() && getSubject() <= upper)) { |
| 51 | 2 | fail("is inclusively in range", lower, upper); |
| 52 | |
} |
| 53 | 3 | } |
| 54 | |
|
| 55 | |
|
| 56 | |
|
| 57 | |
|
| 58 | |
|
| 59 | |
|
| 60 | |
|
| 61 | |
|
| 62 | |
public void isBetween(long lower, long upper) { |
| 63 | 5 | ensureOrderedBoundaries(lower, upper); |
| 64 | 4 | if (!(lower < getSubject() && getSubject() < upper)) { |
| 65 | 1 | fail("is in between", lower, upper); |
| 66 | |
} |
| 67 | 3 | } |
| 68 | |
|
| 69 | |
|
| 70 | |
|
| 71 | |
|
| 72 | |
|
| 73 | |
private static void ensureOrderedBoundaries(long lower, long upper) { |
| 74 | 11 | if (lower > upper) { |
| 75 | 2 | throw new IllegalArgumentException( |
| 76 | |
"Range inclusion parameter lower (" + lower + ") " |
| 77 | |
+ " should not be greater than upper (" + upper + ")"); |
| 78 | |
} |
| 79 | 9 | } |
| 80 | |
|
| 81 | |
public void isEqualTo(Integer other) { |
| 82 | 11 | isEqualTo((other == null) ? null : Long.valueOf(other.longValue())); |
| 83 | 6 | } |
| 84 | |
|
| 85 | |
public void isEqualTo(Long other) { |
| 86 | 12 | if (getSubject() == null) { |
| 87 | 2 | if(other != null) { |
| 88 | 1 | fail("is equal to", other); |
| 89 | |
} |
| 90 | |
} else { |
| 91 | 10 | if (!getSubject().equals(other)) { |
| 92 | 4 | fail("is equal to", other); |
| 93 | |
} |
| 94 | |
} |
| 95 | 7 | } |
| 96 | |
|
| 97 | |
public void isNotEqualTo(Integer other) { |
| 98 | 15 | isNotEqualTo((other == null) ? null : Long.valueOf(other.longValue())); |
| 99 | 11 | } |
| 100 | |
|
| 101 | |
public void isNotEqualTo(Long other) { |
| 102 | 16 | if (getSubject() == null) { |
| 103 | 2 | if(other == null) { |
| 104 | 1 | fail("is not equal to", (Object)null); |
| 105 | |
} |
| 106 | |
} else { |
| 107 | 14 | if (getSubject().equals(other)) { |
| 108 | 4 | fail("is not equal to", other); |
| 109 | |
} |
| 110 | |
} |
| 111 | 12 | } |
| 112 | |
|
| 113 | |
public void is(int other) { |
| 114 | 2 | super.is((long)other); |
| 115 | 2 | } |
| 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 | 1 | public static final SubjectFactory<IntegerSubject, Long> INTEGER = |
| 127 | 7 | new SubjectFactory<IntegerSubject, Long>() { |
| 128 | |
@Override public IntegerSubject getSubject(FailureStrategy fs, Long target) { |
| 129 | 6 | return new IntegerSubject(fs, target); |
| 130 | |
} |
| 131 | |
}; |
| 132 | |
} |