-
-
Notifications
You must be signed in to change notification settings - Fork 682
/
AbstractBooleanAssert.java
137 lines (127 loc) · 4.5 KB
/
AbstractBooleanAssert.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
/**
* Licensed under the Apache License, Version 2.0 (the "License"); you may not use this file except in compliance with
* the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on
* an "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the
* specific language governing permissions and limitations under the License.
*
* Copyright 2012-2015 the original author or authors.
*/
package org.assertj.core.api;
import java.util.Comparator;
import org.assertj.core.internal.Booleans;
import org.assertj.core.util.VisibleForTesting;
/**
* Base class for all implementations of assertions for {@link Boolean}s.
*
* @param <S> the "self" type of this assertion class. Please read "<a href="http://bit.ly/1IZIRcY"
* target="_blank">Emulating 'self types' using Java Generics to simplify fluent API implementation</a>"
* for more details.
*
* @author Alex Ruiz
* @author Yvonne Wang
* @author David DIDIER
* @author Ansgar Konermann
* @author Mikhail Mazursky
*/
public abstract class AbstractBooleanAssert<S extends AbstractBooleanAssert<S>> extends AbstractAssert<S, Boolean> {
@VisibleForTesting
Booleans booleans = Booleans.instance();
protected AbstractBooleanAssert(Boolean actual, Class<?> selfType) {
super(actual, selfType);
}
/**
* Verifies that the actual value is {@code true}.
* <p/>
* Example:
* <pre><code class='java'> // assertions will pass
* assertThat(true).isTrue();
* assertThat(Boolean.TRUE).isTrue();
*
* // assertions will fail
* assertThat(false).isTrue();
* assertThat(Boolean.FALSE).isTrue();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not {@code true}.
*/
public S isTrue() {
return isEqualTo(true);
}
/**
* Verifies that the actual value is {@code false}.
* <p/>
* Example:
* <pre><code class='java'> // assertions will pass
* assertThat(false).isFalse();
* assertThat(Boolean.FALSE).isFalse();
*
* // assertions will fail
* assertThat(true).isFalse();
* assertThat(Boolean.TRUE).isFalse();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not {@code false}.
*/
public S isFalse() {
return isEqualTo(false);
}
/**
* Verifies that the actual value is equal to the given one.
* <p/>
* Example:
* <pre><code class='java'> // assertions will pass
* assertThat(true).isEqualTo(true);
* assertThat(Boolean.FALSE).isEqualTo(false);
*
* // assertions will fail
* assertThat(true).isEqualTo(false);
* assertThat(Boolean.TRUE).isEqualTo(false);</code></pre>
*
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not equal to the given one.
*/
public S isEqualTo(boolean expected) {
booleans.assertEqual(info, actual, expected);
return myself;
}
/**
* Verifies that the actual value is not equal to the given one.
* <p/>
* Example:
* <pre><code class='java'> // assertions will pass
* assertThat(true).isNotEqualTo(false);
* assertThat(Boolean.FALSE).isNotEqualTo(true);
*
* // assertions will fail
* assertThat(true).isNotEqualTo(true);
* assertThat(Boolean.FALSE).isNotEqualTo(false);</code></pre>
*
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is equal to the given one.
*/
public S isNotEqualTo(boolean other) {
booleans.assertNotEqual(info, actual, other);
return myself;
}
/**
* Do not use this method.
*
* @deprecated Custom Comparator is not supported for Boolean comparison.
* @throws UnsupportedOperationException if this method is called.
*/
@Override
@Deprecated
public final S usingComparator(Comparator<? super Boolean> customComparator) {
throw new UnsupportedOperationException("custom Comparator is not supported for Boolean comparison");
}
}