@@ -922,6 +922,29 @@ public void comparingValuesUsing_containsEntry_diffExpectedKeyHasWrongValue() {
922
922
+ "within 10 of <60>. However, it has a mapping from that key to <71> (diff: 11)" );
923
923
}
924
924
925
+ @ Test
926
+ public void comparingValuesUsing_containsEntry_handlesFormatDiffExceptions () {
927
+ Map <String , Integer > actual = new LinkedHashMap <>();
928
+ actual .put ("abc" , 35 );
929
+ actual .put ("def" , null );
930
+ expectFailureWhenTestingThat (actual )
931
+ .comparingValuesUsing (WITHIN_10_OF )
932
+ .containsEntry ("def" , 60 );
933
+ assertFailureKeys (
934
+ "Not true that <{abc=35, def=null}> contains an entry with key <def> and a value that is "
935
+ + "within 10 of <60>. However, it has a mapping from that key to <null>" ,
936
+ "additionally, one or more exceptions were thrown while comparing values" ,
937
+ "first exception" ,
938
+ "additionally, one or more exceptions were thrown while formatting diffs" ,
939
+ "first exception" );
940
+ assertThatFailure ()
941
+ .factValue ("first exception" , 0 )
942
+ .startsWith ("compare(null, 60) threw java.lang.NullPointerException" );
943
+ assertThatFailure ()
944
+ .factValue ("first exception" , 1 )
945
+ .startsWith ("formatDiff(null, 60) threw java.lang.NullPointerException" );
946
+ }
947
+
925
948
@ Test
926
949
public void comparingValuesUsing_containsEntry_handlesExceptions_expectedKeyHasWrongValue () {
927
950
Map <Integer , String > actual = new LinkedHashMap <>();
@@ -1274,6 +1297,33 @@ public void comparingValuesUsing_containsExactlyEntriesIn_diffMissingAndExtraAnd
1274
1297
+ "{ghi=(expected 90 but got 101, diff: 11)}" );
1275
1298
}
1276
1299
1300
+ @ Test
1301
+ public void comparingValuesUsing_containsExactlyEntriesIn_handlesFormatDiffExceptions () {
1302
+ ImmutableMap <String , Integer > expected = ImmutableMap .of ("abc" , 30 , "def" , 60 , "ghi" , 90 );
1303
+ Map <String , Integer > actual = new LinkedHashMap <>();
1304
+ actual .put ("abc" , 35 );
1305
+ actual .put ("def" , null );
1306
+ actual .put ("ghi" , 95 );
1307
+ expectFailureWhenTestingThat (actual )
1308
+ .comparingValuesUsing (WITHIN_10_OF )
1309
+ .containsExactlyEntriesIn (expected );
1310
+ assertFailureKeys (
1311
+ "Not true that <{abc=35, def=null, ghi=95}> contains exactly one entry that has a key that "
1312
+ + "is equal to and a value that is within 10 of the key and value of each entry of "
1313
+ + "<{abc=30, def=60, ghi=90}>. It has the following entries with matching keys but "
1314
+ + "different values: {def=(expected 60 but got null)}" ,
1315
+ "additionally, one or more exceptions were thrown while comparing values" ,
1316
+ "first exception" ,
1317
+ "additionally, one or more exceptions were thrown while formatting diffs" ,
1318
+ "first exception" );
1319
+ assertThatFailure ()
1320
+ .factValue ("first exception" , 0 )
1321
+ .startsWith ("compare(null, 60) threw java.lang.NullPointerException" );
1322
+ assertThatFailure ()
1323
+ .factValue ("first exception" , 1 )
1324
+ .startsWith ("formatDiff(null, 60) threw java.lang.NullPointerException" );
1325
+ }
1326
+
1277
1327
@ Test
1278
1328
public void comparingValuesUsing_containsExactlyEntriesIn_inOrder_failsOutOfOrder () {
1279
1329
ImmutableMap <String , Integer > expected = ImmutableMap .of ("def" , 456 , "abc" , 123 );
0 commit comments