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 | 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 | |
|
43 | |
|
44 | |
|
45 | |
|
46 | |
|
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 | |
|
57 | |
|
58 | |
|
59 | |
|
60 | |
|
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 | |
|
71 | |
|
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 | |
} |