15
15
*/
16
16
package org .springframework .batch .test ;
17
17
18
- import static org .junit .jupiter .api .Assertions .assertDoesNotThrow ;
19
- import static org .junit .jupiter .api .Assertions .assertThrows ;
20
- import static org .junit .jupiter .api .Assertions .assertTrue ;
21
-
22
18
import org .junit .ComparisonFailure ;
23
19
import org .junit .jupiter .api .Test ;
24
20
import org .springframework .core .io .FileSystemResource ;
25
21
22
+ import static org .junit .jupiter .api .Assertions .*;
23
+
26
24
/**
27
25
* This class can be used to assert that two files are the same.
28
26
*
29
27
* @author Dan Garrette
28
+ * @author Glenn Renfro
30
29
* @since 2.0
31
30
*/
32
31
class AssertFileTests {
@@ -39,21 +38,36 @@ void testAssertEquals_equal() {
39
38
}
40
39
41
40
@ Test
42
- void testAssertEquals_notEqual () {
43
- Error error = assertThrows (ComparisonFailure .class , () -> executeAssertEquals ("input1.txt" , "input2.txt" ));
44
- assertTrue (error .getMessage ().startsWith ("Line number 3 does not match." ));
41
+ public void testAssertEquals_notEqual () throws Exception {
42
+ try {
43
+ executeAssertEquals ("input1.txt" , "input2.txt" );
44
+ fail ();
45
+ }
46
+ catch (IllegalStateException e ) {
47
+ assertTrue (e .getMessage ().startsWith ("Line number 3 does not match." ));
48
+ }
45
49
}
46
50
47
51
@ Test
48
- void testAssertEquals_tooLong () {
49
- Error error = assertThrows (AssertionError .class , () -> executeAssertEquals ("input3.txt" , "input1.txt" ));
50
- assertTrue (error .getMessage ().startsWith ("More lines than expected. There should not be a line number 4." ));
52
+ public void testAssertEquals_tooLong () throws Exception {
53
+ try {
54
+ executeAssertEquals ("input3.txt" , "input1.txt" );
55
+ fail ();
56
+ }
57
+ catch (IllegalStateException e ) {
58
+ assertTrue (e .getMessage ().startsWith ("More lines than expected. There should not be a line number 4." ));
59
+ }
51
60
}
52
61
53
62
@ Test
54
- void testAssertEquals_tooShort () {
55
- Error error = assertThrows (AssertionError .class , () -> executeAssertEquals ("input1.txt" , "input3.txt" ));
56
- assertTrue (error .getMessage ().startsWith ("Line number 4 does not match." ));
63
+ public void testAssertEquals_tooShort () throws Exception {
64
+ try {
65
+ executeAssertEquals ("input1.txt" , "input3.txt" );
66
+ fail ();
67
+ }
68
+ catch (IllegalStateException e ) {
69
+ assertTrue (e .getMessage ().startsWith ("Line number 4 does not match." ));
70
+ }
57
71
}
58
72
59
73
@ Test
@@ -62,15 +76,25 @@ void testAssertEquals_blank_equal() {
62
76
}
63
77
64
78
@ Test
65
- void testAssertEquals_blank_tooLong () {
66
- Error error = assertThrows (AssertionError .class , () -> executeAssertEquals ("blank.txt" , "input1.txt" ));
67
- assertTrue (error .getMessage ().startsWith ("More lines than expected. There should not be a line number 1." ));
79
+ public void testAssertEquals_blank_tooLong () throws Exception {
80
+ try {
81
+ executeAssertEquals ("blank.txt" , "input1.txt" );
82
+ fail ();
83
+ }
84
+ catch (IllegalStateException e ) {
85
+ assertTrue (e .getMessage ().startsWith ("More lines than expected. There should not be a line number 1." ));
86
+ }
68
87
}
69
88
70
89
@ Test
71
- void testAssertEquals_blank_tooShort () {
72
- Error error = assertThrows (AssertionError .class , () -> executeAssertEquals ("input1.txt" , "blank.txt" ));
73
- assertTrue (error .getMessage ().startsWith ("Line number 1 does not match." ));
90
+ public void testAssertEquals_blank_tooShort () throws Exception {
91
+ try {
92
+ executeAssertEquals ("input1.txt" , "blank.txt" );
93
+ fail ();
94
+ }
95
+ catch (IllegalStateException e ) {
96
+ assertTrue (e .getMessage ().startsWith ("Line number 1 does not match." ));
97
+ }
74
98
}
75
99
76
100
private void executeAssertEquals (String expected , String actual ) throws Exception {
0 commit comments