/
BooleanArrays.java
339 lines (308 loc) · 14.3 KB
/
BooleanArrays.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
/**
* 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-2017 the original author or authors.
*/
package org.assertj.core.internal;
import java.util.Comparator;
import org.assertj.core.api.ArraySortedAssert;
import org.assertj.core.api.AssertionInfo;
import org.assertj.core.data.Index;
import org.assertj.core.util.VisibleForTesting;
/**
* Reusable assertions for arrays of {@code boolean}s.
*
* @author Alex Ruiz
* @author Joel Costigliola
* @author Mikhail Mazursky
* @author Nicolas François
*/
public class BooleanArrays {
private static final BooleanArrays INSTANCE = new BooleanArrays();
/**
* Returns the singleton instance of this class.
*
* @return the singleton instance of this class.
*/
public static BooleanArrays instance() {
return INSTANCE;
}
private Arrays arrays;
@VisibleForTesting
Failures failures = Failures.instance();
@VisibleForTesting
BooleanArrays() {
setArrays(Arrays.instance());
}
@VisibleForTesting
public void setArrays(Arrays arrays) {
this.arrays = arrays;
}
/**
* Asserts that the given array is {@code null} or empty.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @throws AssertionError if the given array is not {@code null} *and* contains one or more elements.
*/
public void assertNullOrEmpty(AssertionInfo info, boolean[] actual) {
arrays.assertNullOrEmpty(info, failures, actual);
}
/**
* Asserts that the given array is empty.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array is not empty.
*/
public void assertEmpty(AssertionInfo info, boolean[] actual) {
arrays.assertEmpty(info, failures, actual);
}
/**
* Asserts that the given array is not empty.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array is empty.
*/
public void assertNotEmpty(AssertionInfo info, boolean[] actual) {
arrays.assertNotEmpty(info, failures, actual);
}
/**
* Asserts that the number of elements in the given array is equal to the expected one.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param expectedSize the expected size of {@code actual}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the number of elements in the given array is different than the expected one.
*/
public void assertHasSize(AssertionInfo info, boolean[] actual, int expectedSize) {
arrays.assertHasSize(info, failures, actual, expectedSize);
}
/**
* Assert that the actual array has the same size as the other {@code Iterable}.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param other the group to compare
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the other group is {@code null}.
* @throws AssertionError if the actual group does not have the same size.
*/
public void assertHasSameSizeAs(AssertionInfo info, boolean[] actual, Iterable<?> other) {
arrays.assertHasSameSizeAs(info, actual, other);
}
/**
* Assert that the actual array has the same size as the other array.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param other the group to compare
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the other group is {@code null}.
* @throws AssertionError if the actual group does not have the same size.
*/
public void assertHasSameSizeAs(AssertionInfo info, boolean[] actual, Object[] other) {
arrays.assertHasSameSizeAs(info, actual, other);
}
/**
* Asserts that the given array contains the given values, in any order.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param values the values that are expected to be in the given array.
* @throws NullPointerException if the array of values is {@code null}.
* @throws IllegalArgumentException if the array of values is empty.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array does not contain the given values.
*/
public void assertContains(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertContains(info, failures, actual, values);
}
/**
* Verifies that the given array contains the given value at the given index.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param value the value to look for.
* @param index the index where the value should be stored in the given array.
* @throws AssertionError if the given array is {@code null} or empty.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws IndexOutOfBoundsException if the value of the given {@code Index} is equal to or greater than the size of
* the given array.
* @throws AssertionError if the given array does not contain the given value at the given index.
*/
public void assertContains(AssertionInfo info, boolean[] actual, boolean value, Index index) {
arrays.assertContains(info, failures, actual, value, index);
}
/**
* Verifies that the given array does not contain the given value at the given index.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param value the value to look for.
* @param index the index where the value should be stored in the given array.
* @throws AssertionError if the given array is {@code null}.
* @throws NullPointerException if the given {@code Index} is {@code null}.
* @throws AssertionError if the given array contains the given value at the given index.
*/
public void assertDoesNotContain(AssertionInfo info, boolean[] actual, boolean value, Index index) {
arrays.assertDoesNotContain(info, failures, actual, value, index);
}
/**
* Asserts that the given array contains only the given values and nothing else, in any order.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param values the values that are expected to be in the given array.
* @throws NullPointerException if the array of values is {@code null}.
* @throws IllegalArgumentException if the array of values is empty.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array does not contain the given values or if the given array contains values
* that are not in the given array.
*/
public void assertContainsOnly(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertContainsOnly(info, failures, actual, values);
}
public void assertContainsExactly(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertContainsExactly(info, failures, actual, values);
}
public void assertContainsExactlyInAnyOrder(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertContainsExactlyInAnyOrder(info, failures, actual, values);
}
/**
* Asserts that the given array contains only once the given values.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param values the values that are expected to be in the given array.
* @throws NullPointerException if the array of values is {@code null}.
* @throws IllegalArgumentException if the array of values is empty.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array does not contain the given values or if the given array contains more
* than once values.
*/
public void assertContainsOnlyOnce(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertContainsOnlyOnce(info, failures, actual, values);
}
/**
* Verifies that the given array contains the given sequence of values, without any other values between them.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param sequence the sequence of values to look for.
* @throws AssertionError if the given array is {@code null}.
* @throws NullPointerException if the given sequence is {@code null}.
* @throws IllegalArgumentException if the given sequence is empty.
* @throws AssertionError if the given array does not contain the given sequence of values.
*/
public void assertContainsSequence(AssertionInfo info, boolean[] actual, boolean[] sequence) {
arrays.assertContainsSequence(info, failures, actual, sequence);
}
/**
* Verifies that the given array contains the given subsequence of values (possibly with other values between them).
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param subsequence the subsequence of values to look for.
* @throws AssertionError if the given array is {@code null}.
* @throws NullPointerException if the given subsequence is {@code null}.
* @throws IllegalArgumentException if the given subsequence is empty.
* @throws AssertionError if the given array does not contain the given subsequence of values.
*/
public void assertContainsSubsequence(AssertionInfo info, boolean[] actual, boolean[] subsequence) {
arrays.assertContainsSubsequence(info, failures, actual, subsequence);
}
/**
* Asserts that the given array does not contain the given values.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param values the values that are expected not to be in the given array.
* @throws NullPointerException if the array of values is {@code null}.
* @throws IllegalArgumentException if the array of values is empty.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array contains any of given values.
*/
public void assertDoesNotContain(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertDoesNotContain(info, failures, actual, values);
}
/**
* Asserts that the given array does not have duplicate values.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @throws NullPointerException if the array of values is {@code null}.
* @throws IllegalArgumentException if the array of values is empty.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array contains duplicate values.
*/
public void assertDoesNotHaveDuplicates(AssertionInfo info, boolean[] actual) {
arrays.assertDoesNotHaveDuplicates(info, failures, actual);
}
/**
* Verifies that the given array starts with the given sequence of values, without any other values between them.
* Similar to <code>{@link #assertContainsSequence(AssertionInfo, boolean[], boolean[])}</code>, but it also verifies
* that the first element in the sequence is also the first element of the given array.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param sequence the sequence of values to look for.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array does not start with the given sequence of values.
*/
public void assertStartsWith(AssertionInfo info, boolean[] actual, boolean[] sequence) {
arrays.assertStartsWith(info, failures, actual, sequence);
}
/**
* Verifies that the given array ends with the given sequence of values, without any other values between them.
* Similar to <code>{@link #assertContainsSequence(AssertionInfo, boolean[], boolean[])}</code>, but it also verifies
* that the last element in the sequence is also the last element of the given array.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param sequence the sequence of values to look for.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the given array does not end with the given sequence of values.
*/
public void assertEndsWith(AssertionInfo info, boolean[] actual, boolean[] sequence) {
arrays.assertEndsWith(info, failures, actual, sequence);
}
/**
* Concrete implementation of {@link ArraySortedAssert#isSorted()}.
*
* @param info contains information about the assertion.
* @param actual the given array.
*/
public void assertIsSorted(AssertionInfo info, boolean[] actual) {
arrays.assertIsSorted(info, failures, actual);
}
/**
* Concrete implementation of {@link ArraySortedAssert#isSortedAccordingTo(Comparator)}.
*
* @param info contains information about the assertion.
* @param actual the given array.
* @param comparator the {@link Comparator} used to compare array elements
*/
public void assertIsSortedAccordingToComparator(AssertionInfo info, boolean[] actual,
Comparator<? super Boolean> comparator) {
Arrays.assertIsSortedAccordingToComparator(info, failures, actual, comparator);
}
public void assertContainsAnyOf(AssertionInfo info, boolean[] actual, boolean[] values) {
arrays.assertContainsAnyOf(info, failures, actual, values);
}
}