-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathassertj-core-older-releases.html
4248 lines (3331 loc) · 277 KB
/
assertj-core-older-releases.html
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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="utf-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<meta name="description" content="AssertJ site">
<meta name="author" content="Joel Costigliola">
<title>AssertJ / Fluent assertions for java</title>
<!-- CSS -->
<link rel="stylesheet" type="text/css" href="http://fonts.googleapis.com/css?family=Inconsolata|Source+Code+Pro|Open+Sans|Ubuntu|Varela+Round|Karla">
<link href="css/bootstrap.min.css" rel="stylesheet">
<link href="font-awesome/css/font-awesome.min.css" rel="stylesheet">
<script src="highlight/highlight.pack.js"></script>
<link rel="stylesheet" href="highlight/styles/railscasts.css">
<script>hljs.initHighlightingOnLoad();</script>
<link href="css/assertj.min.css" rel="stylesheet">
<link rel="shortcut icon" href="favicon.png" />
</head>
<body>
<nav class="navbar navbar-inverse navbar-fixed-top" role="navigation">
<div class="container">
<div class="navbar-header">
<button type="button" class="navbar-toggle" data-toggle="collapse" data-target=".navbar-ex1-collapse">
<span class="sr-only">Toggle navigation</span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</button>
<!-- You'll want to use a responsive image option so this logo looks good on devices - I recommend using something like retina.js (do a quick Google search for it and you'll find it) -->
<a class="navbar-brand" href="index.html">AssertJ</a>
</div>
<!-- Collect the nav links, forms, and other content for toggling -->
<div class="collapse navbar-collapse navbar-ex1-collapse">
<ul class="nav navbar-nav navbar-right">
<li><a href="assertj-core-quick-start.html">Quick start</a></li>
<li><a href="assertj-news.html">News</a></li>
<li><a href="assertj-core.html">Core</a></li>
<li><a href="assertj-assertions-generator.html">Assertions generator</a></li>
<li><a href="assertj-guava.html">Guava</a></li>
<li><a href="assertj-joda-time.html">Joda-Time</a></li>
<li><a href="assertj-db.html">DB</a></li>
<li><a href="assertj-neo4j.html">Neo4j</a></li>
<li><a href="assertj-swing.html">Swing</a></li>
<li><a href="assertj-help.html">Help</a></li>
</ul>
</div>
</div>
</nav>
<div class="container">
<div class="row">
<div class="col-md-2 assertj-sidebar-menu">
<div class="bs-sidebar hidden-print affix-top" role="complementary">
<ul class="bs-sidenav nav ">
<li class="sidenav-header">Main</li>
<li><a href="assertj-core.html">Overview</a></li>
<li><a href="assertj-core-quick-start.html">Quick start</a></li>
<li><a href="assertj-core-news.html">News & releases</a></li>
<li><a href="assertj-core-features-highlight.html">Features highlight</a></li>
<li><a href="assertj-core-conditions.html">Using conditions</a></li>
<li><a href="assertj-core-custom-assertions.html">Custom assertions</a></li>
<li><a href="http://joel-costigliola.github.io/assertj/core/api/index.html" target="_blank">Javadoc (2.x)</a></li>
<li><a href="http://joel-costigliola.github.io/assertj/core-8/api/index.html" target="_blank">Javadoc (3.x)</a></li>
<li><a href="assertj-core.html#help">Help & F.A.Q</a></li>
<li><a href="assertj-core.html#code">Code & issues <i class="fa fa-github"></i></a></li>
<li><a href="assertj-core.html#team">Team</a></li>
<li><a href="assertj-core.html#contributing">Contributing</a></li>
<li class="sidenav-header">Migrating</li>
<li><a href="assertj-core-converting-junit-assertions-to-assertj.html">JUnit 4 Assertions</a></li>
<li><a href="assertj-core-converting-junit5-assertions-to-assertj.html">JUnit 5 Assertions</a></li>
<li><a href="assertj-core-converting-testng-assertions-to-assertj.html">TestNG Assertions</a></li>
<li><a href="assertj-core-migrating-from-fest.html">Fest Assert</a></li>
</ul>
</div>
</div>
<div class="col-lg-10 col-md-10 col-sm-10 text-left" >
<h1 class="page-header">AssertJ Core older releases</h1>
<ul>
<li><a href="#assertj-core-2.9.1">AssertJ core 2.9.1 release</a></li>
<li><a href="#assertj-core-2.9.0">AssertJ core 2.9.0 release</a></li>
<li><a href="#assertj-core-2.8.0">AssertJ core 2.8.0 release</a></li>
<li><a href="#assertj-core-2.7.0">AssertJ core 2.7.0 release</a></li>
<li><a href="#assertj-core-2.6.0">AssertJ core 2.6.0 release</a></li>
<li><a href="#assertj-core-2.5.0">AssertJ core 2.5.0 release</a></li>
<li><a href="#assertj-core-[2|3].4.1">AssertJ core 2.4.1/3.4.1 release</a> (bugfix)</li>
<li><a href="#assertj-core-3.4.0">AssertJ core 3.4.0 release</a> (requires Java 8)</li>
<li><a href="#assertj-core-2.4.0">AssertJ core 2.4.0 release</a></li>
<li><a href="#assertj-core-3.3.0">AssertJ core 3.3.0 release</a> (requires Java 8)</li>
<li><a href="#assertj-core-2.3.0">AssertJ core 2.3.0 release</a></li>
<li><a href="#assertj-core-3.2.0">AssertJ core 3.2.0 release</a> (requires Java 8)</li>
<li><a href="#assertj-core-2.2.0">AssertJ core 2.2.0 release</a></li>
<li><a href="#assertj-core-3.1.0">AssertJ core 3.1.0 release</a> (requires Java 8)</li>
<li><a href="#assertj-core-2.1.0">AssertJ core 2.1.0 release</a></li>
<li><a href="#assertj-core-3.0.0">AssertJ core 3.0.0 release</a> (requires Java 8)</li>
<li><a href="#assertj-core-2.0.0">AssertJ core 2.0.0 release</a></li>
<li><a href="#assertj-core-1.7.1">AssertJ core 1.7.1 release</a></li>
<li><a href="#assertj-core-1.7.0">AssertJ core 1.7.0 release</a></li>
<li><a href="#assertj-core-1.6.1">AssertJ core 1.6.1 release</a></li>
<li><a href="#assertj-core-1.6.0">AssertJ core 1.6.0 release</a></li>
<li><a href="#assertj-core-1.5.0">AssertJ core 1.5.0 release</a></li>
<li><a href="#assertj-core-1.4.0">AssertJ core 1.4.0 release</a></li>
<li><a href="#assertj-core-1.3.0">AssertJ core 1.3.0 release</a></li>
<li><a href="#assertj-core-1.2.0">AssertJ core 1.2.0 release</a></li>
<li><a href="#assertj-core-1.1.0">AssertJ core 1.1.0 release</a></li>
<li><a href="#assertj-core-1.0.0">AssertJ core 1.0.0 release</a></li>
</ul>
<h3 class="page-header"><span id="assertj-core-2.9.1"></span>AssertJ Core 2.9.1 release : New and noteworthy</h3>
<p>Release date : 2018-05-12</p>
<p>This is a bugfix release as 2.x is not actively developped.</p>
<p>Thanks to <span class="contributor">Andrey Kuzmin</span> for his contributions.</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category">Fixed :</div>
<ul>
<li>Fix of extracting/flatExtracting method not having proper description if set. <span class="contributor">(Andrey Kuzmin)</span></li>
<li>Allow passing a comparator description. <span class="contributor">(Andrey Kuzmin)</span></li>
<li>Fix a <span class="small-code">NullPointerException</span> in field by field recursive comparison when comparing null values. <span class="contributor">(Andrey Kuzmin)</span></li>
</ul>
<h3 class="page-header"><span id="assertj-core-2.9.0"></span>AssertJ Core 2.9.0 release : New and noteworthy</h3>
<p>Release date : 2018-01-02</p>
<p><b>This is the last release with new features for Java 7, the next 2.x releases will be bugfixes releases.</b></p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span>,
<span class="contributor">Marko Bekhta</span>,
<span class="contributor">epeee</span>,
<span class="contributor">Kseniya Panasyuk</span>,
<span class="contributor">Filip Hrisafov</span>,
<span class="contributor">Marco Leichsenring</span>,
<span class="contributor">João Delgado</span>,
<span class="contributor">Florent Biville</span>,
<span class="contributor">BillyYccc</span>,
<span class="contributor">Rudi Klassen</span>,
<span class="contributor">Daniel Weber</span>,
<span class="contributor">Chris Arnott</span>,
<span class="contributor">Bojan Trajkovski</span>,
and <span class="contributor">cal101</span> for their contributions.</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category"> Breaking changes:</div>
<ul>
<li><a href="#assertj-core-2.9.0-containsSequence"><span class="small-code">containsSequence</span></a> String assertion now fails if it finds values between the given sequence, use <a href="#assertj-core-2.9.0-containsSubsequence"><span class="small-code">containsSubsequence</span></a> to get the old behavior.</li>
<li><a href="#assertj-core-2.9.0-isBlank"><span class="small-code">isBlank</span></a> String assertion now considers null or empty as blank, use <a href="#assertj-core-2.9.0-containsOnlyWhitespaces"><span class="small-code">containsOnlyWhitespaces</span></a> to get the old behavior.</li>
<li><a href="#assertj-core-2.9.0-isCloseTo"><span class="small-code">assertThat(x).isCloseTo(y, byLessThan(delta))</span></a> Number assertion is now strict and fails when |x-y|=delta.</li>
<li>Compare <span class="small-code">double</span> with a precision of <span class="small-code">1e-15</span> and <span class="small-code">float</span> with <span class="small-code">1e-6f</span> in element by element comparison.</li>
<li>Do not check actual or expected for null before comparing them with a custom comparator (i.e. the comparator should take care of that).</li>
</ul>
<div class="release-section-category"> Deprecation:</div>
<ul>
<li><span class="small-code">isJavaBlank</span></a> String assertion, use <a href="#assertj-core-2.9.0-isBlank"><span class="small-code">isBlank</span></a> or <a href="#assertj-core-2.9.0-containsOnlyWhitespaces"><span class="small-code">containsOnlyWhitespaces</span></a> instead.</li>
</ul>
<div class="release-section-category">New features :</div>
<ul>
<li>Allow to skip tests when <a href="#assertj-core-2.9.0-assumptions">Assumptions</a> are not met. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add <a href="#assertj-core-2.9.0-doesNotHaveAnyElementsOfTypes"><span class="small-code">doesNotHaveAnyElementsOfTypes</span></a> iterable/array assertions. <span class="contributor">(cal101)</span></li>
<li>Add <a href="#assertj-core-2.9.0-containsExactlyInAnyOrderElementsOf"><span class="small-code">containsExactlyInAnyOrderElementsOf</span></a> to iterable/array assertions. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Add <a href="#assertj-core-2.9.0-assertContainsOnlyNulls"><span class="small-code">assertContainsOnlyNulls</span></a> to iterable/array assertions. <span class="contributor">(BillyYccc)</span></li>
<li>Add <a href="#assertj-core-2.9.0-containsAnyOf"><span class="small-code">containsAnyOf</span></a> to iterable/array assertions. <span class="contributor">(Marko Bekhta)</span></li>
<li>Support converting an <a href="#assertj-core-2.9.0-hamcrestMatcherAsCondition">Hamcrest Matcher to an AssertJ Condition</a>. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Provide an SPI to <a href="#assertj-core-2.9.0-registerSpi">register a custom Representation</a>. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Add <a href="#assertj-core-2.9.0-hasSameHashCodeAs"><span class="small-code">hasSameHashCodeAs</span></a> assertion. <span class="contributor">(Rudi Klassen)</span></li>
<li>Add <a href="#assertj-core-2.9.0-usingComparatorForType"><span class="small-code">usingComparatorForType</span></a> to iterable/array assertions. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add <a href="#assertj-core-2.9.0-isEqualToIgnoringNewLines"><span class="small-code">isEqualToIgnoringNewLines</span></a> to string assertions. <span class="contributor">(Daniel Weber)</span></li>
<li>Add <a href="#assertj-core-2.9.0-flatExtractingForMap"><span class="small-code">flatExtracting</span></a> for map assertions. <span class="contributor">(Daniel Weber)</span></li>
<li>Add <a href="#assertj-core-2.9.0-containsSubsequence"><span class="small-code">containsSubsequence</span></a> to string assertions. <span class="contributor">(BillyYccc)</span></li>
<li>Add <a href="#assertj-core-2.9.0-containsOnlyWhitespaces"><span class="small-code">containsOnlyWhitespaces</span></a> to string assertions. <span class="contributor">(Chris Arnott)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li><span class="small-code">doesNotContain</span> string assertion now accepts varargs. <span class="contributor">(BillyYccc)</span></li>
<li>When failing because arrays/iterables have different sizes <span class="small-code">containsExactly</span> error shows arrays/iterables differences. </li>
<li>Class based navigable assert: do not swallow reflection problems. <span class="contributor">(cal101)</span></li>
<li>Add cause description to soft assertion error (if any). </li>
<li>Better description of comparators used in element by element comparison. </li>
<li>Float and Double comparators now handle null values as always less than any other values. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Throw an AssertionError when using the extracting feature on a null object. <span class="contributor">(Marco Leichsenring)</span></li>
<li>Add missing <span class="small-code">@CheckReturnValue</span> annotations.</li>
<li><span class="small-code">usingComparatorForType</span> now accept comparators taking a superclass of the type to compare.</li>
<li>Add AssertJ Java 9 builds (with the classpath). <span class="contributor">(Pascal Schumacher)</span></li>
<li><span class="small-code">endsWith(T[])</span> now succeeds when given an empty array. <span class="contributor">(Florent Biville)</span></li>
<li>Use <span class="small-code">AssertionFailedError</span> from opentest4j if available on the classpath. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Code and tests refactoring. <span class="contributor">(João Delgado, Bojan Trajkovski, Filip Hrisafov)</span></li>
<li>A bunch of javadoc improvements. <span class="contributor">(Pascal Schumacher, epeee, Bojan Trajkovski)</span></li>
<li>Make configurable whether <span class="small-code">AbstractAssert#equals</span> throws an exception for 3rd party libraries integrating AssertJ. <span class="contributor">(Günther Grill)</span></li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li>Fix <span class="small-code">isBetween</span> and <span class="small-code">isStrictlyBetween</span> javadoc. <span class="contributor">(Chris Arnott)</span></li>
<li>When comparing objects field by field recursively and one of the field was a <span class="small-code">String</span> containing <span class="small-code">%</span>, AssertJ failed to build the error message. <span class="contributor">(Chris Arnott)</span></li>
<li>Fix <span class="small-code">FieldSupport.fieldValue</span> which was failing to extract a field when specified as primitive type.</li>
<li>Fix <span class="small-code">containsExactly</span> which did not correctly handle duplicate elements. <span class="contributor">(BillyYccc)</span></li>
</ul>
<h4 class="page-header"><span id="assertj-core-2.9.0-assumptions" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Allow to skip tests with unmet assumptions</h4>
<p>Use <span class="small-code">assumeThat</span> methods to express preconditions for test execution.
All AssertJ assertions can be reused to express assumptions. Assumptions support both JUnit and TestNG.</p>
<p>All tests with unmet assumptions are skipped (provided you express assumptions before the test content).</p>
<p>Example with met assumptions:</p>
<pre><code class="java">import static org.assertj.core.api.Assumptions.assumeThat;
// since this assumption is true ...
assumeThat(frodo.getRace()).isEqualTo(HOBBIT);
// ... this assertion is performed.
assertThat(fellowshipOfTheRing).doesNotContain(sauron);</code></pre>
<p>Example with unmet assumptions:</p>
<pre><code class="java">import static org.assertj.core.api.Assumptions.assumeThat;
// since this assumption is obviously false ...
assumeThat(frodo.getRace()).isEqualTo(ORC);
// ... this assertion is not performed and the test is skipped.
assertThat(fellowshipOfTheRing).contains(sauron);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-doesNotHaveAnyElementsOfTypes" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">doesNotHaveAnyElementsOfTypes</span> to iterable/array assertions</h4>
<p>Verifies that all elements in the actual <code>Iterable</code> do not have the specified types (including subclasses).</p>
<p>Example:</p>
<pre><code class="java">List<Number> numbers = new ArrayList<>();
numbers.add(1);
numbers.add(2);
numbers.add(3.0);
// successful assertion:
assertThat(numbers).doesNotHaveAnyElementsOfTypes(Long.class, Float.class);
// assertion failure:
assertThat(numbers).doesNotHaveAnyElementsOfTypes(Long.class, Integer.class);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-containsExactlyInAnyOrderElementsOf" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">containsExactlyInAnyOrderElementsOf</span> to iterable/array assertions</h4>
<p>Verifies that the actual iterable/array contains exactly the given iterable elements and nothing else, in any order.</p>
<p>Example:</p>
<pre><code class="java">// an Iterable is used in the example but this also works with arrays
Iterable<Ring> elvesRings = list(vilya, nenya, narya, vilya);
Iterable<Ring> elvesRingsDifferentOrder = list(nenya, narya, vilya, vilya);
// assertion succeeds
assertThat(elvesRings).containsExactlyInAnyOrder(elvesRingsDifferentOrder);
// assertion fails as vilya is contained twice in elvesRings
assertThat(elvesRings).containsExactlyInAnyOrder(list(vilya, nenya, narya));</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-assertContainsOnlyNulls" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">assertContainsOnlyNulls</span> to iterable/array assertions</h4>
<p>Verifies that the actual group contains only null elements and nothing else.</p>
<p>Example:</p>
<pre><code class="java">// assertion succeeds
Iterable<String> items = Arrays.asList(null, null, null);
assertThat(items).containsOnlyNulls();
// assertion fails because items2 contains a not null element
Iterable<String> items2 = Arrays.asList(null, null, "notNull");
assertThat(items2).containsOnlyNulls();
// assertion fails since an empty iterable does not contain anything and therefore not null
Iterable<String> empty = new ArrayList<>();
assertThat(empty).containsOnlyNulls();</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-containsAnyOf" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">containsAnyOf</span> to iterable/array assertions</h4>
<p>Verifies that the actual iterable/array contains at least one of the given values.</p>
<p>Example:</p>
<pre><code class="java">Iterable<String> abc = Arrays.asList("a", "b", "c");
// assertions succeeds
assertThat(abc).containsAnyOf("b")
.containsAnyOf("b", "c")
.containsAnyOf("a", "b", "c")
.containsAnyOf("a", "b", "c", "d")
.containsAnyOf("e", "f", "g", "b");
// assertions fail
assertThat(abc).containsAnyOf("d");
assertThat(abc).containsAnyOf("d", "e", "f", "g");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-hamcrestMatcherAsCondition" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Convert an Hamcrest Matcher to a Condition</h4>
<p>Allows to reuse Hamcrest matchers as Conditions.</p>
<p>Example:</p>
<pre><code class="java">import static org.hamcrest.core.StringContains.containsString;
Condition<String> aStringContaining123 = new HamcrestCondition<>(containsString("123"));
// assertions succeed
assertThat("abc123").is(aStringContaining123);
assertThat("def456").isNot(aStringContaining123);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-registerSpi" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Provide an SPI to register a custom Representation</h4>
<p>Allow to register a representation as a service discovered at program startup.
The advantage of registering a representation is that you don't need to do anything in your tests,
the java runtime will discover it and AssertJ will use it but it requires a bit more work than a simple call to <span class="small-code">Assertions.useRepresentation(Representation)</span>.</p>
<p>To register a Representation, you need to do several things:</p>
<ul>
<li>create a file named <span class="small-code">org.assertj.core.presentation.Representation</span> file in the <span class="small-code">META-INF/services</span> directory</li>
<li>put the fully qualified class name of your custom <span class="small-code">Representation</span> in it</li>
<li>make sure <span class="small-code">META-INF/services/org.assertj.core.presentation.Representation</span> is in the runtime classpath.</li>
</ul>
<p>We recommend that you extend <span class="small-code">StandardRepresentation</span> and override <span class="small-code">fallbackToStringOf(Object)</span>.
By doing this all the defaults of AssertJ would be applied and you can apply your own customization.</p>
<p>Placing <span class="small-code">META-INF/services/org.assertj.core.presentation.Representation</span> in <span class="small-code">src/test/resources</span> should be enough to put it in the classpath.</p>
The <a href="https://github.com/joel-costigliola/assertj-examples/tree/master/assertions-examples">assertj-examples</a> project provides a working example, see:
<ul>
<li>the <a href="https://github.com/joel-costigliola/assertj-examples/tree/master/assertions-examples/src/test/resources/META-INF/services"><span class="small-code">META-INF/services</span></a> directory content</li>
<li>the <a href="https://github.com/joel-costigliola/assertj-examples/tree/master/assertions-examples/src/test/resources/META-INF/services/org.assertj.core.presentation.Representation"><span class="small-code">org.assertj.core.presentation.Representation</span></a> file</li>
<li>the <a href="https://github.com/joel-costigliola/assertj-examples/tree/master/assertions-examples/src/test/java/org/assertj/examples/UseRegisteredRepresentationExample.java"><span class="small-code">UseRegisteredRepresentationExample</span></a> test example</li>
</ul>
<h4 class="page-header"><span id="assertj-core-2.9.0-hasSameHashCodeAs" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">hasSameHashCodeAs</span> assertion</h4>
<p>Verifies that the actual object has the same hashCode as the given object.</p>
<p>Example:</p>
<pre><code class='java'> // assertions will pass
assertThat(42L).hasSameHashCodeAs(42L);
assertThat("The Force").hasSameHashCodeAs("The Force");
assertThat(new Jedi("Yoda", "Blue")).hasSameHashCodeAs(new Jedi("Yoda", "Blue"));
// assertions will fail
assertThat(42L).hasSameHashCodeAs(2501L);
assertThat(null).hasSameHashCodeAs("The Force");
assertThat("The Force").hasSameHashCodeAs(null);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-usingComparatorForType" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">usingComparatorForType</span> to iterable/array assertions</h4>
<p>Allows to set a specific comparator for the given type of elements or their fields. It extends <span class="small-code">usingComparatorForElementFieldsWithType</span> by applying the provided comparator to elements themselves, not only to their fields.<p>
<p>Usage of this method affects comparators set by next methods:</p>
<ul>
<li><span class="small-code">usingFieldByFieldElementComparator}</span></li>
<li><span class="small-code">usingElementComparatorOnFields}</span></li>
<li><span class="small-code">usingElementComparatorIgnoringFields}</span></li>
<li><span class="small-code">usingRecursiveFieldByFieldElementComparator}</span></li>
</ul>
<p>Example:</p>
<pre><code class='java'>
// assertion will pass as BigDecimal comnparator 1.0 is equalto to 1.00
assertThat(asList("some", new BigDecimal("4.2")))
.usingComparatorForType(BIG_DECIMAL_COMPARATOR, BigDecimal.class)
.contains(new BigDecimal("4.20"));
</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-isEqualToIgnoringNewLines" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isEqualToIgnoringNewLines</span> to string assertions</h4>
<p>Verifies that the actual <span class="small-code">String</span> is equal to the given one after both strings new lines (\n, \r\n) have been removed.</p>
<p>Example:</p>
<pre><code class='java'>// assertions succeed
assertThat("Some text\nWith new lines").isEqualToIgnoringNewLines("Some textWith new lines")
.isEqualToIgnoringNewLines("Some text\nWith new lines")
.isEqualToIgnoringNewLines("Some text\r\nWith new lines")
.isEqualToIgnoringNewLines("Some text\n\nWith new lines");
// assertion fails
assertThat("Some text\nWith new lines").isEqualToIgnoringNewLines("Some text With new lines");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-flatExtractingForMap" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">flatExtracting</span> to map assertions</h4>
<p>Flatten the values of the given keys from the actual map under test into a new array, this new array becoming the object under test.
The order of values in the resulting array is the order of the map keys iteration then key values.</p>
<p>If a given key is not present in the map under test, a null value is extracted.</p>
<p>If a given key value is not an <span class="small-code">Iterable</span> or an array, it is simply extracted but (obviously) not flattened.</p>
<p>If a given key value is an <span class="small-code">Iterable</span> or an array, it is flattened.</p>
<p>Example:</p>
<pre><code class='java'>List<String> names = asList("Dave", "Jeff");
LinkedHashSet<String> jobs = newLinkedHashSet("Plumber", "Builder");
Iterable<String> cities = asList("Dover", "Boston", "Paris");
int[] ranks = { 1, 2, 3 };
Map<String, Object> map = new LinkedHashMap<>();
map.put("name", names);
map.put("job", jobs);
map.put("city", cities);
map.put("rank", ranks);
assertThat(map).flatExtracting("name", "job", "city", "rank")
.containsExactly("Dave", "Jeff",
"Plumber", "Builder",
"Dover", "Boston", "Paris",
1, 2, 3);
// the order of values in the resulting array is the order of map keys then key values:
assertThat(map).flatExtracting("city", "job", "name")
.containsExactly("Dover", "Boston", "Paris",
"Plumber", "Builder",
"Dave", "Jeff");
// contains exactly null twice (one for each unknown keys)
assertThat(map).flatExtracting("foo", "name", "bar")
.containsExactly(null, "Dave", "Jeff", null);
// if the key value is not an iterable/array, it will be simply extracted but not flattened:
map.put("year", 2017);
assertThat(map).flatExtracting("name", "job", "year")
.containsExactly("Dave", "Jeff", "Plumber", "Builder", 2017);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-containsSequence" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Breaking change: <span class="small-code">containsSequence</span> string assertion</h4>
<p>Verifies that the actual <span class="small-code">String</span> contains the given sequence of values in the given order and since 2.9.0/3.9.0 <b>without any other values between them</b>.</p>
<p>This behavior is consistent with iterable/array <span class="small-code">containsSequence</span> assertion.</p>
<p>If you need the old behavior, simply use the <a href="#assertj-core-2.9.0-containsSubsequence"><span class="small-code">containsSubsequence</span></a> assertion instead.</p>
<p>Example:</p>
<pre><code class='java'>String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}";
// this assertions succeed, you can use a varargs or an iterable to provide the sequence
assertThat(book).containsSequence("'title'", ":", "'A Game of Thrones'");
assertThat(book).containsSequence(Arrays.asList("'title'", ":", "'A Game of Thrones'"));
// this assertion will fail because there are values between the expected sequence (e.g "'title':'")
// this used to pass before 2.9.0/3.9.0
assertThat(book).containsSequence("{", "A Game of Thrones", "George Martin", "}");
// this one fails as ":" must come after "'title'"
assertThat(book).containsSequence(":", "'title'", "'A Game of Thrones'");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-containsSubsequence" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">containsSubsequence</span> to string assertions</h4>
<p>Verifies that the actual <span class="small-code">String</span> contains the given values in the given order, <b>possibly with other values between them</b>.</p>
<p>Example:</p>
<pre><code class='java'>String book = "{ 'title':'A Game of Thrones', 'author':'George Martin'}";
// this assertions succeed, you can use a varargs or an iterable to provide the subsequence
assertThat(book).containsSubsequence("'title'", ":", "'A Game of Thrones'");
assertThat(book).containsSubsequence(Arrays.asList("'title'", ":", "'A Game of Thrones'");
// this one too even if there are values between the expected sequence (e.g "'title':'")
assertThat(book).containsSubsequence("{", "A Game of Thrones", "George Martin", "}");
// this one fails as "author" must come after "A Game of Thrones"
assertThat(book).containsSubsequence("{", "author", "A Game of Thrones", "}");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-isBlank" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Breaking change: <span class="small-code">isBlank</span> string assertion </h4>
<p>Verifies that the actual <span class="small-code">String</span> is blank, i.e. is null, empty or consists of one or more whitespace characters (according to <span class="small-code"><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html?is-external=true#isWhitespace-char-">Character.isWhitespace(char)</a></span>).</p>
<p> The definition of "blank" has changed, the old behaviour is now under <a href="#assertj-core-2.9.0-containsOnlyWhitespaces"><span class="small-code">containsOnlyWhitespaces</span></a>.</p>
<p>Example:</p>
<pre><code class='java'>// these assertions succeed:
assertThat(" ").isBlank();
assertThat("").isBlank();
assertThat(" ").isBlank();
String nullString = null;
assertThat(nullString).isBlank();
// these assertions fail:
assertThat("a").isBlank();
assertThat(" b").isBlank();
assertThat(" c ").isBlank();</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-containsOnlyWhitespaces" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">containsOnlyWhitespaces</span> to string assertions</h4>
<p>Verifies that the actual <span class="small-code">String</span> consists of one or more whitespace characters (according to <span class="small-code"><a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html?is-external=true#isWhitespace-char-">Character.isWhitespace(char)</a></span>).</p>
<p>Example:</p>
<pre><code class='java'>// these assertions succeed:
assertThat(" ").containsOnlyWhitespaces();
assertThat(" ").containsOnlyWhitespaces();
// these assertions fail:
assertThat("a").containsOnlyWhitespaces();
assertThat("").containsOnlyWhitespaces();
assertThat(" b").containsOnlyWhitespaces();
assertThat(" c ").containsOnlyWhitespaces();
String nullString = null;
assertThat(nullString).containsOnlyWhitespaces();</code></pre>
<h4 class="page-header"><span id="assertj-core-2.9.0-isCloseTo" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Breaking change: <span class="small-code">isCloseTo</span> number assertion when used with <span class="small-code">byLessThan</span></h4>
<p>Verifies that the actual number is close to the given one within the given offset value.</p>
<p>When <span class="small-code">abs(actual - expected) == offset</span> value, the assertion:</p>
<ul>
<li>succeeds when using <span class="small-code">Assertions.within(Integer)</span>.</li>
<li>fails when using <span class="small-code">Assertions.byLessThan(Integer)</span> or <span class="small-code">Offset.strictOffset(Number)</span>.</li>
</ul>
<p><b>Breaking change since 2.9.0/3.9.0:</b> using <span class="small-code">Assertions.byLessThan(Integer)</span> implies a strict comparison, use <span class="small-code">Assertions.within(Integer)</span> to get the old behavior.</p>
<p>Example:</p>
<pre><code class='java'>// assertions succeed:
assertThat(5).isCloseTo(7, within(3));
assertThat(5).isCloseTo(7, byLessThan(3));
// if difference is exactly equals to the offset, it's ok ...
assertThat(5).isCloseTo(7, within(2));
// ... but not with byLessThan which implies a strict comparison
assertThat(5).isCloseTo(7, byLessThan(2)); // FAIL
// assertions fail
assertThat(5).isCloseTo(7, within(1));
assertThat(5).isCloseTo(7, byLessThan(1));
assertThat(5).isCloseTo(7, byLessThan(2));</code></pre>
<h3 class="page-header"><span id="assertj-core-2.8.0"></span>AssertJ Core 2.8.0 release : New and noteworthy</h3>
<p>Release date : 2017-05-21</p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span> for his contributions.</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category"> Breaking changes:</div>
<ul>
<li><a href="assertj-core-news.html#assertj-core-2.8.0-isEqualToIgnoringWhitespace"><span class="small-code">isEqualToIgnoringWhitespace</span></a> behavior has been changed to really ignore all whitespace, the old behavior has been kept in the better named <a href="assertj-core-news.html#assertj-core-2.8.0-isEqualToNormalizingWhitespace"><span class="small-code">isEqualToNormalizingWhitespace</span></a> assertion. <span class="contributor">(Pascal Schumacher)</span></li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li><span class="small-code">isCloseTo</span>/<span class="small-code">isNotCloseTo</span> assertions now handle NaN and infinity correctly. <span class="contributor">(Pascal Schumacher)</span></li>
</ul>
<h4 class="page-header"><span id="assertj-core-2.8.0-isEqualToIgnoringWhitespace" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Change <span class="small-code">isEqualToIgnoringWhitespace</span> behavior to really ignore all whitespace</h4>
<p>Verifies that the actual <span class="small-code">String</span> is equal to the given one, ignoring whitespace differences.</p>
<p>In the old behavior <span class="small-code">Strings</span> were compared after normalizing their whitespaces but not truly ignoring them (see <a href="assertj-core-news.html#assertj-core-2.8.0-isEqualToNormalizingWhitespace"><span class="small-code">isEqualToNormalizingWhitespace</span></a>).</p>
<p>Examples:</p>
<pre><code class="java">// assertions succeed
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("Game of Thrones")
.isEqualToIgnoringWhitespace(" Game of Thrones ")
.isEqualToIgnoringWhitespace(" Game of Thrones ")
.isEqualToIgnoringWhitespace("Gameof Thrones")
.isEqualToIgnoringWhitespace("Game of\tThrones")
.isEqualToIgnoringWhitespace("GameofThrones");
// this one succeeds but would have failed with the previous assertion behavior:
assertThat("Game of Thrones").isEqualToIgnoringWhitespace("GameofThrones");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.8.0-isEqualToNormalizingWhitespace" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isEqualToNormalizingWhitespace</span> to <span class="small-code">String</span> assertions</h4>
<p>This assertion behaves like the <b>old</b> <span class="small-code">isEqualToIgnoringWhitespace</span>. It verifies that the actual <span class="small-code">String</span> is equal to the given one, after the whitespace of both strings has been normalized.</p>
<p>To be precise, the following whitespace rules are applied:</p>
<ul>
<li>all leading and trailing whitespace of both actual and expected strings are ignored</li>
<li>any remaining whitespace, appearing within either string, is collapsed to a single space before comparison</li>
</ul>
<p>Example :</p>
<pre><code class="java">// assertions will pass
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Game of Thrones")
.isEqualToNormalizingWhitespace("Game of Thrones")
.isEqualToNormalizingWhitespace("Game of Thrones")
.isEqualToNormalizingWhitespace(" Game of Thrones ")
.isEqualToNormalizingWhitespace(" Game of Thrones ")
.isEqualToNormalizingWhitespace("Game of\tThrones")
.isEqualToNormalizingWhitespace("Game of Thrones");
// assertions will fail, after normalization we have whitespace differences
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("GameofThrones");
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Gameof Thrones");
assertThat("Game of Thrones").isEqualToNormalizingWhitespace("Gameo fThrones");</code></pre>
<h3 class="page-header"><span id="assertj-core-2.7.0"></span>AssertJ Core 2.7.0 release : New and noteworthy</h3>
<p>Release date : 2017-05-07</p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span>, <span class="contributor">epeee</span>, <span class="contributor">Kseniya Panasyuk</span>, <span class="contributor">Filip Hrisafov</span>, <span class="contributor">Drummond Dawson</span>,
<span class="contributor">Dmitrii Nikitin</span>, <span class="contributor">Julian Honnen</span>, <span class="contributor">Maurício Aniche</span>, <span class="contributor">Tomasz Kalkosiński</span>, <span class="contributor">Joey Bratton</span>,
<span class="contributor">Martin Winandy</span>, <span class="contributor">Christopher Arnott</span>, <span class="contributor">Ruben Dijkstra</span>, <span class="contributor">Michał Szkutnik</span> and <span class="contributor">Antoine Dessaigne</span> for their contributions.</p>
<p>I would like to specially thank (again) <span class="contributor">epeee</span> and <span class="contributor">Kseniya Panasyuk</span> for their many contributions, awesome guys !</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category">Deprecation :</div>
<ul>
<li><span class="small-code">hasFields</span> has been renamed to <span class="small-code">hasPublicFields</span> in <span class="small-code">Class</span> assertions and will be removed in future versions. </li>
</ul>
<div class="release-section-category">New features :</div>
<ul>
<li>Add <a href="assertj-core-news.html#assertj-core-2.7.0-future"><span class="small-code">Future</span> assertions</a>. <span class="contributor">(Ruben Dijkstra)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-2.7.0-atomic">atomic classes assertions</a>. <span class="contributor">(epeee)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-2.7.0-bigInteger"><span class="small-code">BigInteger</span> assertions</a>. <span class="contributor">(epeee)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-2.7.0-fields-methods">fields/methods</a> <span class="small-code">Class</span> assertions. <span class="contributor">(epeee, Filip Hrisafov)</span></li>
<li>Add <span class="small-code">Class</span> <a href="assertj-core-news.html#assertj-core-2.7.0-class-visibility">visibility</a> assertions. <span class="contributor">(epeee)</span></li>
<li>Add <span class="small-code">isOne</span> number assertion. <span class="contributor">(Drummond Dawson)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-2.7.0-normalizing-equals"><span class="small-code">isEqualToNormalizingNewlines</span></a> to verify that two strings are equal after normalizing newlines. <span class="contributor">(Maurício Aniche)</span></li>
<li>Add a <a href="assertj-core-news.html#assertj-core-2.7.0-hamcrest-matcher">Hamcrest Matcher</a> that reuses AssertJ assertions. <span class="contributor">(Tomasz Kalkosiński)</span></li>
<li>Add map <a href="assertj-core-news.html#assertj-core-2.7.0-hasEntrySatisfying">hasEntrySatisfying</a> condition assertion. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add map <a href="assertj-core-news.html#assertj-core-2.7.0-hasKeySatisfying">hasKeySatisfying</a> condition assertion. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add map <a href="assertj-core-news.html#assertj-core-2.7.0-hasValueSatisfying">hasValueSatisfying</a> condition assertion. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add iterable/array <a href="assertj-core-news.html#assertj-core-2.7.0-hasOnlyElementsOfTypes"><span class="small-code">hasOnlyElementsOfTypes</span></a> assertion. <span class="contributor">(Martin Winandy)</span></li>
<li>Add iterable/array <a href="assertj-core-news.html#assertj-core-2.7.0-doesNotContainSequence"><span class="small-code">doesNotContainSequence</span></a> assertion. <span class="contributor">(Christopher Arnott)</span></li>
<li>Add iterable/array <a href="assertj-core-news.html#assertj-core-2.7.0-doesNotContainSubsequence"><span class="small-code">doesNotContainSubsequence</span></a> assertion. <span class="contributor">(Christopher Arnott)</span></li>
<li>Add String <a href="assertj-core-news.html#assertj-core-2.7.0-doesNotContainPattern"><span class="small-code">doesNotContainPattern</span></a> assertion. <span class="contributor">(Michał Szkutnik)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>AssertJ is compatible with Java 9. <span class="contributor">(Pascal Schumacher)</span></li>
<li><span class="small-code">containsSequence</span> and <span class="small-code">containsSubSequence</span> can now take a <span class="small-code">List</span> parameter. <span class="contributor">(Christopher Arnott)</span></li>
<li>Provide a description of extracted fields unless one has already been given. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Custom description set by <span class="small-code">as/describedAs</span> is kept after after using <span class="small-code">extracting/extractingResultOf</span></li>
<li>Enable static code analysis tools (e.g. Findbugs) to detect incorrect API usage of "non-asserting" methods like describedAs, usingX. (<span class="contributor">Pascal Schumacher</span>)</li>
<li><span class="small-code">isEqualToComparingFieldByFieldRecursively</span> comparison improvements for unordered sets comparison.</span> <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Disambiguate field description in <span class="small-code">isEqualToComparingFieldByFieldRecursively</span> error message.</span></li>
<li>Expose <span class="small-code">extracting</span> for <span class="small-code">Map</span> assertion.</span></li>
<li>Replace null description by an empty one.</span></li>
<li>Do not hide root cause of IntrospectionError. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Extend stack trace filtering to custom assert classes. <span class="contributor">(Julian Honnen)</span></li>
<li>Mark JUnit dependency as optional. <span class="contributor">(Antoine Dessaigne)</span></li>
<li>Add stack trace in Throwable instanceOf assertions error message. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Code refactoring and cleanup. <span class="contributor">(Pascal Schumacher, epeee)</span></li>
<li>A bunch of javadoc improvements. <span class="contributor">(Pascal Schumacher, epeee)</span></li>
</ul>
<div class="release-section-category">Fixed Bugs :</div>
<ul>
<li>Fix field by field comparison that was ignoring field and type comparators when one of the field to compare was null.</li>
<li>Fix <span class="small-code">isZero</span> that should pass for negative double/float zero (and <span class="small-code">isNotZero</span> should fail).</li>
<li>Fix extracting properties implemented by default interface methods. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Fix <span class="small-code">ShouldHaveCause</span> exception error message that was inverting actual and expected causes. <span class="contributor">(Dmitrii Nikitin)</span></li>
<li>Fix a NPE in detailed <span class="small-code">ShouldBeEqual</span> error message for null values. <span class="contributor">(Julian Honnen)</span></li>
<li>Fix <span class="small-code">containsExactly</span> that was not honoring custom element comparator.</li>
</ul>
<h4 class="page-header"><span id="assertj-core-2.7.0-future" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">Future</span> assertions</h4>
<p>Add assertions for <a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/Future.html">Future</a> (<a href="http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/AbstractCompletableFutureAssert.html#method.summary">CompletableFuture assertions</a> are already available in AssertJ Core 3.x).</p>
<p>Example : </p>
<pre><code class="java">ExecutorService executorService = Executors.newSingleThreadExecutor();
// this future is going to complete (almost) immediately
Future<String>> future = executorService.submit(new Callable<String>>() {
@Override
public String call() throws Exception {
return "done";
}
});
// just to be sure the Future is complete
Thread.sleep(100);
assertThat(future).isDone()
.isNotCancelled();
// create a future that is going to take one second to complete
future = executorService.submit(new Callable<String>>() {
@Override
public String call() throws Exception {
Thread.sleep(1000);
return "done";
}
});
// not done yet (it will after one second)
assertThat(future).isNotDone()
.isNotCancelled();
future.cancel(true);
assertThat(future).isCancelled();</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-atomic" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add atomic classes assertions</h4>
<p>Add assertions for the following atomic classes:</p>
<ul>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicBoolean.html">AtomicBoolean</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicInteger.html">AtomicInteger</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicIntegerArray.html">AtomicIntegerArray</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicIntegerFieldUpdater.html">AtomicIntegerFieldUpdater</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLong.html">AtomicLong</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLongArray.html">AtomicLongArray</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicLongFieldUpdater.html">AtomicLongFieldUpdater</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicMarkableReference.html">AtomicMarkableReference</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReference.html">AtomicReference</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReferenceArray.html">AtomicReferenceArray</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicReferenceFieldUpdater.html">AtomicReferenceFieldUpdater</a></li>
<li><a href="https://docs.oracle.com/javase/8/docs/api/java/util/concurrent/atomic/AtomicStampedReference.html">AtomicStampedReference</a></li>
</ul>
<p>Atomic assertions are similar to their non atomic counterparts. For example the <span class="small-code">AtomicLong</span> assertion has the same methods as the <span class="small-code">Long</span> assertion.</p>
<p>Example : </p>
<pre><code class="java">import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.Assertions.withinPercentage;
// AtomicInteger assertions (AtomicLong assertions are similar)
AtomicInteger atomicInteger = new AtomicInteger(42);
assertThat(atomicInteger).hasValue(42)
.doesNotHaveValue(50)
.hasPositiveValue()
.hasValueLessThan(50)
.hasValueGreaterThan(40)
.hasValueBetween(40, 50)
.hasValueCloseTo(45, within(3))
.hasValueCloseTo(45, withinPercentage(10));
// AtomicBoolean assertions
AtomicBoolean atomicBoolean = new AtomicBoolean(true);
assertThat(atomicBoolean).isTrue();
// AtomicLongArray assertions
AtomicLongArray atomicLongArray = new AtomicLongArray(new long[] { 1, 2, 3 });
assertThat(atomicLongArray).isNotEmpty()
.startsWith(1, 2)
.endsWith(3);
// AtomicReference assertions
AtomicReference<String> atomicReference = new AtomicReference<>("foo");
assertThat(atomicReference).hasValue("foo")
.doesNotHaveValue("bar");
// AtomicReferenceArray assertions
AtomicReferenceArray<String> abc = new AtomicReferenceArray<>(new String[] { "a", "b", "c" });
assertThat(abc).contains("b", "a")
.contains("b", "a", "b");
// AtomicIntegerFieldUpdater assertions for TolkienCharacter's age which is a volatile public int field
AtomicIntegerFieldUpdater<TolkienCharacter> ageUpdater = newUpdater(TolkienCharacter.class, "age");
ageUpdater.set(gandalf, 25);
assertThat(ageUpdater).hasValue(25, gandalf);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-bigInteger" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add BigInteger assertions</h4>
<p>Extend existing number assertions to <span class="small-code">BigInteger</span>.</p>
<p>Examples: </p>
<pre><code class="java">import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.Assertions.withinPercentage;
BigInteger eleven = new BigInteger("11");
assertThat(BigInteger.TEN).isGreaterThan(BigInteger.ONE)
.isGreaterThanOrEqualTo(BigInteger.TEN)
.isLessThan(eleven)
.isLessThanOrEqualTo(BigInteger.TEN)
.isBetween(BigInteger.ONE, eleven)
.isCloseTo(eleven, within(BigInteger.ONE))
.isCloseTo(eleven, withinPercentage(20))
.isPositive()
.isNotNegative();
assertThat(BigInteger.ONE).isOne();</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-fields-methods" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add fields/methods Class assertions</h4>
<p>Add assertions to verify the existence and visibility of the fields and methods of a <span class="small-code">class</span>.</p>
<p>Examples: </p>
<pre><code class="java">class MySuperClass {
public void superMethod() {}
private void privateSuperMethod() {}
}
class MyClass extends MySuperClass {
// fields
public String fieldOne;
public String fieldTwo;
private String fieldThree;
// methods
public void methodOne() {}
private void methodTwo() {}
}
// field assertions
assertThat(MyClass.class).hasPublicFields("fieldTwo", "fieldOne")
.hasDeclaredFields("fieldThree", "fieldTwo", "fieldOne")
.hasOnlyPublicFields("fieldOne", "fieldTwo")
.hasOnlyDeclaredFields("fieldThree", "fieldTwo", "fieldOne");
// method assertions
assertThat(MyClass.class).hasMethods("methodOne", "methodTwo", "superMethod", "privateSuperMethod")
.hasPublicMethods("methodOne", "superMethod")
.hasDeclaredMethods("methodTwo", "methodOne");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-class-visibility" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add Class visibility assertions</h4>
<p>Verifies the visibility of a <span class="small-code">class</span>.</p>
<p>Examples: </p>
<pre><code class="java">assertThat(String.class).isPublic();
protected class MyClass {
// ...
}
assertThat(MyClass.class).isProtected();</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-normalizing-equals" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Assert that two strings are equal after normalizing newlines</h4>
<p>Verifies that two Strings are equal ignoring newline differences, that is considering <span class="small-code">'\r\n'</span> to be equal to <span class="small-code">'\n'</span>.</p>
<p>Examples: </p>
<pre><code class="java">String bookName = "Lord of the Rings\r\n";
assertThat(bookName).isEqualToNormalizingNewlines("Lord of the Rings\n");
// it does not ignore newlines though so this assertion fails:
assertThat("\n").isEqualToNormalizingNewlines("");</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-hamcrest-matcher" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add a Hamcrest Matcher that reuses AssertJ assertions</h4>
<p>Use AssertJ assertions as a Hamcrest Matcher by extending <span class="small-code">AssertionMatcher</span>.</p>
<p>Overriding classes should only implement the <span class="small-code">assertion(T)</span> method as <span class="small-code">Matcher.matches(T)</span> and <span class="small-code">SelfDescribing.describeTo(Description)</span> are provided.</p>
<p>If the matcher fails, the description will contain the stacktrace of the first failed assertion.</p>
<p>Example with Mockito: </p>
<pre><code class="java">verify(customerRepository).save(argThat(new AssertionMatcher<Customer>() {
@Override
public void assertion(Customer actual) {
assertThat(actual).hasName("John")
.hasAge(30);
}
})
);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-hasEntrySatisfying" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add map hasEntrySatisfying condition assertion</h4>
<p>Verifies that the actual map contains an entry satisfying the given entry or key and value <span class="small-code">Condition</span>.</p>
<p>Example: </p>
<pre><code class="java">Map<TolkienCharacter, Ring> ringBearers = new HashMap<>();
ringBearers.put(galadriel, nenya);
ringBearers.put(gandalf, narya);
ringBearers.put(elrond, vilya);
ringBearers.put(frodo, oneRing);
// entry Condition
Condition<Map.Entry<TolkienCharacter, Ring>> oneRingManBearer =
new Condition<Map.Entry<TolkienCharacter, Ring>>("One ring man bearer") {
public boolean matches(Map.Entry<TolkienCharacter, Ring> entry) {
return entry.getKey().getRace() == MAN && entry.getValue() == oneRing;
}
};
// key Condition
Condition<TolkienCharacter> isMan = new Condition<TolkienCharacter>("is man") {
public boolean matches(TolkienCharacter tolkienCharacter) {
return tolkienCharacter.getRace() == MAN;
}
};
// value Condition
Condition<Ring> oneRingBearer = new Condition<Ring>("One ring bearer") {
public boolean matches(Ring ring) {
return ring == oneRing;
}
};
// assertions fail
assertThat(ringBearers).hasEntrySatisfying(oneRingManBearer);
assertThat(ringBearers).hasEntrySatisfying(isMan, oneRingBearer);
ringBearers.put(isildur, oneRing);
// now assertions succeed since we have added isildur
assertThat(ringBearers).hasEntrySatisfying(oneRingManBearer);
assertThat(ringBearers).hasEntrySatisfying(isMan, oneRingBearer);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-hasKeySatisfying" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add map hasKeySatisfying condition assertion</h4>
<p>Verifies that the actual map contains an entry with a key satisfying the given <span class="small-code">Condition</span>.</p>
<p>Example: </p>
<pre><code class="java">Map<TolkienCharacter, Ring> ringBearers = new HashMap<>();
ringBearers.put(galadriel, nenya);
ringBearers.put(gandalf, narya);
ringBearers.put(elrond, vilya);
ringBearers.put(frodo, oneRing);
Condition<TolkienCharacter> isElf = new Condition<TolkienCharacter>("is elf") {
public boolean matches(TolkienCharacter tolkienCharacter) {
return tolkienCharacter.getRace() == ELF;
}
};
Condition<TolkienCharacter> isOrc = new Condition<TolkienCharacter>("is orc") {
public boolean matches(TolkienCharacter tolkienCharacter) {
return tolkienCharacter.getRace() == ORC;
}
};
// assertion will pass
assertThat(ringBearers).hasKeySatisfying(isElf);
// assertion will fail
assertThat(ringBearers).hasKeySatisfying(isOrc);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-hasValueSatisfying" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add map hasValueSatisfying condition assertion</h4>
<p>Verifies that the actual map contains an entry with a value satisfying the given <span class="small-code">Condition</span>.</p>
<p>Example: </p>
<pre><code class="java">Map<Ring, TolkienCharacter> ringBearers = new HashMap<>();
ringBearers.put(nenya, galadriel);
ringBearers.put(narya, gandalf);
ringBearers.put(vilya, elrond);
ringBearers.put(oneRing, frodo);
Condition<TolkienCharacter> isElf = new Condition<TolkienCharacter>("is elf") {
public boolean matches(TolkienCharacter tolkienCharacter) {
return tolkienCharacter.getRace() == ELF;
}
};
Condition<TolkienCharacter> isOrc = new Condition<TolkienCharacter>("is orc") {
public boolean matches(TolkienCharacter tolkienCharacter) {
return tolkienCharacter.getRace() == ORC;
}
};
// assertion will pass
assertThat(ringBearers).hasValueSatisfying(isElf);
// assertion will fail
assertThat(ringBearers).hasValueSatisfying(isOrc);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-hasOnlyElementsOfTypes" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add iterable/array hasOnlyElementsOfTypes assertion</h4>
<p>Verifies that all elements of the actual iterable/array are instances of the given types.</p>
<p>Example: </p>
<pre><code class="java">Iterable<? extends Object> objects = Arrays.asList("foo", new StringBuilder());
// assertions will pass
assertThat(objects).hasOnlyElementsOfTypes(CharSequence.class);
assertThat(objects).hasOnlyElementsOfTypes(String.class, StringBuilder.class);
// assertions will fail
assertThat(objects).hasOnlyElementsOfTypes(Number.class);
assertThat(objects).hasOnlyElementsOfTypes(String.class, Number.class);
assertThat(objects).hasOnlyElementsOfTypes(String.class);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-doesNotContainSequence" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add iterable/array doesNotContainSequence assertion</h4>
<p>Verifies that the actual iterable/array does not contain the given sequence. A sequence is defined as an ordered group of values <b>without extra values between them</b>.</p>
<p>Example: </p>
<pre><code class="java">Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass, the elements order is correct but there is a value between them (nenya)
assertThat(elvesRings).doesNotContainSequence(vilya, narya)
.doesNotContainSequence(nenya, vilya);
// assertions will fail since proper sequence are passed
assertThat(elvesRings).doesNotContainSequence(vilya, nenya);
assertThat(elvesRings).doesNotContainSequence(nenya, narya);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-doesNotContainSubsequence" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add iterable/array doesNotContainSubsequence assertion</h4>
<p>Verifies that the actual group does not contain the given subsequence. A subsequence is defined as an ordered group of values <b>with possibly extra values between them</b>.</p>
<p>Example: </p>
<pre><code class="java">Iterable<Ring> elvesRings = newArrayList(vilya, nenya, narya);
// assertions will pass
assertThat(elvesRings).doesNotContainSubsequence(nenya, vilya)
.doesNotContainSubsequence(narya, vilya);
// assertion will fail
assertThat(elvesRings).doesNotContainSubsequence(vilya, nenya);
assertThat(elvesRings).doesNotContainSubsequence(vilya, narya);</code></pre>
<h4 class="page-header"><span id="assertj-core-2.7.0-doesNotContainPattern" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add String doesNotContainPattern assertion</h4>
<p>Verifies that the actual <span class="small-code">String</span> does not contain the given regular expression expressed either as a <span class="small-code">Pattern</span> or a <span class="small-code">String</span>.</p>
<p>Examples: </p>
<pre><code class="java">// assertions will pass
assertThat("Frodo").doesNotContainPattern(Pattern.compile("Fr.ud"));
assertThat("Frodo").doesNotContainPattern("Fr.ud");
// assertions will fail
assertThat("Freud").doesNotContainPattern(Pattern.compile("Fr.ud"));
assertThat("Freud").doesNotContainPattern("Fr.ud");</code></pre>
<h3 class="page-header"><span id="assertj-core-2.6.0"></span>AssertJ Core 2.6.0 release : New and noteworthy</h3>
<p>Release date : 2016-11-21</p>
<p>Many thanks to <span class="contributor">Class Augner</span>, <span class="contributor">Pascal Schumacher</span>, <span class="contributor">Mike Wilkes</span>, <span class="contributor">Kseniya Panasyuk</span>, <span class="contributor">Valeriy Vyrva</span>, <span class="contributor">Chris Arnott</span>, <span class="contributor">Gaël Lhez</span> and <span class="contributor">Filip Hrisafov</span> for their contributions.</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category">New features :</div>
<ul>
<li>Add <a href="#assertj-core-2.6.0-soft-failure-methods">failure methods</a> to soft assertions. <span class="contributor">(Class Augner)</span></li>
<li>Add <a href="#assertj-core-2.6.0-fail-string-format"><span class="small-code">fail(String failureMessage, Object... args)</span></a> following <span class="small-code">String#format</span> pattern. </li>
<li>Add <a href="#assertj-core-2.6.0-byte-array-int-overload-assertions">integer-based</a> method overloads to <span class="small-code">ByteArrayAssert</span>. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Add <a href="#assertj-core-2.6.0-containsExactlyInAnyOrder"><span class="small-code">containsExactlyInAnyOrder</span></a> assertion for primitive arrays. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Add <a href="#assertj-core-2.6.0-hasSuppressedException"><span class="small-code">hasSuppressedException</span></a> throwable assertion. </li>
<li>Add <a href="#assertj-core-2.6.0-hasNoSuppressedExceptions"><span class="small-code">hasNoSuppressedExceptions</span></a> throwable assertion. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Add <a href="#assertj-core-2.6.0-hasEntrySatisfying"><span class="small-code">hasEntrySatisfying(K, Condition<? super V>)</span></a> map assertion. <span class="contributor">(Valeriy Vyrva)</span></li>
<li>Add <a href="#assertj-core-2.6.0-containsAnyOf"><span class="small-code">containsAnyOf(entries)</span></a> map assertion. </li>
<li>Add <a href="#assertj-core-2.6.0-isNotCloseTo"><span class="small-code">isNotCloseTo</span></a> number assertion. <span class="contributor">(Chris Arnott)</span></li>
<li>Add <a href="#assertj-core-2.6.0-isBlank"><span class="small-code">isBlank</span>/<span class="small-code">isNotBlank</span></a> string assertion. <span class="contributor">(Pascal Schumacher)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>Static fields should be ignored in field by field comparisons. <span class="contributor">(Mike Wilkes and Kseniya Panasyuk)</span></li>
<li>Add <span class="small-code">byLessThan</span> as an alias of <span class="small-code">within</span>/<span class="small-code">offset</span> for number assertions.</li>
<li><span class="small-code">usingComparatorForType</span> now accepts registered type subclasses instead of only an exact type match. (<span class="contributor">Filip Hrisafov</span>)</li>
<li>Limit the number of elements from an iterable/array/map that are printed in error messages to 1000. (<span class="contributor">Filip Hrisafov</span>)</li>
<li>Add many missing tests. (<span class="contributor">Filip Hrisafov</span>)</li>
<li>Provide @SafeVarargs for <span class="small-code">ListAssert</span> and <span class="small-code">IterableAssert</span>. (<span class="contributor">Gaël Lhez</span>)</li>
<li>Remove usage of <span class="small-code">java.beans.Introspection</span> to improve android compatibility. (<span class="contributor">Pascal Schumacher</span>)</li>
<li>Javadoc improvements ! (<span class="contributor">mainly by Pascal Schumacher</span>)</li>
</ul>
<div class="release-section-category">Fixed Bugs :</div>
<ul>
<li>OSGI manifest contains unnecassary import and export packages. <span class="contributor">(Cristiano Gavião)</span></li>
<li>Increase priority of custom comparators in <span class="small-code">isEqualToComparingFieldByFieldRecursively</span> so that custom comparators can be used for collection types and maps. <span class="contributor">(Pascal Schumacher)</span></li>
<li><span class="small-code">containsExactly</span> was broken when the used comparison strategy found duplicate elements.</li>
</ul>
<h4 class="page-header"><span id="assertj-core-2.6.0-soft-failure-methods" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add failure methods to soft assertions</h4>
<p><span class="small-code">fail</span> methods have been added to soft assertions filling the gap with standard assertions.</p>