forked from joel-costigliola/assertj
-
Notifications
You must be signed in to change notification settings - Fork 0
/
assertj-core-news.html
1295 lines (1063 loc) · 88 KB
/
assertj-core-news.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 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 latest releases</h1>
<ul>
<li><a href="#assertj-core-3.11.1">AssertJ core 3.11.1 release</a></li>
<li><a href="#assertj-core-3.11.0">AssertJ core 3.11.0 release</a></li>
<li><a href="#assertj-core-3.10.0">AssertJ core 3.10.0 release</a></li>
<li><a href="#assertj-core-3.9.1">AssertJ core 3.9.1 release</a></li>
<li><a href="#assertj-core-3.9.0">AssertJ core 3.9.0 release</a></li>
<li><a href="#assertj-core-3.8.0">AssertJ core 3.8.0 release</a></li>
<li><a href="#assertj-core-3.7.0">AssertJ core 3.7.0 release</a></li>
<li><a href="#assertj-core-3.6.2">AssertJ core 3.6.2 release</a> (bugfix)</li>
<li><a href="#assertj-core-3.6.1">AssertJ core 3.6.1 release</a> (bugfix)</li>
<li><a href="#assertj-core-3.6.0">AssertJ core 3.6.0 release</a></li>
<li><a href="#assertj-core-3.5.2">AssertJ core 3.5.2 release</a> (OSGi bugfix)</li>
<li><a href="#assertj-core-3.5.0">AssertJ core 3.5.0/3.5.1 release</a></li>
<li><a href="assertj-core-older-releases.html">AssertJ core older releases</a> (including 2.x and 1.x)</li>
</ul>
<h3 class="page-header"><span id="assertj-core-3.11.1"></span>AssertJ Core 3.11.1 bugfix release</h3>
<p>Release date : 2018-08-28</p>
<p>This release fixes Findbugs false positive on <span class="small-code">Assertions.fail</span> methods by annotating them with <span class="small-code">@CanIgnoreReturnValue</span>, thanks to <span class="contributor">Erhard Pointl</span> and <span class="contributor">Glenn Sheasby</span> for the fix.</p>
<h3 class="page-header"><span id="assertj-core-3.11.0"></span>AssertJ Core 3.11.0 release : New and noteworthy</h3>
<p>Release date : 2018-08-15</p>
<p>Big thanks for all the contributors to this release:</p>
<ul>
<li><span class="contributor">Pascal Schumacher</span></li>
<li><span class="contributor">Erhard Pointl</span></li>
<li><span class="contributor">Stephan Windmüller</span></li>
<li><span class="contributor">Roland Weisleder</span></li>
<li><span class="contributor">Lars Hvile</span></li>
<li><span class="contributor">Valeriy Vyrva</span></li>
<li><span class="contributor">Günther Grill</span></li>
<li><span class="contributor">Fr Jeremy Krieg</span></li>
<li><span class="contributor">Drummond Dawson</span></li>
<li><span class="contributor">Thomas Weißschuh</span></li>
<li><span class="contributor">Alexandre Dutra</span></li>
</ul>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category"> Breaking changes</div>
<ul>
<li>Add <a href="#assertj-core-3.11.0-extracting"><span class="small-code">extracting(Function)</span></a> to <span class="small-code">Object</span> assertion that returns one value instead of a singleton list.</li>
<li>Favor throwing <span class="small-code">org.opentest4j.MultipleFailuresError</span> over <span class="small-code">SoftAssertionError</span> when soft assertions fails.</li>
</ul>
<div class="release-section-category">New features :</div>
<ul>
<li>Add <a href="#assertj-core-3.11.0-containsWhitespaces"><span class="small-code">containsWhitespaces()</span></a> to <span class="small-code">String/CharSequence</span> assertions. <span class="contributor">(Stephan Windmüller)</span></li>
<li>Add <a href="#assertj-core-3.11.0-doesNotContainAnyWhitespaces"><span class="small-code">doesNotContainAnyWhitespaces()</span></a> to <span class="small-code">String/CharSequence</span> assertions. <span class="contributor">(Stephan Windmüller)</span></li>
<li>Add <a href="#assertj-core-3.11.0-junit5-soft-assertions">JUnit 5 extensions</a> for soft assertions. <span class="contributor">(Roland Weisleder)</span></li>
<li>Add <a href="#assertj-core-3.11.0-hasContent"><span class="small-code">hasContent(String)</span></a> to <span class="small-code">InputStream</span> assertions. <span class="contributor">(Stephan Windmüller)</span></li>
<li>Add <a href="#assertj-core-3.11.0-hasDigest"><span class="small-code">hasDigest</span></a> to <span class="small-code">Path/File/InputStream</span> assertions. <span class="contributor">(Valeriy Vyrva)</span></li>
<li>Add <a href="#assertj-core-3.11.0-comparableStringAssertions"><span class="small-code">isLessThan,isLessThanOrEqualTo,isGreaterThan</span> and <span class="small-code">isGreaterThanOrEqualTo</span></a> to <span class="small-code">String</span> assertions.</span></li>
<li>Add <a href="#assertj-core-3.11.0-isBetween"><span class="small-code">isBetween</span> and <span class="small-code">isStrictlyBetween</span></a> to <span class="small-code">String</span> assertions.</span></li>
<li>Add <a href="#assertj-core-3.11.0-satisfiesWithCondition"><span class="small-code">satisfies(Condition)</span></a> base assertion.</span></li>
<li>Add <a href="#assertj-core-3.11.0-filteredOnAssertions"><span class="small-code">filteredOnAssertions(Consumer)</span></a> to <span class="small-code">Iterable</span> assertions.</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>Clarify how <span class="small-code">Stream</span> assertions are lazy initialized into List assertions.</li>
<li>Improve satisfies list assertion javadoc.</li>
<li><span class="small-code">hasMessage</span> fails with an <span class="small-code">AssertionFailedError</span> allowing to compare actual and expected messages visually in IDEs.</li>
<li>Improve error message of <span class="small-code">Iterable</span> <span class="small-code">allSatisfy</span> assertion.</li>
<li>Make AssertJ compatible with Java 11. <span class="contributor">(Erhard Pointl)</span> </li>
<li>Improve <span class="small-code">normalizeWhitespace</span> and <span class="small-code">removeAllWhitespaces</span> performance. <span class="contributor">(Pascal Schumacher)</span></li>
<li>A <b>lot</b> of internal improvements by <span class="contributor">Pascal Schumacher</span> !</li>
<li>Javadoc improvements. <span class="contributor">(Pascal Schumacher)</span></li>
<li>allows <span class="small-code">fail()</span> to be used where the java compiler expects a value like <span class="small-code">Optional.orElseGet()</span>. <span class="contributor">(Thomas Weißschuh)</span></li>
<li>Better disambiguation of objects with the same <span class="small-code">toString()</span> representation in error message. <span class="contributor">(Alexandre Dutra)</span></li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li>Fix if-else logic in <span class="small-code">PredicateAssert</span>. <span class="contributor">(Lars Hvile)</span></li>
<li>Fix <span class="small-code">ClassCastException</span> on <span class="small-code">SortedSet</span> assertions when chained after <span class="small-code">extracting</span>.</li>
<li>Fix missing OSGI <span class="small-code">Import-Package</span>.</li>
<li>Fix <span class="small-code">isToday</span> error message that inverted actual and expected dates. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Remove spurious <span class="small-code">@CheckReturnValue</span> from <span class="small-code">assertThatThrownBy/thenThrownBy</span>. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Fix parameter names in <span class="small-code">isStrictlyBetween</span> that used the word inclusive instead of exclusive. <span class="contributor">(Günther Grill)</span></li>
<li>Fix missing OSGi Import-Package for dynamically loaded classes. <span class="contributor">(Fr Jeremy Krieg)</span></li>
<li>Fix compilation error <span class="small-code">containsAnyElementsOf</span> by using bounded wildcard parameter. <span class="contributor">(Drummond Dawson)</span></li>
</ul>
<h4 class="page-header"><span id="assertj-core-3.11.0-extracting" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">extracting(Function)</span> to <span class="small-code">Object</span> assertion to extract one value</h4>
<p>Uses the given <span class="small-code">Function</span> to extract a value from the object under test, the extracted value becoming the new object under test.</p>
<p>Note that since the value is extracted as an <span class="small-code">Object</span>, only <span class="small-code">Object</span> assertions can be chained after extracting.</p>
<p>Example:</p>
<pre><code class='java'>// Create frodo, setting its name, age and Race
TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
// let's extract and verify Frodo's name:
assertThat(frodo).extracting(TolkienCharacter::getName)
.isEqualTo("Frodo");
// The extracted value being a String, we would like to use String assertions
// but we can't due to Java generics limitations.
// The following assertion does NOT compile !
assertThat(frodo).extracting(TolkienCharacter::getName)
.startsWith("Fro");</code></pre>
<p>This is a <b>breaking change</b> as previously <span class="small-code">extracting(TolkienCharacter::getName)</span> would be resolved to <span class="small-code">extracting(Function... extractors)</span> and return a (singleton) list.</p>
<pre><code class='java'>// previous to 3.11, extracting returns a singleton list:
assertThat(frodo).extracting(TolkienCharacter::getName)
// use list assertion and not isEqualTo("Frodo") although
// compiling it would fail as a list is expected
.containsExactly("Frodo");</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-containsWhitespaces" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">containsWhitespaces()</span></a> to <span class="small-code">String/CharSequence</span> assertions</h4>
<p>Verifies that the actual <span class="small-code">CharSequence</span> contains one or more whitespace characters according to <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html?is-external=true#isWhitespace-char-"><span class="small-code">Character.isWhitespace(char)</span></a>.</p>
<p>Examples:</p>
<pre><code class='java'>assertThat(" ").containsWhitespaces();
assertThat("a b").containsWhitespaces();
assertThat(" c ").containsWhitespaces();</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-doesNotContainAnyWhitespaces" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">doesNotContainAnyWhitespaces()</span></a> to <span class="small-code">String/CharSequence</span> assertions</h4>
<p>Verifies that the actual <span class="small-code">CharSequence</span> is either null, empty or does not contain any whitespace characters according to <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/Character.html?is-external=true#isWhitespace-char-"><span class="small-code">Character.isWhitespace(char)</span></a>.</p>
<p>Examples:</p>
<pre><code class='java'>assertThat("a").doesNotContainAnyWhitespaces();
assertThat("").doesNotContainAnyWhitespaces();
assertThat("ab").doesNotContainAnyWhitespaces();
String nullString = null;
assertThat(nullString).doesNotContainAnyWhitespaces();</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-junit5-soft-assertions" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add JUnit 5 extensions for soft assertions</h4>
<p>Make AssertJ soft assertions usable with JUnit 5, this is equivalent of the Junit 4 <a href="assertj-core-features-highlight.html#JUnitSoftAssertions">soft assertions rule</a> that calls <span class="small-code">assertAll</span> for you.</p>
<p>Soft assertions examples:</p>
<pre><code class='java'>public class SoftlyTest {
@RegisterExtension
public final JUnitJupiterSoftAssertions softly = new JUnitJupiterSoftAssertions();
@Test
public void soft_assertions() throws Exception {
softly.assertThat(1).isEqualTo(2);
softly.assertThat(Lists.newArrayList(1, 2)).containsOnly(1, 2);
}
}</code></pre>
<p>BDD Soft assertions examples:</p>
<pre><code class='java'>public class SoftlyTest {
@RegisterExtension
public final JUnitJupiterBDDSoftAssertions softly = new JUnitJupiterBDDSoftAssertions();
@Test
public void soft_bdd_assertions() throws Exception {
softly.then(1).isEqualTo(2);
softly.then(Lists.newArrayList(1, 2)).containsOnly(1, 2);
}
}</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-hasContent" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> <span class="small-code">hasContent(String)</span> to <span class="small-code">InputStream</span> assertions</h4>
<p>Verifies that the content of the actual <span class="small-code">InputStream</span> is equal to the given <span class="small-code">String</span>.</p>
<p>Examples:</p>
<pre><code class='java'>InputStream inputStream = new ByteArrayInputStream("a".getBytes());
assertThat(inputStream).hasContent("a");</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-hasDigest" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> <span class="small-code">hasDigest</span> to <span class="small-code">Path/File/InputStream</span> assertions</h4>
<p>Verifies that the <span class="small-code">Path/File/InputStream</span> digest calculated with the specified algorithm is equal to the given value (either a <span class="small-code">String</span> or a <span class="small-code">byte[]</span>).</p>
<p>You can specify the message digest algorithm with <span class="small-code">MessageDigest</span> or a <span class="small-code">String</span>.</p>
<p>Examples:</p>
<pre><code class='java'>// assume that assertj-core-2.9.0.jar was downloaded from https://repo1.maven.org/maven2
InputStream is = new FileInputStream(new File("assertj-core-2.9.0.jar"));
assertThat(is).hasDigest("SHA1", "5c5ae45b58f12023817abe492447cdc7912c1a2c")
.hasDigest("MD5", "dcb3015cd28447644c810af352832c19")
.hasDigest(MessageDigest.getInstance("SHA1"), "5c5ae45b58f12023817abe492447cdc7912c1a2c")
.hasDigest(MessageDigest.getInstance("MD5"), "dcb3015cd28447644c810af352832c19")
// full byte array omitted for brevety sake
.hasDigest("SHA1", new byte[]{92, 90, ... })
.hasDigest(MessageDigest.getInstance("SHA1"), new byte[]{92, 90, ... });</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-comparableStringAssertions" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isLessThan[OrEqualTo],isGreaterThan[OrEqualTo]</span> to <span class="small-code">String</span> assertions</h4>
<p>Add the comparison operator <span class="small-code"><</span>, <span class="small-code"><=</span>, <span class="small-code">></span> and <span class="small-code">>=</span> to <span class="small-code">String</span> assertions.</p>
<p><span class="small-code">isLessThan</span> examples:</p>
<pre><code class='java'>assertThat("abc").isLessThan("bcd")
.isLessThan("b")
.isLessThan("abca")
.usingComparator(CASE_INSENSITIVE)
.isLessThan("BCD");</code></pre>
<p><span class="small-code">isLessThanOrEqualTo</span> examples:</p>
<pre><code class='java'>assertThat("abc").isLessThanOrEqualTo("bcd")
.isLessThanOrEqualTo("abc")
.isLessThanOrEqualTo("b")
.isLessThanOrEqualTo("abca")
.usingComparator(CASE_INSENSITIVE)
.isLessThanOrEqualTo("ABC");</code></pre>
<p><span class="small-code">isGreaterThan</span> examples:</p>
<pre><code class='java'>assertThat("xyz").isGreaterThan("abc")
.isGreaterThan("xy")
.isGreaterThan("ABC");
assertThat("XYZ").usingComparator(CASE_INSENSITIVE)
.isGreaterThan("abc");</code></pre>
<p><span class="small-code">isGreaterThanOrEqualTo</span> examples:</p>
<pre><code class='java'>assertThat("xyz").isGreaterThanOrEqualTo("abc")
.isGreaterThanOrEqualTo("xyz")
.isGreaterThanOrEqualTo("xy")
.isGreaterThanOrEqualTo("ABC");
assertThat("XYZ").usingComparator(CASE_INSENSITIVE)
.isGreaterThanOrEqualTo("abc");
</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-isBetween" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isBetween</span> and <span class="small-code">isStrictlyBetween</span> to <span class="small-code">String</span> assertions</h4>
<p><span class="small-code">isBetween</span> verifies that the actual value is in [start, end] range (start and end included) according to <span class="small-code">String</span>'s <a href="https://docs.oracle.com/javase/8/docs/api/java/lang/String.html?is-external=true#compareTo-java.lang.String-"><span class="small-code">compareTo</span></a>
method whereas <span class="small-code">isStrictlyBetween</span> excludes start and end (]start, end[).</p>
<p>Examples:</p>
<pre><code class='java'>// isBetween examples
assertThat("ab").isBetween("aa", "ac")
.isBetween("ab", "ac")
.isBetween("aa", "ab")
.isBetween("ab", "ab")
.isBetween("a", "c")
.usingComparator(CASE_INSENSITIVE)
.isBetween("AA", "AC");
// isStrictlyBetween examples
assertThat("ab").isStrictlyBetween("aa", "ac")
.isStrictlyBetween("a", "c")
.usingComparator(CASE_INSENSITIVE)
.isStrictlyBetween("AA", "AC");</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-satisfiesWithCondition" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">satisfies(Condition)</span> base assertion.</span></h4>
<p>Verifies that the actual value satisfies the given condition, this is an alias of <a href="http://joel-costigliola.github.io/assertj/core-8/api/org/assertj/core/api/ExtensionPoints.html#is-org.assertj.core.api.Condition-"><span class="small-code">is(Condition)</span></a> except for the wording of the error message that uses <i>satisfies</i> in place of <i>is</i>.</p>
<p>Example:</p>
<pre><code class='java'>// Given
Condition<String> fairyTale = new Condition<>(s -> s.startsWith("Once upon a time"), "fairy tale start");
// When
String littleRedCap = "Once upon a time there was a dear little girl ...";
// Then
assertThat(littleRedCap).satisfies(fairyTale);</code></pre>
<h4 class="page-header"><span id="assertj-core-3.11.0-filteredOnAssertions" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">filteredOnAssertions(Consumer)</span> to <span class="small-code">Iterable</span> assertions.</span></h4>
<p>Filter the iterable under test keeping only elements matching the given assertions specified with a <a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html?is-external=true"><span class="small-code">Consumer</span></a>.</p>
<p>Example:</p>
<pre><code class='java'>// Given
TolkienCharacter pippin = new TolkienCharacter("Pippin", 28, HOBBIT);
TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
TolkienCharacter merry = new TolkienCharacter("Merry", 36, HOBBIT);
TolkienCharacter sam = new TolkienCharacter("Sam", 38, HOBBIT);
// When
List<TolkienCharacter> hobbits = list(frodo, sam, merry, pippin);
// Then
assertThat(hobbits).filteredOnAssertions(hobbit -> assertThat(hobbit.age).isLessThan(34))
.containsOnly(frodo, pippin);</code></pre>
<!-- //////////////////////////////////////////////////////////////////////////////////////////////////////////////////////// -->
<h3 class="page-header"><span id="assertj-core-3.10.0"></span>AssertJ Core 3.10.0 release : New and noteworthy</h3>
<p>Release date : 2018-05-12</p>
<p>This release improves soft assertions performance that decreased after migrating to <a href="http://bytebuddy.net/#/">byte buddy</a> (the migration was necessary as cglib had non fixable issues).
Although it is still slower than cglib based soft assertions, this version is much faster than 3.9.1. Thanks to <span class="contributor">Rafael Winterhalter</span> and <span class="contributor">testn</span> for their help.</p>
<p>The other contributors to this release are <span class="contributor">Pascal Schumacher</span>,
<span class="contributor">Andrey Kuzmin</span>,
<span class="contributor">Marcel Overdijk</span>,
<span class="contributor">Jacek Jackowiak</span>,
<span class="contributor">HugoHo0212</span>,
<span class="contributor">f4lco</span>,
<span class="contributor">Andrew Auclair</span>,
<span class="contributor">valery1707</span>,
<span class="contributor">Bernd Farka</span>,
<span class="contributor">nebehr</span>,
and <span class="contributor">Piotr Swiatowski</span>. Thanks guys!</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category">New features :</div>
<ul>
<li>Add <span class="small-code">isUpperCase/isLowerCase</span> to <span class="small-code">String/CharSequence</span> assertions. <span class="contributor">(Marcel Overdijk)</span></li>
<li>Add <a href="#assertj-core-3.10.0-satisfies_for_list"><span class="small-code">satisfies(consumer, index)</span></a> to list assertions. <span class="contributor">(Jacek Jackowiak)</span></li>
<li>Add <a href="#assertj-core-3.10.0-noneSatisfy"><span class="small-code">noneSatisfy(consumer)</span></a> to iterable/array assertions. <span class="contributor">(Bernd Farka)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>Propagate assertion context (description, overridden error message, representation and comparators):</span></li>
<ul>
<li>after filtering iterables</li>
<li>after <span class="small-code">extracting</span>, <span class="small-code">flatExtracting</span> and <span class="small-code">extractingResultOf</span> methods</li>
<li>on methods changing the object under test for soft assertions and assumptions</li>
</ul>
<li>Exclude proxied class from SoftAssertions line number (in error stacktrace).</span></li>
<li><span class="small-code">zipSatisfy</span> now returns all zipped pairs not meeting the given requirements (instead of the first one).</span></li>
<li>Fix varargs warning on Map assertion <span class="small-code">extracting</span>.</li>
<li>CompletableFuture representation now displays stacktrace when completed exceptionally. <span class="contributor">(Piotr Swiatowski)</span></li>
<li>Improve <span class="small-code">TypeComparators</span> initialization resolving a performance degradation introduced in 3.9.1.</li>
<li>Allow overriding collected errors list modification.</li> <span class="contributor">(nebehr)</span></li>
<li>Close stream after lazy init of list assertions from stream. <span class="contributor">(f4lco)</span></li>
<li>Add <span class="small-code">org.assertj.core</span> as Automatic-Module-Name in Manifest file. <span class="contributor">(Andrew Auclair)</span></li>
<li>Make constructors of <span class="small-code">ThrowableAssertAlternative</span> and <span class="small-code">ThrowableTypeAssert</span> public and <span class="small-code">ThrowableTypeAssert</span> fields protected for better extensibility.</li>
<li>Internal code improvements. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Javadoc improvements. <span class="contributor">(Pascal Schumacher)</span>, <span class="contributor">(valery1707)</span></li>
<li>README.md improvements. <span class="contributor">(HugoHo0212)</span></li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li>SortedSet assertions now honor the <span class="small-code">SortedSet</span> comparator.</li>
<li>Fix Map assertion <span class="small-code">extracting</span> that was limited to extracting values from String keys, it now accepts any Object keys.</li>
<li>Fix <span class="small-code">asList()</span> that was not honoring the given description. <span class="contributor">(Andrey Kuzmin)</span></li>
<li>Fix soft assertions that did not handle correctly formatting error messages with double <span class="small-code">%</span>.</li>
<li>Strongly typed navigation assertions were not supported after <span class="small-code">filteredOn</span> operations.</li>
</ul>
<h4 class="page-header"><span id="assertj-core-3.10.0-satisfies_for_list" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">satisfies(consumer, index)</span> to list assertions</h4>
<p>Verifies that the actual list contains a value at given index that satisfies the given requirements.</p>
<p>Example:</p>
<pre><code class='java'>List<TolkienCharacter> ringBearers = newArrayList(frodo, elrond, gandalf);
// this assertion will pass
assertThat(ringBearers).satisfies(ringBearer -> {
assertThat(ringBearer.getAge()).isGreaterThan(200);
assertThat(ringBearer.getRace()).isEqualTo(ELF);
},
atIndex(1));
// this assertion will fail
assertThat(ringBearers).satisfies(ringBearer -> {
assertThat(ringBearer.getRace()).isEqualTo(ELF);
},
atIndex(0);</code></pre>
<h4 class="page-header"><span id="assertj-core-3.10.0-noneSatisfy" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> <span class="small-code">noneSatisfy(consumer)</span> to iterable/array assertions</h4>
<p>Verifies that no elements satisfy the given restrictions expressed as a <span class="small-code">Consumer</span>.</p>
<p>Example:</p>
<pre><code class='java'>// assume that all icelander in myIcelanderFriends are not from Brazil
assertThat(myIcelanderFriends).noneSatisfy(friend -> {
assertThat(friend.getCountry()).isEqualTo("Brazil");
});</code></pre>
<h3 class="page-header"><span id="assertj-core-3.9.1"></span>AssertJ Core 3.9.1 release : New and noteworthy</h3>
<p>Release date : 2018-02-21</p>
<p>This release is mainly a bugfix release, a notable highlight is the migration to <a href="http://bytebuddy.net/#/">byte buddy</a>
and a bunch of fixes related to soft assertions for methods that change the object under test like <span class="small-code">asString()</span>,
<span class="small-code">extracting</span>, <span class="small-code">filteredOn</span>, ...</p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span>,
<span class="contributor">Erhard Pointl</span>,
<span class="contributor">Filip Hrisafov</span>,
<span class="contributor">Sebastien Arod</span>,
<span class="contributor">Simon Dudley</span>,
<span class="contributor">Gerard Szczepański</span>,
and <span class="contributor">Piotr Swiatowski</span> for their contributions.</p>
<p>Special thanks to <span class="contributor"><b>Rafael Winterhalter</b></span> (<a href="http://bytebuddy.net/#/">byte buddy</a> creator) for his help to migrate to byte buddy.</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category">New features :</div>
<ul>
<li>Add <span class="small-code">isEqualTo(long)</span> to integer assertions. <span class="contributor">(Erhard Pointl)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>Replace cglib with <a href="http://bytebuddy.net/#/">byte buddy</a>. <span class="contributor">(Filip Hrisafov, Rafael Winterhalter)</span></li>
<li>Javadoc improvements. <span class="contributor">(Erhard Pointl, Pascal Schumacher)</span></li>
<li>Bump internal dependencies. <span class="contributor">(Pascal Schumacher, Erhard Pointl)</span></li>
<li>Remove unnecessary optional ASM dependency. <span class="contributor">(Pascal Schumacher)</span></li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li>Fix soft assertions and assumptions that were not properly supporting methods changing the object under test, including:</li>
<ul>
<li><span class="small-code">extracting</span>, <span class="small-code">flatExtracting</span>, <span class="small-code">extractingResultOf</span>, <span class="small-code">filteredOn</span>, <span class="small-code">map</span>, <span class="small-code">flatMap</span></li>
<li>navigation assertions: <span class="small-code">size()</span>, <span class="small-code">first()</span>, <span class="small-code">element(index)</span>, <span class="small-code">last()</span></li>
<li>straight conversion: <span class="small-code">asString()</span> and <span class="small-code">asList()</span></li>
</ul>
<li>Fix <i>reference to assertThat is ambiguous</i> error introduced in 3.9.0 by moving <span class="small-code">assertThat(CompletionStage)</span> to <span class="small-code">AssertionsForInterfaceTypes</span> - <a href="https://github.com/joel-costigliola/assertj-core/issues/839">#839</a>.</li>
<li>Fix <span class="small-code">containsAnyOf</span> that only worked with comparable elements - <a href="https://github.com/joel-costigliola/assertj-core/issues/1154">#1154</a>.</li>
<li>Fix <span class="small-code">ClassNotFoundError</span> on OSGI when using soft assertions - <a href="https://github.com/joel-costigliola/assertj-core/issues/1160">#1160</a>. <span class="contributor">(Sebastien Arod)</span></li>
<li>Handle <span class="small-code">null</span> correctly in <span class="small-code">ZonedDateTimeAssert</span> <span class="small-code">isEqualTo</span> and <span class="small-code">isNotEqualTo</span> assertions - <a href="https://github.com/joel-costigliola/assertj-core/issues/1164">#1164</a>. <span class="contributor">(Piotr Swiatowski)</span></li>
<li>Fix (hopefully) all warning like: <i>A generic array of XXX is created for a varargs parameter</i> - <a href="https://github.com/joel-costigliola/assertj-core/issues/1157">#1157</a>.</li>
<li>Fix a regression in field by field recursive comparison where we stopped displaying an helpful error message - <a href="https://github.com/joel-costigliola/assertj-core/issues/1158">#1158</a>.</li>
<li>Fix a <span class="small-code">NullPointerException</span> in field by field recursive comparison when comparing null values - <a href="https://github.com/joel-costigliola/assertj-core/issues/1145">#1145</a>. <span class="contributor">(Simon Dudley)</span></li>
<li>Fix <span class="small-code">BigDecimal.isBetween</span> assertion that was failing when given the same start and end but with different scale - <a href="https://github.com/joel-costigliola/assertj-core/issues/1177">#1177</a>.</li>
</ul>
<h3 class="page-header"><span id="assertj-core-3.9.0"></span>AssertJ Core 3.9.0 release : New and noteworthy</h3>
<p>Release date : 2018-01-02</p>
<p>This release includes all changes from <a href="assertj-core-older-releases.html#assertj-core-2.9.0">AssertJ core 2.9.0</a> and adds the following that are Java 8 specific.</p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span>,
<span class="contributor">Rudi Klassen</span>,
<span class="contributor">Kseniya Panasyuk</span>,
<span class="contributor">Filip Hrisafov</span>,
<span class="contributor">Michael Keppler</span>,
<span class="contributor">Jeremy Landis</span>,
<span class="contributor">Pontus Alexander</span>,
<span class="contributor">Jean-Noël Rouvignac</span>,
<span class="contributor">Alberto Scotto</span>,
<span class="contributor">Fr Jeremy Krieg</span>,
<span class="contributor">Mike Kobit</span>,
and <span class="contributor">Thibault Kruse</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-3.9.0-anyMatch"><span class="small-code">anyMatch</span></a> to iterable/array assertions. <span class="contributor">(Jean-Noël Rouvignac)</span></li>
<li>Add <a href="#assertj-core-3.9.0-noneMatch"><span class="small-code">noneMatch</span></a> to iterable/array assertions. <span class="contributor">(Jean-Noël Rouvignac)</span></li>
<li>Add <a href="#assertj-core-3.9.0-allSatisfyForMap"><span class="small-code">allSatisfy</span></a> map assertion.</li>
<li>Add <a href="#assertj-core-3.9.0-zipSatisfy"><span class="small-code">zipSatisfy</span></a> assertion to check pairs built from two group of objects.</li>
<li>Add <a href="#assertj-core-3.9.0-catchThrowableOfType"><span class="small-code">catchThrowableOfType</span></a> to perform assertion on the caught throwable cast to the given type. <span class="contributor">(Fr Jeremy Krieg)</span></li>
<li>Allow performing <span class="small-code">Object</span> assertion on the <span class="small-code">Optional</span> value after calling <a href="#assertj-core-3.9.0-optional-get"><span class="small-code">get()</span></a>. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Add <a href="#assertj-core-2.9.0-assumptions">Assumptions</a> for Java 8 types to skip tests when preconditions are not satisfied.</li>
<li>Allow to set a description for <a href="#assertj-core-3.9.0-describe-assertThatThrownBy">assertThatThrownBy</a>.</li>
<li>Add a factory method to return a <span class="small-code">CompletableFuture</span> assertion from a <span class="small-code">CompletionStage</span>. <span class="contributor">(Thibault Kruse)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>Allow to <a href="#assertj-core-3.9.0-describe-assertThatExceptionOfType">use a description</a> after <span class="small-code">assertThatExceptionOfType</span> like assertions. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Align <span class="small-code">assertThat</span> methods between <span class="small-code">Assertions</span> and <span class="small-code">WithAssertions</span>. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Add missing <span class="small-code">thenCode</span> BDD assertion.</li>
<li>Print stack trace information when <span class="small-code">doesNotThrowAnyException</span> fails. <span class="contributor">(Mike Kobit)</span> </li>
<li>Warn users that the <span class="small-code">Future</span> state displayed in error messages might be different from the one at the time when the assertion was performed.</li>
<li>Javadoc improvements. <span class="contributor">(Pontus Alexander, Pascal Schumacher)</span></li>
<li>Contributor guide improvements. <span class="contributor">(Rudi Klassen)</span></li>
<li>Add openjdk8 build. <span class="contributor">(Jeremy Landis)</span></li>
<li>Maven build updates. <span class="contributor">(Jeremy Landis)</span></li>
<li>README.md improvements. <span class="contributor">(Michael Keppler)</span></li>
<li><span class="small-code">ShouldContainCharSequenceOnlyOnce</span> refactoring. <span class="contributor">(Alberto Scotto)</span></li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li>Fix a compiler error since 3.7.0 on <span class="small-code">assertThat(Stream)</span> when given an upper bounded <span class="small-code">Stream</span>.</li>
</ul>
<h4 class="page-header"><span id="assertj-core-3.9.0-anyMatch" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">anyMatch</span> to iterable/array assertions</h4>
<p>Verifies whether any iterable/array elements match the provided <span class="small-code">Predicate</span>.</p>
<p>Example:</p>
<pre><code class='java'>Iterable<String> abcc = newArrayList("a", "b", "cc");
// assertion will pass
assertThat(abcc).anyMatch(s -> s.length() == 2);
// assertion will fail
assertThat(abcc).anyMatch(s -> s.length() > 2);</code></pre>
<p>Note that you can achieve the same result with <span class="small-code">areNot(Condition)</span>/<span class="small-code">doNotHave(Condition)</span>.</p>
<h4 class="page-header"><span id="assertj-core-3.9.0-noneMatch" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">noneMatch</span> to iterable/array assertions</h4>
<p>Verifies that no iterable/array elements match the provided <span class="small-code">Predicate</span>.</p>
<p>Example:</p>
<pre><code class='java'>Iterable<String> abcc = newArrayList("a", "b", "cc");
// assertion will pass
assertThat(abcc).noneMatch(s -> s.isEmpty());
// assertion will fail
assertThat(abcc).noneMatch(s -> s.length() == 2);</code></pre>
<p>Note that you can achieve the same result with <span class="small-code">areAtLeastOne(Condition)</span>/<span class="small-code">haveAtLeastOne(Condition)</span>.</p>
<h4 class="page-header"><span id="assertj-core-3.9.0-allSatisfyForMap" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">allSatisfy</span> map assertion</h4>
<p>Verifies that all the actual map entries satisfy the given entry requirements.</p>
<p>If the actual map is empty <span class="small-code">allSatisfy</span> succeeds as there is nothing to check.</p>
<p>Example:</p>
<pre><code class='java'>Map<TolkienCharacter, Ring> elvesRingBearers = new HashMap<>();
elvesRingBearers.put(galadriel, nenya);
elvesRingBearers.put(gandalf, narya);
elvesRingBearers.put(elrond, vilya);
// this assertion succeeds
assertThat(elvesRingBearers).allSatisfy((character, ring) -> {
assertThat(character.getRace()).isIn(ELF, MAIA);
assertThat(ring).isIn(nenya, narya, vilya);
});
// this assertion fails as Gandalf is a maia and not an elf
assertThat(elvesRingBearers).allSatisfy((character, ring) -> {
assertThat(character.getRace()).isEqualTo(ELF);
assertThat(ring).isIn(nenya, narya, vilya);
});</code></pre>
<h4 class="page-header"><span id="assertj-core-3.9.0-zipSatisfy" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">zipSatisfy</span> assertion to check pairs built from two group of objects</h4>
<p>Verifies that the zipped pairs of actual and expected elements, i.e: (actual 1st element, expected 1st element), (actual 2nd element, expected 2nd element), ... all satisfy the given requirements.</p>
<p>This assertion assumes that actual and expected have the same size but they can contain different types of elements making it handy to compare objects converted to another type, for example Domain and View/DTO objects.</p>
<p>Example:</p>
<pre><code class='java'>List<Adress> addressModels = findGoodRestaurants();
List<AdressView> addressViews = convertToView(addressModels);
// compare addressViews and addressModels respective paired elements.
assertThat(addressViews).zipSatisfy(addressModels, (AdressView view, Adress model) -> {
assertThat(view.getZipcode() + ' ' + view.getCity()).isEqualTo(model.getCityLine());
assertThat(view.getStreet()).isEqualTo(model.getStreet().toUpperCase());
});</code></pre>
<h4 class="page-header"><span id="assertj-core-3.9.0-catchThrowableOfType" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">catchThrowableOfType</span> to perform assertion on the caught throwable cast to the given type</h4>
<p><span class="small-code">catchThrowableOfType</span> allows catching a <span class="small-code">Throwable</span> of a specific type <span class="small-code">T</span>.
If no exception is thrown it returns <span class="small-code">null</span> otherwise it checks that the caught Throwable is of type <span class="small-code">T</span> and casts it making it convenient to perform subtype-specific assertions on the throwable of type <span class="small-code">T</span>.</p>
<p>Example:</p>
<pre><code class='java'>class CustomParseException extends Exception {
int line;
int column;
public CustomParseException(String msg, int l, int c) {
super(msg);
line = l;
column = c;
}
}
CustomParseException e = catchThrowableOfType(() -> { throw new CustomParseException("boom!", 1, 5); },
CustomParseException.class);
// assertions pass
assertThat(e).hasMessageContaining("boom");
assertThat(e.line).isEqualTo(1);
assertThat(e.column).isEqualTo(5);
// succeeds as catchThrowableOfType returns null when the code does not thrown any exceptions
assertThat(catchThrowableOfType(() -> {}, Exception.class)).isNull();
// fails as CustomParseException is not a RuntimeException
catchThrowableOfType(() -> { throw new CustomParseException("boom!", 1, 5); },
RuntimeException.class);</code></pre>
<h4 class="page-header"><span id="assertj-core-3.9.0-optional-get" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Allow performing <span class="small-code">Object</span> assertion on the <span class="small-code">Optional</span> value after calling <span class="small-code">get()</span>.</h4>
<p>Verifies that the <span class="small-code">Optional</span> under test is not null and not empty, then returns an <span class="small-code">Object</span> assertion to allow chaining of (Object only) assertions on the optional value.</p>
<p>Note that it is only possible to return <span class="small-code">Object</span> assertions after calling this method due to java generics limitations.</p>
<p>Example:</p>
<pre><code class="java">TolkienCharacter frodo = new TolkienCharacter("Frodo", 33, HOBBIT);
// Use get() to navigate to perform assertions on frodo.
assertThat(Optional.of(frodo)).get().isEqualTo(frodo);
// fails since the API does not allow navigating to a null value.
assertThat(Optional.empty()).get();</code></pre>
<h4 class="page-header"><span id="assertj-core-3.9.0-describe-assertThatThrownBy" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Allow to set a description in <span class="small-code">assertThatThrownBy</span>.</h4>
<p>A variant of <span class="small-code">assertThatThrownBy</span> which accepts a description has been added.</p>
<p>Example:</p>
<pre><code class="java">// this assertion fails ...
assertThatThrownBy(() -> { throw new IOException("bam!"); }, "check explosion")
.isInstanceOf(IOException.class)
.hasMessageContaining("boom!");
// ... with the following error message:
java.lang.AssertionError: [check explosion]
Expecting message:
<"bam !">
but was:
<"boom !"></code></pre>
<h4 class="page-header"><span id="assertj-core-3.9.0-describe-assertThatExceptionOfType" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Allow to use a description after <span class="small-code">assertThatExceptionOfType</span> like assertions.</h4>
<p>Allow to set a description for assertions initialized with:
<ul>
<li><span class="small-code">assertThatExceptionOfType</span></li>
<li><span class="small-code">assertThatIllegalStateException</span></li>
<li><span class="small-code">assertThatNullPointerException</span></li>
<li><span class="small-code">assertThatIOException</span></li>
<li><span class="small-code">assertThatIllegalArgumentException</span></li>
</ul>
<p>Examples:</p>
<pre><code class="java">// assertions succeeds
assertThatExceptionOfType(RuntimeException.class)
.as("check explosion")
.isThrownBy(() -> {throw new RuntimeException("boom !");})
.withMessage("boom !");
assertThatNullPointerException()
.as("null check")
.isThrownBy(() -> {throw new NullPointerException("null !");})
.withMessage("null !");
// assertion fails ...
assertThatExceptionOfType(RuntimeException.class)
.as("check explosion")
.isThrownBy(() -> {throw new RuntimeException("boom !");})
.withMessage("bam !");
// ... with the error below (note the description):
java.lang.AssertionError: [check explosion]
Expecting message:
<"bam !">
but was:
<"boom !"></code></pre>
<!-- ================================================================================================================= -->
<h3 class="page-header"><span id="assertj-core-3.8.0"></span>AssertJ Core 3.8.0 release : New and noteworthy</h3>
<p>Release date : 2017-05-21</p>
<p>This release includes all changes from <a href="assertj-core-older-releases.html#assertj-core-2.8.0">AssertJ core 2.8.0</a> and adds the following that are Java 8 specific.</p>
<h4 class="page-header"> Release notes</h4>
<div class="release-section-category">New features :</div>
<ul>
<li>Add <a href="assertj-core-news.html#assertj-core-3.8.0-isBetween"><span class="small-code">isBetween</span></a> to all <span class="small-code">Temporal</span> assertions.</li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.8.0-isStrictlyBetween"><span class="small-code">isStrictlyBetween</span></a> to all <span class="small-code">Temporal</span> assertions.</li>
</ul>
<div class="release-section-category">Fixed :</div>
<ul>
<li>New <span class="small-code">Instant</span> assertions were missing the <span class="small-code">isBetween</span> assertion which was available in <span class="small-code">Comparable</span> assertions. </li>
<li>New <span class="small-code">Instant</span> assertions were missing the <span class="small-code">isStriclyBetween</span> assertion which was available in <span class="small-code">Comparable</span> assertions. </li>
</ul>
<h4 class="page-header"><span id="assertj-core-3.8.0-isBetween" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isBetween</span> to all <span class="small-code">Temporal</span> assertions</h4>
<p>Verifies that the actual <span class="small-code">Temporal</span> is in the [start, end] period (start and end included).</p>
<p><span class="small-code">Temporal</span> types supported include: <span class="small-code">Instant</span>, <span class="small-code">LocalDate</span>, <span class="small-code">LocalDateTime</span>, <span class="small-code">LocalTime</span>, <span class="small-code">OffsetTime</span>, <span class="small-code">OffsetDateTime</span> and <span class="small-code">ZonedDateTime</span>.</p>
<p>Examples with <span class="small-code">Instant</span> : </p>
<pre><code class="java">Instant instant = Instant.now();
// assertions succeed
assertThat(instant).isBetween(instant.minusSeconds(1), instant.plusSeconds(1))
.isBetween(instant, instant.plusSeconds(1))
.isBetween(instant.minusSeconds(1), instant)
.isBetween(instant, instant);</code></pre>
<h4 class="page-header"><span id="assertj-core-3.8.0-isStrictlyBetween" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isStrictlyBetween</span> to all <span class="small-code">Temporal</span> assertions</h4>
<p>Verifies that the actual <span class="small-code">Temporal</span> is in the ]start, end[ period (start and end excluded).</p>
<p><span class="small-code">Temporal</span> types supported include <span class="small-code">Instant</span>, <span class="small-code">LocalDate</span>, <span class="small-code">LocalDateTime</span>, <span class="small-code">LocalTime</span>, <span class="small-code">OffsetTime</span>, <span class="small-code">OffsetDateTime</span> and <span class="small-code">ZonedDateTime</span>.</p>
<p>Examples with <span class="small-code">Instant</span> : </p>
<pre><code class="java">Instant instant = Instant.now();
// assertion succeeds
assertThat(instant).isStrictlyBetween(instant.minusSeconds(1), instant.plusSeconds(1));
// assertions fail
assertThat(instant).isStrictlyBetween(instant.plusSeconds(1), instant.plusSeconds(10));
assertThat(instant).isStrictlyBetween(instant, instant.plusSeconds(1));
assertThat(instant).isStrictlyBetween(instant.minusSeconds(1), instant);</code></pre>
<h3 class="page-header"><span id="assertj-core-3.7.0"></span>AssertJ Core 3.7.0 release : New and noteworthy</h3>
<p>Release date : 2017-05-07</p>
<p>This release includes all changes from <a href="assertj-core-older-releases.html#assertj-core-2.7.0">AssertJ core 2.7.0</a> and adds the following that are Java 8 specific.</p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span>, <span class="contributor">Eirik Lygre</span>, <span class="contributor">epeee</span>, <span class="contributor">Kseniya Panasyuk</span>, <span class="contributor">Gaël Lhez</span>, <span class="contributor">Brice Dutheil</span>, <span class="contributor">Takuya "Mura-Mi" Murakami</span> and <span class="contributor">Maurício Aniche</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-news.html#assertj-core-3.7.0-instant"><span class="small-code">Instant</span></a> assertions. <span class="contributor">(epeee)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.7.0-isCloseTo"><span class="small-code">isCloseTo</span></a> to <span class="small-code">Temporal</span> types assertion. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add iterable/array <a href="assertj-core-news.html#assertj-core-3.7.0-anySatisfy"><span class="small-code">anySatisfy</span></a> assertion. <span class="contributor">(epeee)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.7.0-primitive-stream">primitive <span class="small-code">Stream</span></a> assertions. <span class="contributor">(Brice Dutheil)</span></li>
<li>Add <span class="small-code">assertThatExceptionOfType</span> <a href="assertj-core-news.html#assertj-core-3.7.0-assertThatExceptionOfType-shortcuts">shortcuts</a> for common exceptions. <span class="contributor">(Gaël Lhez)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.7.0-doesNotThrowAnyException"><span class="small-code">doesNotThrowAnyException</span></a> assertion. <span class="contributor">(Brice Dutheil)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.7.0-returns"><span class="small-code">returns</span></a> Object assertion. <span class="contributor">(Takuya "Mura-Mi" Murakami)</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">extracting</span> and <span class="small-code">flatExtracting</span> now accept <a href="assertj-core-news.html#assertj-core-3.7.0-throwingExtractor">extractor functions throwing checked exceptions</a>. <span class="contributor">(epeee)</span></li>
<li><span class="small-code">allMatch</span> assertion now prints all non matching elements if it fails. <span class="contributor">(Maurício Aniche)</span></li>
<li>Add <span class="small-code">@CheckReturnValue</span> for findbugs integration in <span class="small-code">WithAssertions</span>. <span class="contributor">(Pascal Schumacher)</span></li>
<li>Improve error message of <span class="small-code">containsInstanceOf</span> <span class="small-code">Optional</span> assertion. <span class="contributor">(Eirik Lygre)</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>
<h4 class="page-header"><span id="assertj-core-3.7.0-instant" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add Instant assertions</h4>
<p>Expose assertions for the <a href="https://docs.oracle.com/javase/8/docs/api/java/time/Instant.html"><span class="small-code">Instant</span></a> type from the new Date / Time API introduced in Java 8.</p>
<p>Examples: </p>
<pre><code class="java">import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.Assertions.byLessThan;
Instant firstOfJanuary2000 = Instant.parse("2000-01-01T00:00:00.00Z");
// if you pass a String, AssertJ parses it to an Instant
assertThat(firstOfJanuary2000).isEqualTo("2000-01-01T00:00:00.00Z")
.isAfter("1999-12-31T23:59:59.99Z")
.isAfter(firstOfJanuary2000.minusSeconds(1))
.isAfterOrEqualTo("2000-01-01T00:00:00.00Z")
.isBefore(firstOfJanuary2000.plusSeconds(1))
.isBefore("2000-01-01T00:00:00.01Z")
.isCloseTo("1999-12-31T23:59:59.99Z", within(10, ChronoUnit.MILLIS))
.isCloseTo("1999-12-31T23:59:59.99Z", byLessThan(11, ChronoUnit.MILLIS));</code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-isCloseTo" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add isCloseTo to Temporal types assertions</h4>
<p>Verifies that the actual <a href="https://docs.oracle.com/javase/8/docs/api/java/time/temporal/Temporal.html"><span class="small-code">Temporal</span></a> is close to the other according to the given <span class="small-code">TemporalOffset</span>. </p>
<p> You can build the offset parameter using:
<ul>
<li><span class="small-code">Assertions.within(long, TemporalUnit)</span></li>
<li><span class="small-code">Assertions.byLessThan(long, TemporalUnit)</span></li>
</ul>
</p>
<p>Examples: </p>
<pre><code class="java">import static org.assertj.core.api.Assertions.within;
import static org.assertj.core.api.Assertions.byLessThan;
LocalTime _07_10 = LocalTime.of(7, 10);
LocalTime _07_42 = LocalTime.of(7, 42);
// assertions will pass
assertThat(_07_10).isCloseTo(_07_42, within(1, ChronoUnit.HOURS));
assertThat(_07_10).isCloseTo(_07_42, within(32, ChronoUnit.MINUTES));
// assertions will fail (byLessThan does not allow equals)
assertThat(_07_10).isCloseTo(_07_42, byLessThan(32, ChronoUnit.MINUTES));
assertThat(_07_10).isCloseTo(_07_42, within(10, ChronoUnit.SECONDS));</code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-anySatisfy" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add anySatisfy to iterable/array assertions</h4>
<p>Verifies that at least one element satisfies the given requirements expressed as a <span class="small-code">Consumer</span>. </p>
<p>If the iterable/array to assert is empty, the assertion will fail.</p>
<p>Example: </p>
<pre><code class="java">// assume that one of myIcelanderFriends has a name ending with 'son' (highly probable indeed)
assertThat(myIcelanderFriends).anySatisfy(person -> {
assertThat(person.getCountry()).isEqualTo("Iceland");
assertThat(person.getName()).endsWith("son");
});</code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-primitive-stream" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add primitive Stream assertions</h4>
<p>Extend <span class="small-code">Stream</span> assertions to primitive streams: <span class="small-code">IntStream</span> , <span class="small-code">LongStream</span> and <span class="small-code">DoubleStream</span>.</p>
<p>Examples: </p>
<pre><code class="java">// IntStream example:
assertThat(IntStream.of(1, 2, 3)).contains(3)
.anySatisfy(i -> assertThat(i).isLessThan(2));
// LongStream example:
assertThat(LongStream.of(0, 1, 2, 3, 4)).hasSize(5)
.containsSequence(1L, 2L, 3L);
// DoubleStream example:
assertThat(DoubleStream.of(1, 2, 3)).hasSize(3)
.contains(1.0, 2.0, 3.0)
.allMatch(Double::isFinite);</code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-doesNotThrowAnyException" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add doesNotThrowAnyException assertion</h4>
<p>Verify that a code block <b>does not</b> raise an exception. This allows finer control over statement(s) that should or should not raise an exception.</p>
<p>Example: </p>
<pre><code class="java">assertThatCode(() -> {}).doesNotThrowAnyException();</code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-assertThatExceptionOfType-shortcuts" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add assertThatExceptionOfType shortcuts for common exceptions</h4>
<p>Provide the following <span class="small-code">assertThatExceptionOfType</span> shortchuts:</p>
<ul>
<li><span class="small-code">assertThatNullPointerException</span></li>
<li><span class="small-code">assertThatIllegalArgumentException</span></li>
<li><span class="small-code">assertThatIllegalStateException</span></li>
<li><span class="small-code">assertThatIOException</span></li>
</ul>
<p>Example: </p>
<pre><code class="java">// instead of ...
assertThatExceptionOfType(IOException.class).isThrownBy(() -> { throw new IOException("boom!"); })
.withMessage("boom!")
.withMessageContaining("oom")
.withMessage("%s!", "boom")
.withStackTraceContaining("IOException")
.withNoCause();
// ... you can simply write:
assertThatIOException().isThrownBy(() -> { throw new IOException("boom!"); })
.withMessage("boom!")
... </code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-returns" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add returns Object assertion</h4>
<p>Verify that the object under test returns the given expected value from the given method expressed as a <a href="http://docs.oracle.com/javase/8/docs/api/java/util/function/Function.html"><span class="small-code">Function</span></a>. A typical usage is to pass a method reference to assert an object's property.</p>
<p>Wrapping the given <span class="small-code">Function</span> with <span class="small-code">Assertions.from</span> makes the assertion more readable.</p>
<p>Examples: </p>
<pre><code class="java">import static org.assertj.core.api.Assertions.from;
// from is not mandatory but it makes the assertions more readable
assertThat(frodo).returns("Frodo", from(TolkienCharacter::getName))
.returns("Frodo", TolkienCharacter::getName) // no from :(
.returns(HOBBIT, from(TolkienCharacter::getRace));</code></pre>
<h4 class="page-header"><span id="assertj-core-3.7.0-throwingExtractor" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> extracting / flatExtracting now accept an extractor function throwing checked exceptions</h4>
<p><span class="small-code">Extracting</span> and <span class="small-code">flatExtracting</span> can be passed extractor functions <b>that throw checked exceptions</b>.</p>
<p>Any checked exception raised in the extractor is rethrown wrapped in a <span class="small-code">RuntimeException</span>.</p>
<p>Examples: </p>
<pre><code class="java">// Instead of using an Extractor, we use a ThrowingExtractor
ThrowingExtractor<TolkienCharacter, Race, Exception> nonHobbitRace = tolkienCharacter -> {
if (tolkienCharacter.getRace() == HOBBIT) {
throw new Exception("Filthy little hobbites. They stole it from us. Myyy PRECIOUSSS !");
}
return tolkienCharacter.getRace();
};
// assertion succeeds
assertThat(newArrayList(elrond, aragorn)).extracting(nonHobbitRace)
.containsOnly(ELF, MAN)
.doesNotContain(HOBBIT);
// Error ! a RuntimeException wrapping the Exception raised from nonHobbitRace extractor is thrown
assertThat(fellowshipOfTheRing).extracting(nonHobbitRace)
.contains(HOBBIT, ELF)
.doesNotContain(ORC);
// flat extracting example
ThrowingExtractor<TolkienCharacter, Collection<String>, Exception> nameAndRaceExtractor =
tolkienCharacter -> {
if (tolkienCharacter == null) {
throw new Exception("can't accept null TolkienCharacter");
}
return asList(tolkienCharacter.getName(), tolkienCharacter.getRace().getName());
};
assertThat(fellowshipOfTheRing).flatExtracting(nameAndRaceExtractor)
.contains("Hobbit", "Frodo", "Elf", "Legolas");</code></pre>
<h3 class="page-header"><span id="assertj-core-3.6.2"></span>AssertJ Core 3.6.2 bugfix release</h3>
<p>Release date : 2017-01-21</p>
<div class="release-section-category">Fixed Bug :</div>
<ul>
<li>Fix <span class="small-code">extracting</span> properties from default getter method.</li>
</ul>
<h3 class="page-header"><span id="assertj-core-3.6.1"></span>AssertJ Core 3.6.1 bugfix release</h3>
<p>Release date : 2016-11-27</p>
<div class="release-section-category">Fixed Bug :</div>
<ul>
<li>Fix <span class="small-code">filteredOn(Predicate)</span> that was only working with <span class="small-code">List</span>.</li>
</ul>
<h3 class="page-header"><span id="assertj-core-3.6.0"></span>AssertJ Core 3.6.0 for Java 8 release : New and noteworthy</h3>
<p>Release date : 2016-11-21</p>
<p>This release includes all changes from <a href="#assertj-core-2.6.0">AssertJ core 2.6.0</a> and adds the following that are Java 8 specific.</p>
<p>Thanks to <span class="contributor">Pascal Schumacher</span>, <span class="contributor">Mike Kobit</span>, <span class="contributor">Clément Mathieu</span>, <span class="contributor">Kseniya Panasyuk</span>, <span class="contributor">Gaël Lhez</span>, <span class="contributor">Valeriy Vyrva</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-news.html#assertj-core-3.6.0-allSatisfy"><span class="small-code">allSatisfy</span> iterable/array assertion</a>. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.6.0-isInstanceOfSatisfying"><span class="small-code">isInstanceOfSatisfying</span></a> assertion.</li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.6.0-map-flatmap"><span class="small-code">map</span> and <span class="small-code">flatMap</span></a> to ease using optional assertions. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.6.0-hasEntrySatisfying"><span class="small-code">hasEntrySatisfying</span></a> map assertion. <span class="contributor">(Valeriy Vyrva)</span></li>
<li>Add <a href="assertj-core-news.html#assertj-core-3.6.0-hasValueSatisfying"><span class="small-code">hasValueSatisfying</span></a> optional assertion. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li>Add static <a href="assertj-core-news.html#assertj-core-3.6.0-assertSoftly"><span class="small-code">assertSoftly</span></a> method for soft assertions. <span class="contributor">(Jilles Van Gurp)</span></li>
</ul>
<div class="release-section-category">Improvements :</div>
<ul>
<li>Parameterize <span class="small-code">registerFormatterForType</span> with type. <span class="contributor">(Kseniya Panasyuk)</span></li>
<li><span class="small-code">Predicate</span> assertions error message improvements. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Allow to pass a <a href="assertj-core-news.html#assertj-core-3.6.0-predicate-description"><span class="small-code">Predicate</span> description</a> to <span class="small-code">allMatch</span> iterable/array assertion. <span class="contributor">(Filip Hrisafov)</span></li>
<li>Varargs warning removal. <span class="contributor">(Gaël Lhez)</span></li>
<li>Add missing <span class="small-code">assertThat</span> in <span class="small-code">WithAssertions</span>. <span class="contributor">(Clément Mathieu)</span></li>
<li>A bunch of code cleanup and javadoc improvements. <span class="contributor">(Pascal Schumacher, Mike Kobit)</span></li>
</ul>
<div class="release-section-category">Fixed Bugs :</div>
<ul>
<li>Fix stack overflow for completable future <span class="small-code">toStringOf</span> joining on another future that cycles back to the first. <span class="contributor">(Kseniya Panasyuk)</span></li>
</ul>
<h4 class="page-header"><span id="assertj-core-3.6.0-isInstanceOfSatisfying" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">isInstanceOfSatisfying</span> assertion</h4>
<p>Verifies that the actual value is an instance of the given type satisfying the given requirements expressed as a <a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html">Consumer</a>.</p>
<p>This is typically used when one knows the real type of the object under test and wants to perform strongly typed assertions without having to do an explicit cast.</p>
<p>Example : </p>
<pre><code class="java">// Build Jedi but declare them as Object (second 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);</code></pre>
<h4 class="page-header"><span id="assertj-core-3.6.0-allSatisfy" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">allSatisfy</span> iterable/array assertion</h4>
<p>Verifies that all elements satisfy the given requirements expressed as a <a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html">Consumer</a>. This is typically used to perform a group of assertions on every element of the iterable/array under test.</p>
<p>Example : </p>
<pre><code class="java">assertThat(myIcelanderFriends).allSatisfy(person -> {
assertThat(person.getCountry()).isEqualTo("Iceland");
assertThat(person.getPhoneCountryCode()).isEqualTo("+354");
});</code></pre>
<h4 class="page-header"><span id="assertj-core-3.6.0-map-flatmap" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">map</span> and <span class="small-code">flatMap</span> to ease using optional assertions</h4>
<p>Call <span class="small-code">map</span>/<span class="small-code">flatMap</span> on the <span class="small-code">Optional</span> under test, assertions chained afterwards are performed on the Optional resulting from the <span class="small-code">map</span>/<span class="small-code">flatMap</span> call.</p>
<p>Example : </p>
<pre><code class="java">// map example
assertThat(Optional.of("42")).contains("42")
.map(String::length)
.contains(2);
// flatMap examples
Function<String, Optional<String>> UPPER_CASE_OPTIONAL_STRING
= s -> s == null ? Optional.empty() : Optional.of(s.toUpperCase());
assertThat(Optional.of("something")).contains("something")
.flatMap(UPPER_CASE_OPTIONAL_STRING)
.contains("SOMETHING");
assertThat(Optional.<String> empty()).flatMap(UPPER_CASE_OPTIONAL_STRING)
.isEmpty();
assertThat(Optional.<String> ofNullable(null)).flatMap(UPPER_CASE_OPTIONAL_STRING)
.isEmpty();</code></pre>
<h4 class="page-header"><span id="assertj-core-3.6.0-hasEntrySatisfying" class="adjustAnchor"></span><i class="fa fa-arrow-circle-right"></i> Add <span class="small-code">hasEntrySatisfying(K, Consumer<? super V>)</span> map assertion</h4>
<p>Verifies that the actual <span class="small-code">Map</span> contains the given key and that its value satisfies the given requirements expressed as a <a href="https://docs.oracle.com/javase/8/docs/api/java/util/function/Consumer.html">Consumer</a>.</p>
<p>Example:</p>