15
15
*/
16
16
package com .google .common .truth ;
17
17
18
+ import static com .google .common .truth .ExpectFailure .expectFailure ;
18
19
import static com .google .common .truth .Truth .assertThat ;
19
20
import static java .math .BigDecimal .TEN ;
20
21
@@ -47,28 +48,32 @@ public void isEquivalentAccordingToCompareTo() {
47
48
public void isEqualToIgnoringScale_bigDecimal () {
48
49
assertThat (TEN ).isEqualToIgnoringScale (TEN );
49
50
assertThat (TEN ).isEqualToIgnoringScale (new BigDecimal (10 ));
50
- expectFailureWhenTestingThat (TEN ).isEqualToIgnoringScale (new BigDecimal (3 ));
51
- assertFailureKeys ("expected" , "but was" , "(scale is ignored)" );
52
- assertFailureValue ("expected" , "3" );
53
- assertFailureValue ("but was" , "10" );
51
+ AssertionError e =
52
+ expectFailure (
53
+ whenTesting -> whenTesting .that (TEN ).isEqualToIgnoringScale (new BigDecimal (3 )));
54
+ assertFailureKeys (e , "expected" , "but was" , "(scale is ignored)" );
55
+ assertFailureValue (e , "expected" , "3" );
56
+ assertFailureValue (e , "but was" , "10" );
54
57
}
55
58
56
59
@ Test
57
60
public void isEqualToIgnoringScale_int () {
58
61
assertThat (TEN ).isEqualToIgnoringScale (10 );
59
- expectFailureWhenTestingThat (TEN ).isEqualToIgnoringScale (3 );
60
- assertFailureKeys ("expected" , "but was" , "(scale is ignored)" );
61
- assertFailureValue ("expected" , "3" );
62
- assertFailureValue ("but was" , "10" );
62
+ AssertionError e =
63
+ expectFailure (whenTesting -> whenTesting .that (TEN ).isEqualToIgnoringScale (3 ));
64
+ assertFailureKeys (e , "expected" , "but was" , "(scale is ignored)" );
65
+ assertFailureValue (e , "expected" , "3" );
66
+ assertFailureValue (e , "but was" , "10" );
63
67
}
64
68
65
69
@ Test
66
70
public void isEqualToIgnoringScale_long () {
67
71
assertThat (TEN ).isEqualToIgnoringScale (10L );
68
- expectFailureWhenTestingThat (TEN ).isEqualToIgnoringScale (3L );
69
- assertFailureKeys ("expected" , "but was" , "(scale is ignored)" );
70
- assertFailureValue ("expected" , "3" );
71
- assertFailureValue ("but was" , "10" );
72
+ AssertionError e =
73
+ expectFailure (whenTesting -> whenTesting .that (TEN ).isEqualToIgnoringScale (3L ));
74
+ assertFailureKeys (e , "expected" , "but was" , "(scale is ignored)" );
75
+ assertFailureValue (e , "expected" , "3" );
76
+ assertFailureValue (e , "but was" , "10" );
72
77
}
73
78
74
79
@ Test
@@ -77,10 +82,11 @@ public void isEqualToIgnoringScale_string() {
77
82
assertThat (TEN ).isEqualToIgnoringScale ("10." );
78
83
assertThat (TEN ).isEqualToIgnoringScale ("10.0" );
79
84
assertThat (TEN ).isEqualToIgnoringScale ("10.00" );
80
- expectFailureWhenTestingThat (TEN ).isEqualToIgnoringScale ("3" );
81
- assertFailureKeys ("expected" , "but was" , "(scale is ignored)" );
82
- assertFailureValue ("expected" , "3" );
83
- assertFailureValue ("but was" , "10" );
85
+ AssertionError e =
86
+ expectFailure (whenTesting -> whenTesting .that (TEN ).isEqualToIgnoringScale ("3" ));
87
+ assertFailureKeys (e , "expected" , "but was" , "(scale is ignored)" );
88
+ assertFailureValue (e , "expected" , "3" );
89
+ assertFailureValue (e , "but was" , "10" );
84
90
}
85
91
86
92
@ Test
@@ -90,13 +96,10 @@ public void isEqualToIgnoringScale_stringWithDecimals() {
90
96
assertThat (tenFour ).isEqualToIgnoringScale ("10.4" );
91
97
assertThat (tenFour ).isEqualToIgnoringScale ("10.40" );
92
98
assertThat (tenFour ).isEqualToIgnoringScale ("10.400" );
93
- expectFailureWhenTestingThat (tenFour ).isEqualToIgnoringScale ("3.4" );
94
- assertFailureKeys ("expected" , "but was" , "(scale is ignored)" );
95
- assertFailureValue ("expected" , "3.4" );
96
- assertFailureValue ("but was" , "10.4" );
97
- }
98
-
99
- private BigDecimalSubject expectFailureWhenTestingThat (BigDecimal actual ) {
100
- return expectFailure .whenTesting ().that (actual );
99
+ AssertionError e =
100
+ expectFailure (whenTesting -> whenTesting .that (tenFour ).isEqualToIgnoringScale ("3.4" ));
101
+ assertFailureKeys (e , "expected" , "but was" , "(scale is ignored)" );
102
+ assertFailureValue (e , "expected" , "3.4" );
103
+ assertFailureValue (e , "but was" , "10.4" );
101
104
}
102
105
}
0 commit comments