/
Assertions.java
3252 lines (3047 loc) · 130 KB
/
Assertions.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-2021 the original author or authors.
*/
package org.assertj.core.api;
import static org.assertj.core.configuration.ConfigurationProvider.CONFIGURATION_PROVIDER;
import static org.assertj.core.data.Percentage.withPercentage;
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
import java.io.UncheckedIOException;
import java.math.BigDecimal;
import java.math.BigInteger;
import java.net.URI;
import java.net.URL;
import java.nio.charset.Charset;
import java.nio.file.Path;
import java.text.DateFormat;
import java.time.Duration;
import java.time.Instant;
import java.time.LocalDate;
import java.time.LocalDateTime;
import java.time.LocalTime;
import java.time.OffsetDateTime;
import java.time.OffsetTime;
import java.time.Period;
import java.time.ZonedDateTime;
import java.time.temporal.TemporalUnit;
import java.util.Collection;
import java.util.Date;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Optional;
import java.util.OptionalDouble;
import java.util.OptionalInt;
import java.util.OptionalLong;
import java.util.Spliterator;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CompletionStage;
import java.util.concurrent.Future;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicInteger;
import java.util.concurrent.atomic.AtomicIntegerArray;
import java.util.concurrent.atomic.AtomicIntegerFieldUpdater;
import java.util.concurrent.atomic.AtomicLong;
import java.util.concurrent.atomic.AtomicLongArray;
import java.util.concurrent.atomic.AtomicLongFieldUpdater;
import java.util.concurrent.atomic.AtomicMarkableReference;
import java.util.concurrent.atomic.AtomicReference;
import java.util.concurrent.atomic.AtomicReferenceArray;
import java.util.concurrent.atomic.AtomicReferenceFieldUpdater;
import java.util.concurrent.atomic.AtomicStampedReference;
import java.util.concurrent.atomic.LongAdder;
import java.util.function.Consumer;
import java.util.function.DoublePredicate;
import java.util.function.Function;
import java.util.function.IntPredicate;
import java.util.function.LongPredicate;
import java.util.function.Predicate;
import java.util.stream.DoubleStream;
import java.util.stream.IntStream;
import java.util.stream.LongStream;
import java.util.stream.Stream;
import org.assertj.core.api.ThrowableAssert.ThrowingCallable;
import org.assertj.core.api.filter.FilterOperator;
import org.assertj.core.api.filter.Filters;
import org.assertj.core.api.filter.InFilter;
import org.assertj.core.api.filter.NotFilter;
import org.assertj.core.api.filter.NotInFilter;
import org.assertj.core.condition.AllOf;
import org.assertj.core.condition.AnyOf;
import org.assertj.core.condition.DoesNotHave;
import org.assertj.core.condition.Not;
import org.assertj.core.configuration.Configuration;
import org.assertj.core.configuration.ConfigurationProvider;
import org.assertj.core.data.Index;
import org.assertj.core.data.MapEntry;
import org.assertj.core.data.Offset;
import org.assertj.core.data.Percentage;
import org.assertj.core.data.TemporalUnitLessThanOffset;
import org.assertj.core.data.TemporalUnitOffset;
import org.assertj.core.data.TemporalUnitWithinOffset;
import org.assertj.core.description.Description;
import org.assertj.core.groups.Properties;
import org.assertj.core.groups.Tuple;
import org.assertj.core.presentation.BinaryRepresentation;
import org.assertj.core.presentation.HexadecimalRepresentation;
import org.assertj.core.presentation.Representation;
import org.assertj.core.presentation.StandardRepresentation;
import org.assertj.core.presentation.UnicodeRepresentation;
import org.assertj.core.util.CanIgnoreReturnValue;
import org.assertj.core.util.CheckReturnValue;
import org.assertj.core.util.Files;
import org.assertj.core.util.URLs;
import org.assertj.core.util.introspection.FieldSupport;
import org.assertj.core.util.introspection.Introspection;
/**
* Entry point for assertion methods for different types. Each method in this class is a static factory for a
* type-specific assertion object.
* <p>
* For example:
*
* <pre><code class='java'> int removed = employees.removeFired();
* {@link Assertions#assertThat(int) assertThat}(removed).{@link IntegerAssert#isZero isZero}();
*
* List<Employee> newEmployees = employees.hired(TODAY);
* {@link Assertions#assertThat(Iterable) assertThat}(newEmployees).{@link IterableAssert#hasSize(int) hasSize}(6);</code></pre>
* <p>
* This class only contains all <code>assertThat</code> methods, if you have ambiguous method compilation error, use either {@link AssertionsForClassTypes} or {@link AssertionsForInterfaceTypes}
* and if you need both, fully qualify you assertThat method.
* <p>
* Java 8 is picky when choosing the right <code>assertThat</code> method if the object under test is generic and bounded,
* for example if foo is instance of T that extends Exception, java 8 will complain that it can't resolve
* the proper <code>assertThat</code> method (normally <code>assertThat(Throwable)</code> as foo might implement an interface like List,
* if that occurred <code>assertThat(List)</code> would also be a possible choice - thus confusing java 8.
* <p>
* This why {@link Assertions} have been split in {@link AssertionsForClassTypes} and {@link AssertionsForInterfaceTypes}
* (see http://stackoverflow.com/questions/29499847/ambiguous-method-in-java-8-why).
*
* @author Alex Ruiz
* @author Yvonne Wang
* @author David DIDIER
* @author Ted Young
* @author Joel Costigliola
* @author Matthieu Baechler
* @author Mikhail Mazursky
* @author Nicolas François
* @author Julien Meddah
* @author William Bakker
* @author William Delanoue
*/
@CheckReturnValue
public class Assertions implements InstanceOfAssertFactories {
static {
// just call a method to trigger loading the ConfigurationProvider and thus look for any registered Configuration
ConfigurationProvider.class.hashCode();
}
/**
* Creates a new <code>{@link Assertions}</code>.
*/
protected Assertions() {}
/**
* Create assertion for {@link Predicate}.
*
* @param actual the actual value.
* @param <T> the type of the value contained in the {@link Predicate}.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static <T> PredicateAssert<T> assertThat(Predicate<T> actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}
/**
* Create assertion for {@link IntPredicate}.
*
* @param actual the actual value.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static IntPredicateAssert assertThat(IntPredicate actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}
/**
* Create assertion for {@link LongPredicate}.
*
* @param actual the actual value.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static LongPredicateAssert assertThat(LongPredicate actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}
/**
* Create assertion for {@link DoublePredicate}.
*
* @param actual the actual value.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static DoublePredicateAssert assertThat(DoublePredicate actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.concurrent.CompletableFuture}.
*
* @param actual the actual value.
* @param <RESULT> the type of the value contained in the {@link java.util.concurrent.CompletableFuture}.
*
* @return the created assertion object.
*/
public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletableFuture<RESULT> actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.concurrent.CompletionStage} by converting it to a {@link CompletableFuture} and returning a {@link CompletableFutureAssert}.
* <p>
* If the given {@link java.util.concurrent.CompletionStage} is null, the {@link CompletableFuture} in the returned {@link CompletableFutureAssert} will also be null.
*
* @param actual the actual value.
* @param <RESULT> the type of the value contained in the {@link java.util.concurrent.CompletionStage}.
*
* @return the created assertion object.
*/
public static <RESULT> CompletableFutureAssert<RESULT> assertThat(CompletionStage<RESULT> actual) {
return AssertionsForInterfaceTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.Optional}.
*
* @param actual the actual value.
* @param <VALUE> the type of the value contained in the {@link java.util.Optional}.
*
* @return the created assertion object.
*/
public static <VALUE> OptionalAssert<VALUE> assertThat(Optional<VALUE> actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.OptionalDouble}.
*
* @param actual the actual value.
*
* @return the created assertion object.
*/
public static OptionalDoubleAssert assertThat(OptionalDouble actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.OptionalInt}.
*
* @param actual the actual value.
*
* @return the created assertion object.
*/
public static OptionalIntAssert assertThat(OptionalInt actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.OptionalInt}.
*
* @param actual the actual value.
*
* @return the created assertion object.
*/
public static OptionalLongAssert assertThat(OptionalLong actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link BigDecimalAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBigDecimalAssert<?> assertThat(BigDecimal actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link BigIntegerAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 2.7.0 / 3.7.0
*/
public static AbstractBigIntegerAssert<?> assertThat(BigInteger actual) {
return new BigIntegerAssert(actual);
}
/**
* Creates a new instance of <code>{@link UriAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractUriAssert<?> assertThat(URI actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link UrlAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractUrlAssert<?> assertThat(URL actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link BooleanAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBooleanAssert<?> assertThat(boolean actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link BooleanAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBooleanAssert<?> assertThat(Boolean actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link BooleanArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBooleanArrayAssert<?> assertThat(boolean[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Boolean2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Boolean2DArrayAssert assertThat(boolean[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ByteAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractByteAssert<?> assertThat(byte actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ByteAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractByteAssert<?> assertThat(Byte actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ByteArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractByteArrayAssert<?> assertThat(byte[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Byte2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Byte2DArrayAssert assertThat(byte[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link CharacterAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharacterAssert<?> assertThat(char actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link CharArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharArrayAssert<?> assertThat(char[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link CharArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Char2DArrayAssert assertThat(char[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link CharacterAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharacterAssert<?> assertThat(Character actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ClassAssert}</code>
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static ClassAssert assertThat(Class<?> actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link DoubleAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDoubleAssert<?> assertThat(double actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link DoubleAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDoubleAssert<?> assertThat(Double actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link DoubleArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDoubleArrayAssert<?> assertThat(double[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Double2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Double2DArrayAssert assertThat(double[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link FileAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFileAssert<?> assertThat(File actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.util.concurrent.Future}.
*
* @param actual the actual value.
* @param <RESULT> the type of the value contained in the {@link java.util.concurrent.Future}.
*
* @return the created assertion object.
* @since 2.7.0 / 3.7.0
*/
public static <RESULT> FutureAssert<RESULT> assertThat(Future<RESULT> actual) {
return new FutureAssert<>(actual);
}
/**
* Creates a new instance of <code>{@link InputStreamAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractInputStreamAssert<?, ? extends InputStream> assertThat(InputStream actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link FloatAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFloatAssert<?> assertThat(float actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link FloatAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFloatAssert<?> assertThat(Float actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link FloatArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFloatArrayAssert<?> assertThat(float[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link IntegerAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractIntegerAssert<?> assertThat(int actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link IntArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractIntArrayAssert<?> assertThat(int[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Int2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Int2DArrayAssert assertThat(int[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Float2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Float2DArrayAssert assertThat(float[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link IntegerAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractIntegerAssert<?> assertThat(Integer actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link FactoryBasedNavigableIterableAssert}</code> allowing to navigate to any {@code Iterable} element
* in order to perform assertions on it.
* <p>
* Navigational methods provided:<ul>
* <li>{@link AbstractIterableAssert#first() first()}</li>
* <li>{@link AbstractIterableAssert#last() last()}</li>
* <li>{@link AbstractIterableAssert#elements(int...) elements(index...)}</li>
* </ul>
* <p>
* The available assertions after navigating to an element depend on the {@code ELEMENT_ASSERT} parameter of the given
* {@link AssertFactory AssertFactory<ELEMENT, ELEMENT_ASSERT>} (AssertJ can't figure it out because of Java type erasure).
* <p>
* Example with {@code String} element assertions:
* <pre><code class='java'> Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
*
* // build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)
* AssertFactory<String, StringAssert> stringAssertFactory = new AssertFactory<String, StringAssert>() {
* {@literal @}Override
* public StringAssert createAssert(String string) {
* return new StringAssert(string);
* }
* };
*
* // assertion succeeds with String assertions chained after first()
* assertThat(hobbits, stringAssertFactory).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* @param <ACTUAL> The actual type
* @param <ELEMENT> The actual elements type
* @param <ELEMENT_ASSERT> The actual elements AbstractAssert type
* @param actual the actual value.
* @param assertFactory the factory used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
*/
//@format:off
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(Iterable<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
return AssertionsForInterfaceTypes.assertThat(actual, assertFactory);
}
/**
* Creates a new instance of <code>{@link ClassBasedNavigableIterableAssert}</code> allowing to navigate to any {@code Iterable} element
* in order to perform assertions on it.
* <p>
* Navigational methods provided:<ul>
* <li>{@link AbstractIterableAssert#first() first()}</li>
* <li>{@link AbstractIterableAssert#last() last()}</li>
* <li>{@link AbstractIterableAssert#element(int) element(index)}</li>
* <li>{@link AbstractIterableAssert#elements(int...) element(int...)}</li>
* </ul>
* <p>
* The available assertions after navigating to an element depend on the given {@code assertClass}
* (AssertJ can't find the element assert type by itself because of Java type erasure).
* <p>
* Example with {@code String} element assertions:
* <pre><code class='java'> Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
*
* // assertion succeeds with String assertions chained after first()
* assertThat(hobbits, StringAssert.class).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* @param <ACTUAL> The actual type
* @param <ELEMENT> The actual elements type
* @param <ELEMENT_ASSERT> The actual elements AbstractAssert type
* @param actual the actual value.
* @param assertClass the class used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
*/
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(ACTUAL actual,
Class<ELEMENT_ASSERT> assertClass) {
return AssertionsForInterfaceTypes.assertThat(actual, assertClass);
}
/**
* Creates a new instance of <code>{@link FactoryBasedNavigableListAssert}</code> allowing to navigate to any {@code List} element
* in order to perform assertions on it.
* <p>
* Navigational methods provided:<ul>
* <li>{@link AbstractIterableAssert#first() first()}</li>
* <li>{@link AbstractIterableAssert#last() last()}</li>
* <li>{@link AbstractIterableAssert#element(int) element(index)}</li>
* <li>{@link AbstractIterableAssert#elements(int...) elements(int...)}</li>
* </ul>
* <p>
* The available assertions after navigating to an element depend on the {@code ELEMENT_ASSERT} parameter of the given
* {@link AssertFactory AssertFactory<ELEMENT, ELEMENT_ASSERT>} (AssertJ can't figure it out because of Java type erasure).
* <p>
* Example with {@code String} element assertions:
* <pre><code class='java'> List<String> hobbits = newArrayList("frodo", "sam", "pippin");
*
* // build an AssertFactory for StringAssert (much nicer with Java 8 lambdas)
* AssertFactory<String, StringAssert> stringAssertFactory = new AssertFactory<String, StringAssert>() {
* {@literal @}Override
* public StringAssert createAssert(String string) {
* return new StringAssert(string);
* }
* };
*
* // assertion succeeds with String assertions chained after first()
* assertThat(hobbits, stringAssertFactory).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* @param <ACTUAL> The actual type
* @param <ELEMENT> The actual elements type
* @param <ELEMENT_ASSERT> The actual elements AbstractAssert type
* @param actual the actual value.
* @param assertFactory the factory used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
*/
public static <ACTUAL extends List<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
return AssertionsForInterfaceTypes.assertThat(actual, assertFactory);
}
/**
* Creates a new instance of <code>{@link ClassBasedNavigableListAssert}</code> allowing to navigate to any {@code List} element
* in order to perform assertions on it.
* <p>
* Navigational methods provided:<ul>
* <li>{@link AbstractIterableAssert#first() first()}</li>
* <li>{@link AbstractIterableAssert#last() last()}</li>
* <li>{@link AbstractIterableAssert#element(int) element(index)}</li>
* <li>{@link AbstractIterableAssert#elements(int...) elements(int...)}</li>
* </ul>
* <p>
* The available assertions after navigating to an element depend on the given {@code assertClass}
* (AssertJ can't find the element assert type by itself because of Java type erasure).
* <p>
* Example with {@code String} element assertions:
* <pre><code class='java'> List<String> hobbits = newArrayList("frodo", "sam", "pippin");
*
* // assertion succeeds with String assertions chained after first()
* assertThat(hobbits, StringAssert.class).first()
* .startsWith("fro")
* .endsWith("do");</code></pre>
*
* @param <ACTUAL> The actual type
* @param <ELEMENT> The actual elements type
* @param <ELEMENT_ASSERT> The actual elements AbstractAssert type
* @param actual the actual value.
* @param assertClass the class used to create the elements assert instance.
* @return the created assertion object.
* @since 2.5.0 / 3.5.0
*/
public static <ELEMENT, ACTUAL extends List<? extends ELEMENT>, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> assertThat(List<? extends ELEMENT> actual,
Class<ELEMENT_ASSERT> assertClass) {
return AssertionsForInterfaceTypes.assertThat(actual, assertClass);
}
//@format:on
/**
* Creates a new instance of <code>{@link LongAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLongAssert<?> assertThat(long actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link LongAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLongAssert<?> assertThat(Long actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link LongArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLongArrayAssert<?> assertThat(long[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Long2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Long2DArrayAssert assertThat(long[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ObjectAssert}</code>.
*
* @param <T> the type of the actual value.
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T> ObjectAssert<T> assertThat(T actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ObjectArrayAssert}</code>.
*
* @param <T> the actual's elements type.
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T> ObjectArrayAssert<T> assertThat(T[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Object2DArrayAssert}</code>.
*
* @param <T> the actual's elements type.
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static <T> Object2DArrayAssert<T> assertThat(T[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ShortAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractShortAssert<?> assertThat(short actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ShortAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractShortAssert<?> assertThat(Short actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ShortArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractShortArrayAssert<?> assertThat(short[] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link Short2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Short2DArrayAssert assertThat(short[][] actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link DateAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDateAssert<?> assertThat(Date actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link ZonedDateTimeAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractZonedDateTimeAssert<?> assertThat(ZonedDateTime actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link LocalDateTimeAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLocalDateTimeAssert<?> assertThat(LocalDateTime actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link java.time.OffsetDateTime}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractOffsetDateTimeAssert<?> assertThat(OffsetDateTime actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link java.time.OffsetTime}.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractOffsetTimeAssert<?> assertThat(OffsetTime actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link LocalTimeAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLocalTimeAssert<?> assertThat(LocalTime actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link LocalDateAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLocalDateAssert<?> assertThat(LocalDate actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link InstantAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.7.0
*/
public static AbstractInstantAssert<?> assertThat(Instant actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link DurationAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.15.0
*/
public static AbstractDurationAssert<?> assertThat(Duration actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Creates a new instance of <code>{@link PeriodAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static AbstractPeriodAssert<?> assertThat(Period actual) {
return AssertionsForClassTypes.assertThat(actual);
}
/**
* Create assertion for {@link AtomicBoolean}.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 2.7.0 / 3.7.0
*/
public static AtomicBooleanAssert assertThat(AtomicBoolean actual) {
return new AtomicBooleanAssert(actual);
}
/**