-
-
Notifications
You must be signed in to change notification settings - Fork 683
/
ObjectEnumerableAssert.java
1205 lines (1155 loc) · 53.7 KB
/
ObjectEnumerableAssert.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
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/**
* 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.api;
import java.util.HashSet;
/**
* Assertions methods applicable to groups of objects (e.g. arrays or collections.)
*
* @param <SELF> 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.
* @param <ELEMENT> the type of elements of the "actual" value.
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Nicolas François
* @author Mikhail Mazursky
* @author Joel Costigliola
* @author Nicolas François
* @author Florent Biville
*/
public interface ObjectEnumerableAssert<SELF extends ObjectEnumerableAssert<SELF, ELEMENT>, ELEMENT>
extends EnumerableAssert<SELF, ELEMENT> {
/**
* Verifies that the actual group contains the given values, in any order.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
*
* // assertions will pass
* assertThat(abc).contains("b", "a");
* assertThat(abc).contains("b", "a", "b");
*
* // assertion will fail
* assertThat(abc).contains("d");</code></pre>
* <p>
* If you want to specify the elements to check with an {@link Iterable}, use {@link #containsAll(Iterable) containsAll(Iterable)} instead.
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain the given values.
*/
SELF contains(@SuppressWarnings("unchecked") ELEMENT... values);
/**
* Verifies that the actual group contains only the given values and nothing else, in any order and with possibly duplicates.
* <p>
* If you need to check exactly the elements and their duplicates use:
* <ul>
* <li>{@link #containsExactly(Object...) containsExactly(Object...)} if the order does matter</li>
* <li>{@link #containsExactlyInAnyOrder(Object...) containsExactlyInAnyOrder(Object...)} if the order does not matter</li>
* </ul>
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
*
* // assertions will pass as order does not matter
* assertThat(abc).containsOnly("c", "b", "a");
* // duplicates are ignored
* assertThat(abc).containsOnly("a", "a", "b", "c", "c");
* // ... on both actual and expected values
* assertThat(asList("a", "a", "b")).containsOnly("a", "b")
* .containsOnly("a", "a", "b", "b");
*
* // assertion will fail because "c" is missing in the given values
* assertThat(abc).containsOnly("a", "b");
* // assertion will fail because "d" is missing in abc (use isSubsetOf if you want this assertion to pass)
* assertThat(abc).containsOnly("a", "b", "c", "d");</code></pre>
* <p>
* If you need to check that actual is a subset of the given values, use {@link #isSubsetOf(Object...)}.
* <p>
* If you want to specify the elements to check with an {@link Iterable}, use {@link #containsOnlyElementsOf(Iterable) containsOnlyElementsOf(Iterable)} instead.
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain the given values, i.e. the actual group contains some
* or none of the given values, or the actual group contains more values than the given ones.
*/
SELF containsOnly(@SuppressWarnings("unchecked") ELEMENT... values);
/**
* Verifies that the actual group contains only null elements and nothing else.
* <p>
* Example:
* <pre><code class='java'> // assertion will pass
* Iterable<String> items = Arrays.asList(null, null, null);
* assertThat(items).containsOnlyNulls();
*
* // assertion will fail because items2 contains a not null element
* Iterable<String> items2 = Arrays.asList(null, null, "notNull");
* assertThat(items2).containsOnlyNulls();
*
* // assertion will fail since an empty iterable does not contain any element and therefore no null ones.
* Iterable<String> empty = new ArrayList<>();
* assertThat(empty).containsOnlyNulls();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group is empty or contains non null elements.
* @since 2.9.0 / 3.9.0
*/
SELF containsOnlyNulls();
/**
* Verifies that the actual group contains the given values only once.
* <p>
* Examples :
* <pre><code class='java'> // lists are used in the examples but it would also work with arrays
*
* // assertions will pass
* assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("winter");
* assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("coming", "winter");
*
* // assertions will fail
* assertThat(newArrayList("winter", "is", "coming")).containsOnlyOnce("Lannister");
* assertThat(newArrayList("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark");
* assertThat(newArrayList("Arya", "Stark", "daughter", "of", "Ned", "Stark")).containsOnlyOnce("Stark", "Lannister", "Arya");</code></pre>
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain the given values, i.e. the actual group contains some
* or none of the given values, or the actual group contains more than once these values.
*/
SELF containsOnlyOnce(@SuppressWarnings("unchecked") ELEMENT... values);
/**
* Verifies that the actual group contains exactly the given values and nothing else, <b>in order</b>.<br>
* This assertion should only be used with groups that have a consistent iteration order (i.e. don't use it with
* {@link HashSet}, prefer {@link #containsOnly(Object...)} in that case).
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertion will pass
* assertThat(elvesRings).containsExactly(vilya, nenya, narya);
*
* // assertion will fail as actual and expected order differ
* assertThat(elvesRings).containsExactly(nenya, vilya, narya);</code></pre>
* <p>
* If you want to specify the elements to check with an {@link Iterable}, use {@link #containsExactlyElementsOf(Iterable) containsExactlyElementsOf(Iterable)} instead.
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain the given values with same order, i.e. the actual group
* contains some or none of the given values, or the actual group contains more values than the given ones
* or values are the same but the order is not.
*/
SELF containsExactly(@SuppressWarnings("unchecked") ELEMENT... values);
/**
* Verifies that the actual group contains exactly the given values and nothing else, <b>in any order</b>.<br>
*
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya, vilya);
*
* // assertion will pass
* assertThat(elvesRings).containsExactlyInAnyOrder(vilya, vilya, nenya, narya);
*
* // assertion will fail as vilya is contained twice in elvesRings.
* assertThat(elvesRings).containsExactlyInAnyOrder(nenya, vilya, narya);</code></pre>
* <p>
* If you want to specify the elements to check with an {@link Iterable}, use {@link #containsExactlyInAnyOrderElementsOf(Iterable) containsExactlyInAnyOrderElementsOf(Iterable)} instead.
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain the given values, i.e. the actual group
* contains some or none of the given values, or the actual group contains more values than the given ones.
*/
SELF containsExactlyInAnyOrder(@SuppressWarnings("unchecked") ELEMENT... values);
/**
* Verifies that the actual group contains exactly the given values and nothing else, <b>in any order</b>.<br>
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya, vilya);
* Iterable<Ring> elvesRingsSomeMissing = newArrayList(vilya, nenya, narya);
* Iterable<Ring> elvesRingsDifferentOrder = newArrayList(nenya, narya, vilya, vilya);
*
* // assertion will pass
* assertThat(elvesRings).containsExactlyInAnyOrder(elvesRingsDifferentOrder);
*
* // assertion will fail as vilya is contained twice in elvesRings.
* assertThat(elvesRings).containsExactlyInAnyOrder(elvesRingsSomeMissing);</code></pre>
* <p>
* If you want to directly specify the elements to check, use {@link #containsExactlyInAnyOrder(Object...) containsExactlyInAnyOrder(Object...)} instead.
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain the given values, i.e. the actual group
* contains some or none of the given values, or the actual group contains more values than the given ones.
* @since 2.9.0 / 3.9.0
*/
SELF containsExactlyInAnyOrderElementsOf(Iterable<? extends ELEMENT> values);
/**
* Verifies that the actual group contains the given sequence in the correct order and <b>without extra values between the sequence values</b>.
* <p>
* Use {@link #containsSubsequence(Object...)} to allow values between the expected sequence values.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass
* assertThat(elvesRings).containsSequence(vilya, nenya)
* .containsSequence(nenya, narya);
*
* // assertions will fail, the elements order is correct but there is a value between them (nenya)
* assertThat(elvesRings).containsSequence(vilya, narya);
* assertThat(elvesRings).containsSequence(nenya, vilya);</code></pre>
* <p>
* If you want to specify the sequence to check with an {@link Iterable}, use {@link #containsSequence(Iterable) containsSequence(Iterable)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group does not contain the given sequence.
*/
SELF containsSequence(@SuppressWarnings("unchecked") ELEMENT... sequence);
/**
* Verifies that the actual group contains the given sequence in the correct order and <b>without extra values between the sequence values</b>.
* <p>
* Use {@link #containsSubsequence(Iterable)} to allow values between the expected sequence values.
* <p>
* Example:
* <pre><code class='java'> Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass
* assertThat(elvesRings).containsSequence(newArrayList(vilya, nenya))
* .containsSequence(newArrayList(nenya, narya));
*
* // assertions will fail, the elements order is correct but there is a value between them (nenya)
* assertThat(elvesRings).containsSequence(newArrayList(vilya, narya));
* assertThat(elvesRings).containsSequence(newArrayList(nenya, vilya));</code></pre>
* <p>
* If you want to directly specify the elements of the sequence to check, use {@link #containsSequence(Object...) containsSequence(Object...)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group does not contain the given sequence.
*/
SELF containsSequence(Iterable<? extends ELEMENT> sequence);
/**
* Verifies that the actual group does not contain the given sequence,
* a sequence is defined by an ordered group of values <b>without extra values between them</b>.
* <p>
* Use {@link #doesNotContainSubsequence(Object...)} to also ensure the sequence does not exist with values between the expected sequence values.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass, the elements order is correct but there is a value between them (nenya)
* assertThat(elvesRings).doesNotContainSequence(vilya, narya)
* .doesNotContainSequence(nenya, vilya);
*
* // assertions will fail
* assertThat(elvesRings).doesNotContainSequence(vilya, nenya);
* assertThat(elvesRings).doesNotContainSequence(nenya, narya);</code></pre>
* <p>
* If you want to specify the sequence not to find with an {@link Iterable}, use {@link #doesNotContainSequence(Iterable) doesNotContainSequence(Iterable)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group contains the given sequence.
*/
SELF doesNotContainSequence(@SuppressWarnings("unchecked") ELEMENT... sequence);
/**
* Verifies that the actual group does not contain the given sequence,
* a sequence is defined by an ordered group of values <b>without extra values between them</b>.
* <p>
* Use {@link #doesNotContainSubsequence(Iterable)} to also ensure the sequence does not exist with values between the sequence values.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass, the elements order is correct but there is a value between them (nenya)
* assertThat(elvesRings).doesNotContainSequence(newArrayList(vilya, narya))
* .doesNotContainSequence(newArrayList(nenya, vilya));
*
* // assertions will fail
* assertThat(elvesRings).doesNotContainSequence(newArrayList(vilya, nenya));
* assertThat(elvesRings).doesNotContainSequence(newArrayList(nenya, narya));</code></pre>
* <p>
* If you want to directly specify the elements of the sequence not to find, use {@link #doesNotContainSequence(Object...) doesNotContainSequence(Object...)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group contains the given sequence.
*/
SELF doesNotContainSequence(Iterable<? extends ELEMENT> sequence);
/**
* Verifies that the actual group contains the given subsequence in the correct order (possibly with other values between them).
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass
* assertThat(elvesRings).containsSubsequence(vilya, nenya)
* .containsSubsequence(vilya, narya);
*
* // assertion will fail
* assertThat(elvesRings).containsSubsequence(nenya, vilya);</code></pre>
* <p>
* If you want to specify the elements of the subsequence to check with an {@link Iterable}, use {@link #containsSubsequence(Iterable) containsSubsequence(Iterable)} instead.
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group does not contain the given subsequence.
*/
SELF containsSubsequence(@SuppressWarnings("unchecked") ELEMENT... sequence);
/**
* Verifies that the actual group contains the given subsequence in the correct order (possibly with other values between them).
* <p>
* Example:
* <pre><code class='java'> Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass
* assertThat(elvesRings).containsSubsequence(newArrayList(vilya, nenya))
* .containsSubsequence(newArrayList(vilya, narya));
*
* // assertion will fail
* assertThat(elvesRings).containsSubsequence(newArrayList(nenya, vilya));</code></pre>
* <p>
* If you want to directly specify the subsequence to check, use {@link #containsSubsequence(Object...) containsSubsequence(Object...)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group does not contain the given subsequence.
*/
SELF containsSubsequence(Iterable<? extends ELEMENT> sequence);
/**
* Verifies that the actual group does not contain the given subsequence,
* a subsequence is defined by an ordered group of values <b>with possibly extra values between them</b>.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass
* assertThat(elvesRings).doesNotContainSubsequence(nenya, vilya)
* .doesNotContainSubsequence(narya, vilya);
*
* // assertion will fail
* assertThat(elvesRings).doesNotContainSubsequence(vilya, nenya);
* assertThat(elvesRings).doesNotContainSubsequence(vilya, narya);</code></pre>
* <p>
* If you want to specify the subsequence not to find with an {@link Iterable}, use {@link #doesNotContainSubsequence(Iterable) doesNotContainSubsequence(Iterable)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group contains the given subsequence.
*/
SELF doesNotContainSubsequence(@SuppressWarnings("unchecked") ELEMENT... sequence);
/**
* Verifies that the actual group does not contain the given subsequence,
* a subsequence is defined by an ordered group of values <b>with possibly extra values between them</b>.
* <p>
* Example:
* <pre><code class='java'> Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
*
* // assertions will pass
* assertThat(elvesRings).doesNotContainSubsequence(newArrayList(nenya, vilya));
* .doesNotContainSubsequence(newArrayList(narya, vilya));
*
* // assertion will fail
* assertThat(elvesRings).doesNotContainSubsequence(newArrayList(vilya, nenya));
* assertThat(elvesRings).doesNotContainSubsequence(newArrayList(vilya, narya));</code></pre>
* <p>
* If you want to directly specify the elements of the subsequence not to find, use {@link #doesNotContainSubsequence(Object...) doesNotContainSubsequence(Object...)} instead.
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the given array is {@code null}.
* @throws AssertionError if the actual group contains the given subsequence.
*/
SELF doesNotContainSubsequence(Iterable<? extends ELEMENT> sequence);
/**
* Verifies that the actual group does not contain the given values.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<String> abc = newArrayList("a", "b", "c");
*
* // assertions will pass
* assertThat(abc).doesNotContain("d")
* .doesNotContain("d", "e");
*
* // assertions will fail
* assertThat(abc).doesNotContain("a");
* assertThat(abc).doesNotContain("a", "b");
* assertThat(abc).doesNotContain("c", "d");</code></pre>
* <p>
* If you want to specify the elements not to find with an {@link Iterable}, use {@link #doesNotContainAnyElementsOf(Iterable) doesNotContainAnyElementsOf(Iterable)} instead.
*
* @param values the given values.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group contains any of the given values.
*/
SELF doesNotContain(@SuppressWarnings("unchecked") ELEMENT... values);
/**
* Verifies that the actual group does not contain duplicates.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> lotsOfAs = newArrayList("a", "a", "a");
*
* // assertion will pass
* assertThat(abc).doesNotHaveDuplicates();
*
* // assertion will fail
* assertThat(lotsOfAs).doesNotHaveDuplicates();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group contains duplicates.
*/
SELF doesNotHaveDuplicates();
/**
* Verifies that the actual group starts with the given sequence of objects, without any other objects between them.
* Similar to <code>{@link #containsSequence(Object...)}</code>, but it also verifies that the first element in the
* sequence is also first element of the actual group.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<String> abc = newArrayList("a", "b", "c");
*
* // assertions will pass
* assertThat(abc).startsWith("a")
* .startsWith("a", "b");
*
* // assertion will fail
* assertThat(abc).startsWith("c");</code></pre>
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not start with the given sequence of objects.
*/
SELF startsWith(@SuppressWarnings("unchecked") ELEMENT... sequence);
/**
* Verifies that the actual group ends with the given sequence of objects, without any other objects between them.
* Similar to <code>{@link #containsSequence(Object...)}</code>, but it also verifies that the last element in the
* sequence is also last element of the actual group.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<String> abc = newArrayList("a", "b", "c");
*
* // assertions will pass
* assertThat(abc).endsWith("c")
* .endsWith("b", "c");
*
* // assertions will fail
* assertThat(abc).endsWith("a");
* assertThat(abc).endsWith("a", "b");</code></pre>
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws IllegalArgumentException if the given argument is an empty array.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not end with the given sequence of objects.
*/
SELF endsWith(ELEMENT first, @SuppressWarnings("unchecked") ELEMENT... sequence);
/**
* Verifies that the actual group ends with the given sequence of objects, without any other objects between them.
* Similar to <code>{@link #containsSequence(Object...)}</code>, but it also verifies that the last element in the
* sequence is also last element of the actual group.
* <p>
* Example:
* <pre><code class='java'> // an Iterable is used in the example but it would also work with an array
* Iterable<String> abc = newArrayList("a", "b", "c");
*
* // assertions will pass
* assertThat(abc).endsWith(new String[0])
* .endsWith(new String[] {"c"})
* .endsWith(new String[] {"b", "c"});
*
* // assertions will fail
* assertThat(abc).endsWith(new String[] {"a"});
* assertThat(abc).endsWith(new String[] {"a", "b"});</code></pre>
*
* @param sequence the sequence of objects to look for.
* @return this assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not end with the given sequence of objects.
*/
SELF endsWith(ELEMENT[] sequence);
/**
* Verifies that the actual group contains at least a null element.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> abNull = newArrayList("a", "b", null);
*
* // assertion will pass
* assertThat(abNull).containsNull();
*
* // assertion will fail
* assertThat(abc).containsNull();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain a null element.
*/
SELF containsNull();
/**
* Verifies that the actual group does not contain null elements.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> abNull = newArrayList("a", "b", null);
*
* // assertion will pass
* assertThat(abc).doesNotContainNull();
*
* // assertion will fail
* assertThat(abNull).doesNotContainNull();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group contains a null element.
*/
SELF doesNotContainNull();
/**
* Verifies that each element value satisfies the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> abcc = newArrayList("a", "b", "cc");
*
* Condition<String> singleCharacterString = new Condition<String>() {
* public boolean matches(String value) {
* return value.length() == 1;
* }
* });
*
* // assertion will pass
* assertThat(abc).are(singleCharacterString);
*
* // assertion will fail
* assertThat(abcc).are(singleCharacterString);</code></pre>
*
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element cannot be cast to T.
* @throws AssertionError if one or more elements do not satisfy the given condition.
*/
SELF are(Condition<? super ELEMENT> condition);
/**
* Verifies that each element value does not satisfy the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> abcc = newArrayList("a", "b", "cc");
*
* Condition<String> moreThanOneCharacter = new Condition<String>() {
* public boolean matches(String value) {
* return value.length() > 1;
* }
* });
*
* // assertion will pass
* assertThat(abc).areNot(moreThanOneCharacter);
*
* // assertion will fail
* assertThat(abcc).areNot(moreThanOneCharacter);</code></pre>
*
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element cannot be cast to T.
* @throws AssertionError if one or more elements satisfy the given condition.
*/
SELF areNot(Condition<? super ELEMENT> condition);
/**
* Verifies that all elements satisfy the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> abcc = newArrayList("a", "b", "cc");
*
* Condition<String> onlyOneCharacter = new Condition<String>() {
* public boolean matches(String value) {
* return value.length() == 1;
* }
* });
*
* // assertion will pass
* assertThat(abc).have(onlyOneCharacter);
*
* // assertion will fail
* assertThat(abcc).have(onlyOneCharacter);</code></pre>
*
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element cannot be cast to T.
* @throws AssertionError if one or more elements do not satisfy the given condition.
*/
SELF have(Condition<? super ELEMENT> condition);
/**
* Verifies that all elements do not satisfy the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = newArrayList("a", "b", "c");
* Iterable<String> abcc = newArrayList("a", "b", "cc");
*
* Condition<String> moreThanOneCharacter = new Condition<String>() {
* public boolean matches(String value) {
* return value.length() > 1;
* }
* });
*
* // assertion will pass
* assertThat(abc).doNotHave(moreThanOneCharacter);
*
* // assertion will fail
* assertThat(abcc).doNotHave(moreThanOneCharacter);</code></pre>
*
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element cannot be cast to T.
* @throws AssertionError if one or more elements satisfy the given condition.
*/
SELF doNotHave(Condition<? super ELEMENT> condition);
/**
* Verifies that there are <b>at least</b> <i>n</i> elements in the actual group satisfying the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<Integer> oneTwoThree = newArrayList(1, 2, 3);
*
* Condition<Integer> oddNumber = new Condition<Integer>() {
* public boolean matches(Integer value) {
* return value % 2 == 1;
* }
* });
*
* // assertion will pass
* oneTwoThree.areAtLeast(2, oddNumber);
*
* // assertion will fail
* oneTwoThree.areAtLeast(3, oddNumber);</code></pre>
*
* @param n the minimum number of times the condition should be verified.
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element can not be cast to T.
* @throws AssertionError if the number of elements satisfying the given condition is < n.
*/
SELF areAtLeast(int n, Condition<? super ELEMENT> condition);
/**
* Verifies that there is <b>at least <i>one</i></b> element in the actual group satisfying the given condition.
* <p>
* This method is an alias for {@code areAtLeast(1, condition)}.
* <p>
* Example:
* <pre><code class='java'> // jedi is a Condition<String>
* assertThat(newLinkedHashSet("Luke", "Solo", "Leia")).areAtLeastOne(jedi);</code></pre>
*
* @param condition the given condition.
* @return {@code this} assertion object.
* @see #haveAtLeast(int, Condition)
*/
SELF areAtLeastOne(Condition<? super ELEMENT> condition);
/**
* Verifies that there are <b>at most</b> <i>n</i> elements in the actual group satisfying the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<Integer> oneTwoThree = newArrayList(1, 2, 3);
*
* Condition<Integer> oddNumber = new Condition<Integer>() {
* public boolean matches(Integer value) {
* return value % 2 == 1;
* }
* });
*
* // assertions will pass
* oneTwoThree.areAtMost(2, oddNumber)
* .areAtMost(3, oddNumber);
*
* // assertion will fail
* oneTwoThree.areAtMost(1, odd);</code></pre>
*
* @param n the number of times the condition should be at most verified.
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element cannot be cast to T.
* @throws AssertionError if the number of elements satisfying the given condition is > n.
*/
SELF areAtMost(int n, Condition<? super ELEMENT> condition);
/**
* Verifies that there are <b>exactly</b> <i>n</i> elements in the actual group satisfying the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<Integer> oneTwoThree = newArrayList(1, 2, 3);
*
* Condition<Integer> odd = new Condition<Integer>() {
* public boolean matches(Integer value) {
* return value % 2 == 1;
* }
* });
*
* // assertion will pass
* oneTwoThree.areExactly(2, odd);
*
* // assertions will fail
* oneTwoThree.areExactly(1, odd);
* oneTwoThree.areExactly(3, odd);</code></pre>
*
* @param n the exact number of times the condition should be verified.
* @param condition the given condition.
* @return {@code this} object.
* @throws NullPointerException if the given condition is {@code null}.
* @throws AssertionError if an element cannot be cast to T.
* @throws AssertionError if the number of elements satisfying the given condition is ≠ n.
*/
SELF areExactly(int n, Condition<? super ELEMENT> condition);
/**
* Verifies that there is <b>at least <i>one</i></b> element in the actual group satisfying the given condition.
* <p>
* This method is an alias for {@code haveAtLeast(1, condition)}.
* <p>
* Example:
* <pre><code class='java'> List<BasketBallPlayer> bullsPlayers = newArrayList(noah, rose);
*
* // potentialMvp is a Condition<BasketBallPlayer>
* assertThat(bullsPlayers).haveAtLeastOne(potentialMvp);</code></pre>
*
* @param condition the given condition.
* @return {@code this} assertion object.
* @see #haveAtLeast(int, Condition)
*/
SELF haveAtLeastOne(Condition<? super ELEMENT> condition);
/**
* Verifies that there are <b>at least <i>n</i></b> elements in the actual group satisfying the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<Integer> oneTwoThree = newArrayList(1, 2, 3);
*
* Condition<Integer> oddNumber = new Condition<Integer>() {
* public boolean matches(Integer value) {
* return value % 2 == 1;
* }
* });
*
* // assertion will pass
* oneTwoThree.haveAtLeast(2, oddNumber);
*
* // assertion will fail
* oneTwoThree.haveAtLeast(3, oddNumber);</code></pre>
*
* This method is an alias for {@link #areAtLeast(int, Condition)}.
*
* @param n the minimum number of times the condition must hold.
* @param condition the given condition.
* @return {@code this} assertion object.
*/
SELF haveAtLeast(int n, Condition<? super ELEMENT> condition);
/**
* Verifies that there are <b>at most</b> <i>n</i> elements in the actual group satisfying the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<Integer> oneTwoThree = newArrayList(1, 2, 3);
*
* Condition<Integer> oddNumber = new Condition<Integer>() {
* public boolean matches(Integer value) {
* return value % 2 == 1;
* }
* });
*
* // assertions will pass
* oneTwoThree.haveAtMost(2, oddNumber);
* oneTwoThree.haveAtMost(3, oddNumber);
*
* // assertion will fail
* oneTwoThree.haveAtMost(1, odd);</code></pre>
*
* This method is an alias {@link #areAtMost(int, Condition)}.
*
* @param n the maximum number of times the condition must hold.
* @param condition the given condition.
* @return {@code this} assertion object.
*/
SELF haveAtMost(int n, Condition<? super ELEMENT> condition);
/**
* Verifies that there are <b>exactly</b> <i>n</i> elements in the actual group satisfying the given condition.
* <p>
* Example:
* <pre><code class='java'> Iterable<Integer> oneTwoThree = newArrayList(1, 2, 3);
*
* Condition<Integer> oddNumber = new Condition<Integer>() {
* public boolean matches(Integer value) {
* return value % 2 == 1;
* }
* });
*
* // assertion will pass
* oneTwoThree.haveExactly(2, oddNumber);
*
* // assertions will fail
* oneTwoThree.haveExactly(1, oddNumber);
* oneTwoThree.haveExactly(3, oddNumber);</code></pre>
*
* This method is an alias {@link #areExactly(int, Condition)}.
*
* @param n the exact number of times the condition must hold.
* @param condition the given condition.
* @return {@code this} assertion object.
*/
SELF haveExactly(int n, Condition<? super ELEMENT> condition);
/**
* Verifies that the actual group contains all the elements of given {@code Iterable}, in any order.
* <p>
* Example:
* <pre><code class='java'> Iterable<String> abc = Arrays.asList("a", "b", "c");
*
* // assertions will pass
* assertThat(abc).containsAll(Arrays.asList("b", "c"))
* .containsAll(Arrays.asList("a", "b", "c"));
*
* // assertions will fail
* assertThat(abc).containsAll(Arrays.asList("d"));
* assertThat(abc).containsAll(Arrays.asList("a", "b", "c", "d"));</code></pre>
* <p>
* If you want to directly specify the elements to check, use {@link #contains(Object...) contains(Object...)} instead.
*
* @param iterable the given {@code Iterable} we will get elements from.
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if the actual group does not contain all the elements of given {@code Iterable}.
*/
SELF containsAll(Iterable<? extends ELEMENT> iterable);
/**
* Verifies that all elements of the actual group are instances of the given types.
* <p>
* Example:
* <pre><code class='java'> Iterable<? extends Object> objects = Arrays.asList("foo", new StringBuilder());
*
* // assertions will pass
* assertThat(objects).hasOnlyElementsOfTypes(CharSequence.class)
* .hasOnlyElementsOfTypes(String.class, StringBuilder.class);
*
* // assertions will fail
* assertThat(objects).hasOnlyElementsOfTypes(Number.class);
* assertThat(objects).hasOnlyElementsOfTypes(String.class, Number.class);
* assertThat(objects).hasOnlyElementsOfTypes(String.class);</code></pre>
*
* @param types the expected classes and interfaces
* @return {@code this} assertion object.
* @throws NullPointerException if the given argument is {@code null}.
* @throws AssertionError if the actual group is {@code null}.
* @throws AssertionError if not all elements of the actual group are instances of one of the given types
* @since 2.7.0 / 3.7.0
*/
SELF hasOnlyElementsOfTypes(Class<?>... types);
/**
* Verifies that at least one element in the actual {@code Object} group has the specified type (matching
* includes subclasses of the given type).
* <p>
* Example:
* <pre><code class='java'> Number[] numbers = { 2, 6L, 8.0 };
*
* // successful assertion:
* assertThat(numbers).hasAtLeastOneElementOfType(Long.class);
*
* // assertion failure:
* assertThat(numbers).hasAtLeastOneElementOfType(Float.class);</code></pre>
*
* @param expectedType the expected type.
* @return this assertion object.
* @throws NullPointerException if the given type is {@code null}.
* @throws AssertionError if the actual {@code Object} group does not have any elements of the given type.
*/
SELF hasAtLeastOneElementOfType(Class<?> expectedType);
/**
* Verifies that all the elements in the actual {@code Object} group belong to the specified type (matching includes
* subclasses of the given type).
* <p>
* Example:
* <pre><code class='java'> Number[] numbers = { 2, 6, 8 };
*
* // successful assertion:
* assertThat(numbers).hasOnlyElementsOfType(Integer.class);
*
* // assertion failure:
* assertThat(numbers).hasOnlyElementsOfType(Long.class);</code></pre>
*
* @param expectedType the expected type.
* @return this assertion object.
* @throws NullPointerException if the given type is {@code null}.
* @throws AssertionError if one element is not of the expected type.
*/
SELF hasOnlyElementsOfType(Class<?> expectedType);
/**
* Verifies that all the elements in the actual {@code Object} group do not belong to the specified types (including subclasses).
* <p>
* Example:
* <pre><code class='java'> Number[] numbers = { 2, 6, 8.0 };
*
* // successful assertion:
* assertThat(numbers).doesNotHaveAnyElementsOfTypes(Long.class, Float.class);
*
* // assertion failure:
* assertThat(numbers).doesNotHaveAnyElementsOfTypes(Long.class, Integer.class);</code></pre>
*
* @param unexpectedTypes the not expected types.
* @return this assertion object.
* @throws NullPointerException if the given type is {@code null}.