forked from assertj/assertj
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathAssert.java
More file actions
773 lines (737 loc) · 31.4 KB
/
Assert.java
File metadata and controls
773 lines (737 loc) · 31.4 KB
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
/*
* 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-2020 the original author or authors.
*/
package org.assertj.core.api;
import java.util.Comparator;
import java.util.Date;
import java.util.List;
import java.util.function.Consumer;
import org.assertj.core.presentation.Representation;
import org.assertj.core.presentation.StandardRepresentation;
/**
* Base contract of all assertion objects: the minimum functionality that any assertion object should provide.
*
* @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 <ACTUAL> the type of the "actual" value.
*
* @author Yvonne Wang
* @author Alex Ruiz
* @author Nicolas François
* @author Mikhail Mazursky
*/
public interface Assert<SELF extends Assert<SELF, ACTUAL>, ACTUAL> extends Descriptable<SELF>, ExtensionPoints<SELF, ACTUAL> {
/**
* Verifies that the actual value is equal to the given one.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat("abc").isEqualTo("abc");
* assertThat(new HashMap<String, Integer>()).isEqualTo(new HashMap<String, Integer>());
*
* // assertions fail
* assertThat("abc").isEqualTo("123");
* assertThat(new ArrayList<String>()).isEqualTo(1);</code></pre>
*
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is not equal to the given one.
*/
SELF isEqualTo(Object expected);
/**
* Verifies that the actual value is not equal to the given one.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat("abc").isNotEqualTo("123");
* assertThat(new ArrayList<String>()).isNotEqualTo(1);
*
* // assertions fail
* assertThat("abc").isNotEqualTo("abc");
* assertThat(new HashMap<String, Integer>()).isNotEqualTo(new HashMap<String, Integer>());</code></pre>
*
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is equal to the given one.
*/
SELF isNotEqualTo(Object other);
/**
* Verifies that the actual value is {@code null}.
* <p>
* Example:
* <pre><code class='java'> String value = null;
* // assertion succeeds
* assertThat(value).isNull();
*
* // assertions fail
* assertThat("abc").isNull();
* assertThat(new HashMap<String, Integer>()).isNull();</code></pre>
*
* @throws AssertionError if the actual value is not {@code null}.
*/
void isNull();
/**
* Verifies that the actual value is not {@code null}.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat("abc").isNotNull();
* assertThat(new HashMap<String, Integer>()).isNotNull();
*
* // assertions fails
* String value = null;
* assertThat(value).isNotNull();</code></pre>
*
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is {@code null}.
*/
SELF isNotNull();
/**
* Verifies that the actual value is the same as the given one, ie using == comparison.
* <p>
* Example:
* <pre><code class='java'> // Name is a class with first and last fields, two Names are equals if both first and last are equals.
* Name tyrion = new Name("Tyrion", "Lannister");
* Name alias = tyrion;
* Name clone = new Name("Tyrion", "Lannister");
*
* // assertions succeed:
* assertThat(tyrion).isSameAs(alias)
* .isEqualTo(clone);
*
* // assertion fails:
* assertThat(tyrion).isSameAs(clone);</code></pre>
*
* @param expected the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is not the same as the given one.
*/
SELF isSameAs(Object expected);
/**
* Verifies that the actual value is not the same as the given one, ie using == comparison.
* <p>
* Example:
* <pre><code class='java'> // Name is a class with first and last fields, two Names are equals if both first and last are equals.
* Name tyrion = new Name("Tyrion", "Lannister");
* Name alias = tyrion;
* Name clone = new Name("Tyrion", "Lannister");
*
* // assertions succeed:
* assertThat(clone).isNotSameAs(tyrion)
* .isEqualTo(tyrion);
*
* // assertion fails:
* assertThat(alias).isNotSameAs(tyrion);</code></pre>
*
* @param other the given value to compare the actual value to.
* @return {@code this} assertion object.
* @throws AssertionError if the actual value is the same as the given one.
*/
SELF isNotSameAs(Object other);
/**
* Verifies that the actual value is present in the given array of values.
* <p>
* This assertion always fails if the given array of values is empty.
* <p>
* Example:
* <pre><code class='java'> Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
*
* // assertion succeeds
* assertThat(nenya).isIn(elvesRings);
*
* // assertions fail
* assertThat(oneRing).isIn(elvesRings);
* assertThat(oneRing).isIn(new Ring[0]);</code></pre>
*
* @param values the given array to search the actual value in.
* @return {@code this} assertion object.
* @throws NullPointerException if the given array is {@code null}.
* @throws AssertionError if the actual value is not present in the given array.
*/
SELF isIn(Object... values);
/**
* Verifies that the actual value is not present in the given array of values.
* <p>
* This assertion always succeeds if the given array of values is empty.
* <p>
* Example:
* <pre><code class='java'> Ring[] elvesRings = new Ring[] { vilya, nenya, narya };
*
* // assertions succeed
* assertThat(oneRing).isNotIn(elvesRings);
* assertThat(oneRing).isNotIn(new Ring[0]);
*
* // assertions fails:
* assertThat(nenya).isNotIn(elvesRings);</code></pre>
*
* @param values the given array to search the actual value in.
* @return {@code this} assertion object.
* @throws NullPointerException if the given array is {@code null}.
* @throws AssertionError if the actual value is present in the given array.
*/
SELF isNotIn(Object... values);
/**
* Verifies that the actual value is present in the given iterable.
* <p>
* This assertion always fails if the given iterable is empty.
* <p>
* Example:
* <pre><code class='java'> Iterable<Ring> elvesRings = list(vilya, nenya, narya);
*
* // assertion succeeds
* assertThat(nenya).isIn(elvesRings);
*
* // assertions fail:
* assertThat(oneRing).isIn(elvesRings);
* assertThat(oneRing).isIn(emptyList());</code></pre>
*
* @param values the given iterable to search the actual value in.
* @return {@code this} assertion object.
* @throws NullPointerException if the given collection is {@code null}.
* @throws AssertionError if the actual value is not present in the given collection.
*/
SELF isIn(Iterable<?> values);
/**
* Verifies that the actual value is not present in the given iterable.
* <p>
* This assertion always succeeds if the given iterable is empty.
* <p>
* Example:
* <pre><code class='java'> Iterable<Ring> elvesRings = list(vilya, nenya, narya);
*
* // assertions succeed:
* assertThat(oneRing).isNotIn(elvesRings);
* assertThat(oneRing).isNotIn(emptyList());
*
* // assertions fails:
* assertThat(nenya).isNotIn(elvesRings);</code></pre>
*
* @param values the given iterable to search the actual value in.
* @return {@code this} assertion object.
* @throws NullPointerException if the given collection is {@code null}.
* @throws AssertionError if the actual value is present in the given collection.
*/
SELF isNotIn(Iterable<?> values);
/**
* Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
* <p>
* The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default
* comparison strategy will be used.
* <p>
* Examples :
* <pre><code class='java'> // frodo and sam are instances of Character with Hobbit race (obviously :).
* // raceComparator implements Comparator<Character>
* assertThat(frodo).usingComparator(raceComparator).isEqualTo(sam);</code></pre>
*
* @param customComparator the comparator to use for the incoming assertion checks.
* @throws NullPointerException if the given comparator is {@code null}.
* @return {@code this} assertion object.
*/
SELF usingComparator(Comparator<? super ACTUAL> customComparator);
/**
* Use the given custom comparator instead of relying on actual type A equals method for incoming assertion checks.
* <p>
* The custom comparator is bound to assertion instance, meaning that if a new assertion instance is created, the default
* comparison strategy will be used.
* <p>
* Examples :
* <pre><code class='java'> // frodo and sam are instances of Character with Hobbit race (obviously :).
* // raceComparator implements Comparator<Character>
* assertThat(frodo).usingComparator(raceComparator, "Hobbit Race Comparator").isEqualTo(sam);</code></pre>
*
* @param customComparator the comparator to use for the incoming assertion checks.
* @param customComparatorDescription comparator description to be used in assertion error messages
* @throws NullPointerException if the given comparator is {@code null}.
* @return {@code this} assertion object.
*/
SELF usingComparator(Comparator<? super ACTUAL> customComparator, String customComparatorDescription);
/**
* Revert to standard comparison for the incoming assertion checks.
* <p>
* This method should be used to disable a custom comparison strategy set by calling {@link #usingComparator(Comparator) usingComparator}.
*
* @return {@code this} assertion object.
*/
SELF usingDefaultComparator();
/**
* Uses an {@link InstanceOfAssertFactory} to verify that the actual value is an instance of a given type and to produce
* a new {@link Assert} narrowed to that type.
* <p>
* {@link InstanceOfAssertFactories} provides static factories for all the types supported by {@code Assertions#assertThat}.
* <p>
* Additional factories can be created with custom {@code InstanceOfAssertFactory} instances.
* <p>
* Example:
* <pre><code class='java'> // assertions succeeds
* Object string = "abc";
* assertThat(string).asInstanceOf(InstanceOfAssertFactories.STRING).startsWith("ab");
*
* Object integer = 1;
* assertThat(integer).asInstanceOf(InstanceOfAssertFactories.INTEGER).isNotZero();
*
* // assertions fails
* assertThat("abc").asInstanceOf(InstanceOfAssertFactories.INTEGER);</code></pre>
*
* @param <ASSERT> the type of the resulting {@code Assert}.
* @param instanceOfAssertFactory the factory which verifies the type and creates the new {@code Assert}.
* @throws NullPointerException if the given factory is {@code null}.
* @return the narrowed {@code Assert} instance.
*
* @see InstanceOfAssertFactory
* @see InstanceOfAssertFactories
*
* @since 3.13.0
*/
<ASSERT extends AbstractAssert<?, ?>> ASSERT asInstanceOf(InstanceOfAssertFactory<?, ASSERT> instanceOfAssertFactory);
/**
* Verifies that the actual value is an instance of the given type.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat("abc").isInstanceOf(String.class);
* assertThat(new HashMap<String, Integer>()).isInstanceOf(HashMap.class);
* assertThat(new HashMap<String, Integer>()).isInstanceOf(Map.class);
*
* // assertions fail
* assertThat(1).isInstanceOf(String.class);
* assertThat(new ArrayList<String>()).isInstanceOf(LinkedList.class);</code></pre>
*
* @param type the type to check the actual value against.
* @return this assertion object.
* @throws NullPointerException if the given type is {@code null}.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not an instance of the given type.
*/
SELF isInstanceOf(Class<?> type);
/**
* Verifies that the actual value is an instance of the given type satisfying the given requirements expressed as a {@link Consumer}.
* <p>
* This is useful to perform a group of assertions on a single object after checking its runtime type.
* <p>
* Example:
* <pre><code class='java'> // second constructor parameter is the light saber color
* Object yoda = new Jedi("Yoda", "Green");
* Object luke = new Jedi("Luke Skywalker", "Green");
*
* Consumer<Jedi> jediRequirements = jedi -> {
* assertThat(jedi.getLightSaberColor()).isEqualTo("Green");
* assertThat(jedi.getName()).doesNotContain("Dark");
* };
*
* // assertions succeed:
* assertThat(yoda).isInstanceOfSatisfying(Jedi.class, jediRequirements);
* assertThat(luke).isInstanceOfSatisfying(Jedi.class, jediRequirements);
*
* // assertions fail:
* Jedi vader = new Jedi("Vader", "Red");
* assertThat(vader).isInstanceOfSatisfying(Jedi.class, jediRequirements);
* // not a Jedi !
* assertThat("foo").isInstanceOfSatisfying(Jedi.class, jediRequirements);</code></pre>
*
* @param <T> the generic type to check the actual value against.
* @param type the type to check the actual value against.
* @param requirements the requirements expressed as a {@link Consumer}.
* @return this assertion object.
* @throws NullPointerException if the given type is {@code null}.
* @throws NullPointerException if the given Consumer is {@code null}.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not an instance of the given type.
*/
<T> SELF isInstanceOfSatisfying(Class<T> type, Consumer<T> requirements);
/**
* Verifies that the actual value is an instance of any of the given types.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat("abc").isInstanceOfAny(String.class, Integer.class);
* assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, ArrayList.class);
* assertThat(new HashMap<String, Integer>()).isInstanceOfAny(TreeMap.class, Map.class);
*
* // assertions fail
* assertThat(1).isInstanceOfAny(Double.class, Float.class);
* assertThat(new ArrayList<String>()).isInstanceOfAny(LinkedList.class, Vector.class);</code></pre>
*
* @param types the types to check the actual value against.
* @return this assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is not an instance of any of the given types.
* @throws NullPointerException if the given array of types is {@code null}.
* @throws NullPointerException if the given array of types contains {@code null}s.
*/
SELF isInstanceOfAny(Class<?>... types);
/**
* Verifies that the actual value is not an instance of the given type.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(1).isNotInstanceOf(Double.class);
* assertThat(new ArrayList<String>()).isNotInstanceOf(LinkedList.class);
*
* // assertions fail
* assertThat("abc").isNotInstanceOf(String.class);
* assertThat(new HashMap<String, Integer>()).isNotInstanceOf(HashMap.class);
* assertThat(new HashMap<String, Integer>()).isNotInstanceOf(Map.class);</code></pre>
*
* @param type the type to check the actual value against.
* @return this assertion object.
* @throws NullPointerException if the given type is {@code null}.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is an instance of the given type.
*/
SELF isNotInstanceOf(Class<?> type);
/**
* Verifies that the actual value is not an instance of any of the given types.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(1).isNotInstanceOfAny(Double.class, Float.class);
* assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, Vector.class);
*
* // assertions fail
* assertThat(1).isNotInstanceOfAny(Double.class, Integer.class);
* assertThat(new ArrayList<String>()).isNotInstanceOfAny(LinkedList.class, ArrayList.class);
* assertThat(new HashMap<String, Integer>()).isNotInstanceOfAny(TreeMap.class, Map.class);</code></pre>
*
* @param types the types to check the actual value against.
* @return this assertion object.
* @throws AssertionError if the actual value is {@code null}.
* @throws AssertionError if the actual value is an instance of any of the given types.
* @throws NullPointerException if the given array of types is {@code null}.
* @throws NullPointerException if the given array of types contains {@code null}s.
*/
SELF isNotInstanceOfAny(Class<?>... types);
/**
* Verifies that the actual value has the same class as the given object.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(1).hasSameClassAs(2);
* assertThat("abc").hasSameClassAs("123");
* assertThat(new ArrayList<String>()).hasSameClassAs(new ArrayList<Integer>());
*
* // assertions fail
* assertThat(1).hasSameClassAs("abc");
* assertThat(new ArrayList<String>()).hasSameClassAs(new LinkedList<String>());</code></pre>
*
* @param other the object to check type against.
* @return this assertion object.
* @throws AssertionError if the actual has not the same type has the given object.
* @throws NullPointerException if the actual value is null.
* @throws NullPointerException if the given object is null.
*/
SELF hasSameClassAs(Object other);
/**
* Verifies that actual {@code actual.toString()} is equal to the given {@code String}.
* <p>
* Example :
* <pre><code class='java'> CartoonCharacter homer = new CartoonCharacter("Homer");
*
* // Instead of writing ...
* assertThat(homer.toString()).isEqualTo("Homer");
* // ... you can simply write:
* assertThat(homer).hasToString("Homer");</code></pre>
*
* @param expectedToString the expected String description of actual.
* @return this assertion object.
* @throws AssertionError if {@code actual.toString()} result is not to the given {@code String}.
* @throws AssertionError if actual is {@code null}.
*/
SELF hasToString(String expectedToString);
/**
* Verifies that the actual value does not have the same class as the given object.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(1).doesNotHaveSameClassAs("abc");
* assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new LinkedList<String>());
*
* // assertions fail
* assertThat(1).doesNotHaveSameClassAs(2);
* assertThat("abc").doesNotHaveSameClassAs("123");
* assertThat(new ArrayList<String>()).doesNotHaveSameClassAs(new ArrayList<Integer>());</code></pre>
*
* @param other the object to check type against.
* @return this assertion object.
* @throws AssertionError if the actual has the same type has the given object.
* @throws NullPointerException if the actual value is null.
* @throws NullPointerException if the given object is null.
*/
SELF doesNotHaveSameClassAs(Object other);
/**
* Verifies that the actual value is <b>exactly</b> an instance of the given type.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat("abc").isExactlyInstanceOf(String.class);
* assertThat(new ArrayList<String>()).isExactlyInstanceOf(ArrayList.class);
* assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(HashMap.class);
*
* // assertions fail
* assertThat(1).isExactlyInstanceOf(String.class);
* assertThat(new ArrayList<String>()).isExactlyInstanceOf(List.class);
* assertThat(new HashMap<String, Integer>()).isExactlyInstanceOf(Map.class);</code></pre>
*
* @param type the type to check the actual value against.
* @return this assertion object.
* @throws AssertionError if the actual is not <b>exactly</b> an instance of given type.
* @throws NullPointerException if the actual value is null.
* @throws NullPointerException if the given object is null.
*/
SELF isExactlyInstanceOf(Class<?> type);
/**
* Verifies that the actual value is not <b>exactly</b> an instance of given type.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(1).isNotExactlyInstanceOf(String.class);
* assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(List.class);
* assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(Map.class);
*
* // assertions fail
* assertThat("abc").isNotExactlyInstanceOf(String.class);
* assertThat(new ArrayList<String>()).isNotExactlyInstanceOf(ArrayList.class);
* assertThat(new HashMap<String, Integer>()).isNotExactlyInstanceOf(HashMap.class);</code></pre>
*
* @param type the type to check the actual value against.
* @return this assertion object.
* @throws AssertionError if the actual is exactly an instance of given type.
* @throws NullPointerException if the actual value is null.
* @throws NullPointerException if the given object is null.
*/
SELF isNotExactlyInstanceOf(Class<?> type);
/**
* Verifies that the actual value type is in given types.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(HashMap.class, TreeMap.class);
* assertThat(new ArrayList<String>()).isOfAnyClassIn(ArrayList.class, LinkedList.class);
*
* // assertions fail
* assertThat(new HashMap<String, Integer>()).isOfAnyClassIn(TreeMap.class, Map.class);
* assertThat(new ArrayList<String>()).isOfAnyClassIn(LinkedList.class, List.class);</code></pre>
*
* @param types the types to check the actual value against.
* @return this assertion object.
* @throws AssertionError if the actual value type is not in given type.
* @throws NullPointerException if the actual value is null.
* @throws NullPointerException if the given types is null.
*/
SELF isOfAnyClassIn(Class<?>... types);
/**
* Verifies that the actual value type is not in given types.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(Map.class, TreeMap.class);
* assertThat(new ArrayList<String>()).isNotOfAnyClassIn(LinkedList.class, List.class);
*
* // assertions fail
* assertThat(new HashMap<String, Integer>()).isNotOfAnyClassIn(HashMap.class, TreeMap.class);
* assertThat(new ArrayList<String>()).isNotOfAnyClassIn(ArrayList.class, LinkedList.class);</code></pre>
*
* @param types the types to check the actual value against.
* @return this assertion object.
* @throws AssertionError if the actual value type is in given types.
* @throws NullPointerException if the actual value is null.
* @throws NullPointerException if the given types is null.
*/
SELF isNotOfAnyClassIn(Class<?>... types);
/**
* Verifies that the actual value is an instance of List,
* and returns a list assertion, to allow chaining of list-specific
* assertions from this call.
* <p>
* Example :
* <pre><code class='java'> Object sortedListAsObject = Arrays.asList(1, 2, 3);
*
* // assertion succeeds
* assertThat(sortedListAsObject).asList().isSorted();
*
* Object unsortedListAsObject = Arrays.asList(3, 1, 2);
*
* // assertions fails
* assertThat(unsortedListAsObject).asList().isSorted();</code></pre>
*
* @return a list assertion object
*/
AbstractListAssert<?, List<?>, Object, ObjectAssert<Object>> asList();
/**
* Returns a String assertion for the <code>toString()</code> of the actual
* value, to allow chaining of String-specific assertions from this call.
* <p>
* Example :
* <pre><code class='java'> Object stringAsObject = "hello world";
*
* // assertion succeeds
* assertThat(stringAsObject).asString().contains("hello");
*
* // assertions fails
* assertThat(stringAsObject).asString().contains("holla");</code></pre>
*
* @return a string assertion object
*/
AbstractCharSequenceAssert<?, String> asString();
/**
* @deprecated
* Throws <code>{@link UnsupportedOperationException}</code> if called. It is easy to accidentally call
* <code>equals(Object)</code> instead of <code>{@link #isEqualTo(Object)}</code>.
* @throws UnsupportedOperationException if this method is called.
*/
@Override
@Deprecated
boolean equals(Object obj);
/**
* In case of an assertion error, a thread dump will be printed to {@link System#err}.
* <p>
* Example :
* <pre><code class='java'> assertThat("Messi").withThreadDumpOnError().isEqualTo("Ronaldo");</code></pre>
*
* will print a thread dump, something similar to this:
* <pre>{@code "JDWP Command Reader"
* java.lang.Thread.State: RUNNABLE
*
* "JDWP Event Helper Thread"
* java.lang.Thread.State: RUNNABLE
*
* "JDWP Transport Listener: dt_socket"
* java.lang.Thread.State: RUNNABLE
*
* "Signal Dispatcher"
* java.lang.Thread.State: RUNNABLE
*
* "Finalizer"
* java.lang.Thread.State: WAITING
* at java.lang.Object.wait(Native Method)
* at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:135)
* at java.lang.ref.ReferenceQueue.remove(ReferenceQueue.java:151)
* at java.lang.ref.Finalizer$FinalizerThread.run(Finalizer.java:189)
*
* "Reference Handler"
* java.lang.Thread.State: WAITING
* at java.lang.Object.wait(Native Method)
* at java.lang.Object.wait(Object.java:503)
* at java.lang.ref.Reference$ReferenceHandler.run(Reference.java:133)
*
* "main"
* java.lang.Thread.State: RUNNABLE
* at sun.management.ThreadImpl.dumpThreads0(Native Method)
* at sun.management.ThreadImpl.dumpAllThreads(ThreadImpl.java:446)
* at org.assertj.core.internal.Failures.threadDumpDescription(Failures.java:193)
* at org.assertj.core.internal.Failures.printThreadDumpIfNeeded(Failures.java:141)
* at org.assertj.core.internal.Failures.failure(Failures.java:91)
* at org.assertj.core.internal.Objects.assertEqual(Objects.java:314)
* at org.assertj.core.api.AbstractAssert.isEqualTo(AbstractAssert.java:198)
* at org.assertj.examples.ThreadDumpOnErrorExample.main(ThreadDumpOnErrorExample.java:28)}</pre>
*
* @return this assertion object.
*/
SELF withThreadDumpOnError();
/**
* Use the given {@link Representation} to describe/represent values in AssertJ error messages.
* <p>
* The usual way to introduce a new {@link Representation} is to extend {@link StandardRepresentation}
* and override any existing {@code toStringOf} methods that don't suit you. For example you can control
* {@link Date} formatting by overriding {@link StandardRepresentation#toStringOf(Date)}).
* <p>
* You can also control other types format by overriding {@link StandardRepresentation#toStringOf(Object)})
* calling your formatting method first and then fall back to the default representation by calling {@code super.toStringOf(Object)}.
* <p>
* Example :
* <pre><code class='java'> private class Example {}
*
* private class CustomRepresentation extends StandardRepresentation {
*
* // override needed to hook specific formatting
* {@literal @}Override
* public String toStringOf(Object o) {
* if (o instanceof Example) return "Example";
* // fall back to default formatting
* return super.toStringOf(o);
* }
*
* // change String representation
* {@literal @}Override
* protected String toStringOf(String s) {
* return "$" + s + "$";
* }
* }
*
* // next assertion fails with error : "expected:<[null]> but was:<[Example]>"
* Example example = new Example();
* assertThat(example).withRepresentation(new CustomRepresentation())
* .isNull(); // example is not null !
*
* // next assertion fails ...
* assertThat("foo").withRepresentation(new CustomRepresentation())
* .startsWith("bar");
* // ... with error :
* Expecting:
* <$foo$>
* to start with:
* <$bar$></code></pre>
*
* @param representation Describe/represent values in AssertJ error messages.
* @return this assertion object.
*/
SELF withRepresentation(Representation representation);
/**
* Verifies that the actual object has the same hashCode as the given object.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(42L).hasSameHashCodeAs(42L);
* assertThat("The Force").hasSameHashCodeAs("The Force");
* assertThat(new Jedi("Yoda", "Blue")).hasSameHashCodeAs(new Jedi("Yoda", "Blue"));
*
* // assertions fail
* assertThat(42L).hasSameHashCodeAs(2501L);
* assertThat(null).hasSameHashCodeAs("The Force");
* assertThat("The Force").hasSameHashCodeAs(null);</code></pre>
*
* @param other the object to check hashCode against.
*
* @return this assertion object.
*
* @throws AssertionError if the actual object is null.
* @throws NullPointerException if the other object is null.
* @throws AssertionError if the actual object has not the same hashCode as the given object.
*
* @since 2.9.0
*/
SELF hasSameHashCodeAs(Object other);
/**
* Verifies that the actual object does not have the same hashCode as the given object.
* <p>
* Example:
* <pre><code class='java'> // assertions succeed
* assertThat(42L).doesNotHaveSameHashCodeAs(2501L);
* assertThat("The Force").doesNotHaveSameHashCodeAs(null);
*
* // assertions fail
* assertThat(42L).doesNotHaveSameHashCodeAs(42L);
* assertThat("The Force").doesNotHaveSameHashCodeAs("The Force");
* assertThat(new Jedi("Yoda", "Blue")).doesNotHaveSameHashCodeAs(new Jedi("Yoda", "Blue")); </code></pre>
*
* @param other the object to check hashCode against.
*
* @return this assertion object.
*
* @throws AssertionError if the actual object is null.
* @throws NullPointerException if the other object is null.
* @throws AssertionError if the actual object has the same hashCode as the given object.
*
* @since 3.19.0
*/
SELF doesNotHaveSameHashCodeAs(Object other);
}