/
BDDAssertions.java
3302 lines (3105 loc) · 125 KB
/
BDDAssertions.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 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.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.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.TemporalUnitOffset;
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;
/**
* Behavior-driven development style entry point for assertion methods for different types. Each method in this class is a static factory
* for a type-specific assertion object.
* <p>
* The difference with the {@link Assertions} class is that entry point methods are named <code>then</code> instead of
* <code>assertThat</code>.
* <p>
* For example:
* <pre><code class='java'> {@literal @}Test
* public void bdd_assertions_example() {
* //given
* List<BasketBallPlayer> bulls = new ArrayList<>();
*
* //when
* bulls.add(rose);
* bulls.add(noah);
*
* then(bulls).contains(rose, noah).doesNotContain(james);
* }</code></pre>
* Use <code>{@link #and}</code> to avoid clash with other libraries (like BDDMockito) exposing '<code>then(object)</code>'.
* You might have to ignore a warning like: <i>The static method BDDAssertions.then() should be accessed in a static way</i>.
*
*
* @author Gonzalo Müller
* @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 Delanoue
* @author Mariusz Smykula
*/
@CheckReturnValue
public class BDDAssertions extends Assertions {
/**
* Creates a new <code>{@link org.assertj.core.api.BDDAssertions}</code>.
*/
protected BDDAssertions() {}
/**
* A <code>BDDAssertions</code> which allows to blend assertions with other libraries when the name '<code>then</code>' cause clash.
* <p>
* Examples:
* <pre><code class='java'> import static org.assertj.core.api.BDDAssertions.and;
* import static org.mockito.BDDMockito.then;
* import static org.mockito.Mockito.mock;
* import static org.mockito.Mockito.times;
*
* // suppress and.then warning: The static method BDDAssertions.then() should be accessed in a static way
* {@literal @SuppressWarnings}("static-access")
* {@literal @Test}
* public void bdd_assertions_with_bdd_mockito() {
* // GIVEN
* Person person = mock(Person.class)
* // WHEN
* person.ride(bike);
* person.ride(bike);
* // THEN
* // mockito then()
* then(person).should(times(2)).ride(bike);
* // use AssertJ and.then(person) as then(person) would clash with mockito then(person)
* and.then(person.hasBike()).isTrue();
* }</code></pre>
* <p>
* Can also be used to add extra readability:
* <pre><code class='java'> import static org.assertj.core.api.BDDAssertions.and;
* import static org.assertj.core.api.BDDAssertions.then;
*
* // suppress and.then warning: The static method BDDAssertions.then() should be accessed in a static way
* {@literal @SuppressWarnings}("static-access")
* {@literal @Test}
* public void bdd_assertions_with_and_field() {
* // ...
* then(person.hasBike()).isTrue()
* and.then(bike.isNew()).isFalse();
* }</code></pre>
*
* @since 3.14.0
*/
public static final BDDAssertions and = new BDDAssertions();
/**
* 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> then(Predicate<T> actual) {
return assertThat(actual);
}
/**
* Create assertion for {@link IntPredicate}.
*
* @param actual the actual value.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static IntPredicateAssert then(IntPredicate actual) {
return assertThat(actual);
}
/**
* Create assertion for {@link LongPredicate}.
*
* @param actual the actual value.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static LongPredicateAssert then(LongPredicate actual) {
return assertThat(actual);
}
/**
* Create assertion for {@link DoublePredicate}.
*
* @param actual the actual value.
* @return the created assertion object.
*
* @since 3.5.0
*/
public static DoublePredicateAssert then(DoublePredicate actual) {
return assertThat(actual);
}
/**
* Create assertion for {@link java.util.Optional}.
*
* @param <VALUE> the type of the value contained in the {@link java.util.Optional}.
* @param optional the actual value.
*
* @return the created assertion object.
*/
public static <VALUE> OptionalAssert<VALUE> then(Optional<VALUE> optional) {
return assertThat(optional);
}
/**
* Create assertion for {@link java.util.OptionalInt}.
*
* @param optional the actual value.
*
* @return the created assertion object.
*/
public static OptionalIntAssert then(OptionalInt optional) {
return assertThat(optional);
}
/**
* Create assertion for {@link java.util.OptionalLong}.
*
* @param optional the actual value.
*
* @return the created assertion object.
*/
public static OptionalLongAssert then(OptionalLong optional) {
return assertThat(optional);
}
/**
* Create assertion for {@link java.util.OptionalDouble}.
*
* @param optional the actual value.
*
* @return the created assertion object.
*/
public static OptionalDoubleAssert then(OptionalDouble optional) {
return assertThat(optional);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.BigDecimalAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBigDecimalAssert<?> then(BigDecimal actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.BigIntegerAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 2.7.0 / 3.7.0
*/
public static AbstractBigIntegerAssert<?> then(BigInteger actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.BooleanAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBooleanAssert<?> then(boolean actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.BooleanAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBooleanAssert<?> then(Boolean actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.BooleanArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractBooleanArrayAssert<?> then(boolean[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Boolean2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Boolean2DArrayAssert then(boolean[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ByteAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractByteAssert<?> then(byte actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ByteAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractByteAssert<?> then(Byte actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ByteArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractByteArrayAssert<?> then(byte[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Byte2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Byte2DArrayAssert then(byte[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.CharacterAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharacterAssert<?> then(char actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.CharArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharArrayAssert<?> then(char[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Char2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Char2DArrayAssert then(char[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.CharacterAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharacterAssert<?> then(Character actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ClassAssert}</code>
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static ClassAssert then(Class<?> actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.GenericComparableAssert}</code> with
* standard comparison semantics.
*
* @param <T> the actual type
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T extends Comparable<? super T>> AbstractComparableAssert<?, T> then(T actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.IterableAssert}</code>.
*
* @param <T> the actual elements type
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T> IterableAssert<T> then(Iterable<? extends T> actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link IteratorAssert}</code>.
* <p>
* <b>Breaking change in version 3.12.0:</b> this method does not return anymore an {@link IterableAssert} but an {@link IteratorAssert}.<br>
* In order to access assertions from {@link IterableAssert}, use {@link IteratorAssert#toIterable()}.
* <p>
* {@link IteratorAssert} instances have limited assertions because it does not consume iterator's elements.
* <p>
* Examples:
* <pre><code class='java'> Iterator<String> bestBasketBallPlayers = getBestBasketBallPlayers();
*
* then(bestBasketBallPlayers).hasNext() // Iterator assertion
* .toIterable() // switch to Iterable assertions
* .contains("Jordan", "Magic", "Lebron"); // Iterable assertion </code></pre>
*
*
* @param <T> the actual elements type
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T> IteratorAssert<T> then(Iterator<? extends T> actual) {
return 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#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'> 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()
* then(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.
*/
//@format:off
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> then(Iterable<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
return 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...) 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'> Iterable<String> hobbits = newHashSet("frodo", "sam", "pippin");
*
* // assertion succeeds with String assertions chained after first()
* then(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.
*/
public static <ACTUAL extends Iterable<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableIterableAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> then(ACTUAL actual,
Class<ELEMENT_ASSERT> assertClass) {
return 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()
* then(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.
*/
public static <ACTUAL extends List<? extends ELEMENT>, ELEMENT, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
FactoryBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> then(List<? extends ELEMENT> actual,
AssertFactory<ELEMENT, ELEMENT_ASSERT> assertFactory) {
return 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()
* then(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.
*/
public static <ELEMENT, ACTUAL extends List<? extends ELEMENT>, ELEMENT_ASSERT extends AbstractAssert<ELEMENT_ASSERT, ELEMENT>>
ClassBasedNavigableListAssert<?, ACTUAL, ELEMENT, ELEMENT_ASSERT> then(List<? extends ELEMENT> actual,
Class<ELEMENT_ASSERT> assertClass) {
return assertThat(actual, assertClass);
}
//@format:on
/**
* Creates a new instance of <code>{@link org.assertj.core.api.DoubleAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDoubleAssert<?> then(double actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.DoubleAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDoubleAssert<?> then(Double actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.DoubleArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractDoubleArrayAssert<?> then(double[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Double2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Double2DArrayAssert then(double[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.FileAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFileAssert<?> then(File actual) {
return assertThat(actual);
}
/**
* Creates a new instance of {@link PathAssert}
*
* @param actual the path to test
* @return the created assertion object
*/
public static AbstractPathAssert<?> then(Path actual) {
return assertThat(actual);
}
/**
* Creates a new instance of {@link FutureAssert}
*
* @param <RESULT> the type of the value contained in the {@link java.util.concurrent.Future}.
* @param actual the future to test
* @return the created assertion object
* @since 2.7.0 / 3.7.0
*/
public static <RESULT> FutureAssert<RESULT> then(Future<RESULT> actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.InputStreamAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractInputStreamAssert<?, ? extends InputStream> then(InputStream actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.FloatAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFloatAssert<?> then(float actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.FloatAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFloatAssert<?> then(Float actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.FloatArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractFloatArrayAssert<?> then(float[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Float2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Float2DArrayAssert then(float[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.IntegerAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractIntegerAssert<?> then(int actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.IntArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractIntArrayAssert<?> then(int[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Int2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Int2DArrayAssert then(int[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.IntegerAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractIntegerAssert<?> then(Integer actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link CollectionAssert}</code>.
*
* @param <E> the type of elements.
* @param actual the actual value.
* @return the created assertion object.
* @since 3.21.0
*/
public static <E> AbstractCollectionAssert<?, Collection<? extends E>, E, ObjectAssert<E>> then(Collection<? extends E> actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ListAssert}</code>.
*
* @param <T> the type of elements.
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T> ListAssert<T> then(List<? extends T> actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.LongAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLongAssert<?> then(long actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.LongAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLongAssert<?> then(Long actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.LongArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractLongArrayAssert<?> then(long[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Long2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Long2DArrayAssert then(long[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.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> then(T actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ObjectArrayAssert}</code>.
*
* @param <T> the actual's elements type.
* @param actual the actual value.
* @return the created assertion object.
*/
public static <T> ObjectArrayAssert<T> then(T[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.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> then(T[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.MapAssert}</code>.
*
* @param <K> the type of keys in the map.
* @param <V> the type of values in the map.
* @param actual the actual value.
* @return the created assertion object.
*/
public static <K, V> MapAssert<K, V> then(Map<K, V> actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ShortAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractShortAssert<?> then(short actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ShortAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractShortAssert<?> then(Short actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.ShortArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractShortArrayAssert<?> then(short[] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.Short2DArrayAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.17.0
*/
public static Short2DArrayAssert then(short[][] actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.CharSequenceAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractCharSequenceAssert<?, ? extends CharSequence> then(CharSequence actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.CharSequenceAssert}</code> from a {@link StringBuilder}.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.11.0
*/
public static AbstractCharSequenceAssert<?, ? extends CharSequence> then(StringBuilder actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.CharSequenceAssert}</code> from a {@link StringBuffer}.
*
* @param actual the actual value.
* @return the created assertion object.
* @since 3.11.0
*/
public static AbstractCharSequenceAssert<?, ? extends CharSequence> then(StringBuffer actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.StringAssert}</code>.
*
* @param actual the actual value.
* @return the created assertion object.
*/
public static AbstractStringAssert<?> then(String actual) {
return assertThat(actual);
}
/**
* Creates a new instance of <code>{@link org.assertj.core.api.DateAssert}</code>.
*
* @param actual the actual value.