28
28
import static java .nio .charset .StandardCharsets .UTF_8 ;
29
29
import static org .hamcrest .CoreMatchers .is ;
30
30
import static org .hamcrest .MatcherAssert .assertThat ;
31
+ import static org .junit .jupiter .api .Assertions .assertThrows ;
31
32
32
33
import java .io .ByteArrayOutputStream ;
33
34
import java .io .File ;
34
35
import java .io .IOException ;
35
36
import java .io .InputStream ;
36
37
37
38
import org .dom4j .DocumentException ;
38
- import org .junit .Rule ;
39
- import org .junit .Test ;
40
- import org .junit .rules .TemporaryFolder ;
39
+ import org .junit .jupiter .api .Test ;
40
+ import org .junit .jupiter .api .io .TempDir ;
41
41
42
42
/** Tests {@link FormatUtil}. */
43
- public final class FormatUtilTest {
43
+ class FormatUtilTest {
44
44
45
45
private static final String FORMATTED_XML = "<xml><hello/></xml>" ;
46
46
private static final String UNFORMATTED_XML = "<xml> <hello/> </xml>" ;
47
47
48
- @ Rule public TemporaryFolder tmp = new TemporaryFolder ();
48
+ @ TempDir
49
+ private File tmp ;
49
50
50
51
@ Test
51
- public void formattedWillNotChange () throws DocumentException , IOException {
52
+ void formattedWillNotChange () throws DocumentException , IOException {
52
53
inPlaceChange (FORMATTED_XML , false );
53
54
}
54
55
55
56
@ Test
56
- public void test1 () throws DocumentException , IOException {
57
+ void test1 () throws DocumentException , IOException {
57
58
final XmlOutputFormat fmt = new XmlOutputFormat ();
58
59
fmt .setIndentSize (4 );
59
60
fmt .setNewLineAfterDeclaration (false );
@@ -62,7 +63,7 @@ public void test1() throws DocumentException, IOException {
62
63
}
63
64
64
65
@ Test
65
- public void test1KeepBlankLines () throws DocumentException , IOException {
66
+ void test1KeepBlankLines () throws DocumentException , IOException {
66
67
final XmlOutputFormat fmt = new XmlOutputFormat ();
67
68
fmt .setIndentSize (4 );
68
69
fmt .setNewLineAfterDeclaration (false );
@@ -72,7 +73,7 @@ public void test1KeepBlankLines() throws DocumentException, IOException {
72
73
}
73
74
74
75
@ Test
75
- public void test2 () throws DocumentException , IOException {
76
+ void test2 () throws DocumentException , IOException {
76
77
final XmlOutputFormat fmt = new XmlOutputFormat ();
77
78
fmt .setIndentSize (2 );
78
79
fmt .setNewLineAfterDeclaration (false );
@@ -81,7 +82,7 @@ public void test2() throws DocumentException, IOException {
81
82
}
82
83
83
84
@ Test
84
- public void test2KeepBlankLines () throws DocumentException , IOException {
85
+ void test2KeepBlankLines () throws DocumentException , IOException {
85
86
final XmlOutputFormat fmt = new XmlOutputFormat ();
86
87
fmt .setIndentSize (2 );
87
88
fmt .setNewLineAfterDeclaration (false );
@@ -91,7 +92,7 @@ public void test2KeepBlankLines() throws DocumentException, IOException {
91
92
}
92
93
93
94
@ Test
94
- public void test3 () throws DocumentException , IOException {
95
+ void test3 () throws DocumentException , IOException {
95
96
final XmlOutputFormat fmt = new XmlOutputFormat ();
96
97
fmt .setIndentSize (2 );
97
98
fmt .setNewLineAfterDeclaration (false );
@@ -100,7 +101,7 @@ public void test3() throws DocumentException, IOException {
100
101
}
101
102
102
103
@ Test
103
- public void test4 () throws DocumentException , IOException {
104
+ void test4 () throws DocumentException , IOException {
104
105
final XmlOutputFormat fmt = new XmlOutputFormat ();
105
106
fmt .setIndent ("\t " );
106
107
fmt .setNewLineAfterDeclaration (false );
@@ -109,7 +110,7 @@ public void test4() throws DocumentException, IOException {
109
110
}
110
111
111
112
@ Test
112
- public void test4KeepBlankLines () throws DocumentException , IOException {
113
+ void test4KeepBlankLines () throws DocumentException , IOException {
113
114
final XmlOutputFormat fmt = new XmlOutputFormat ();
114
115
fmt .setIndent ("\t " );
115
116
fmt .setNewLineAfterDeclaration (false );
@@ -119,7 +120,7 @@ public void test4KeepBlankLines() throws DocumentException, IOException {
119
120
}
120
121
121
122
@ Test
122
- public void test5 () throws DocumentException , IOException {
123
+ void test5 () throws DocumentException , IOException {
123
124
final XmlOutputFormat fmt = new XmlOutputFormat ();
124
125
fmt .setIndent (" " );
125
126
fmt .setNewLineAfterDeclaration (false );
@@ -133,7 +134,7 @@ public void test5() throws DocumentException, IOException {
133
134
* seems, they don't reach the XMLWriter. Not ideal, but believe we can leave with this exception
134
135
*/
135
136
@ Test
136
- public void test5KeepBlankLines () throws DocumentException , IOException {
137
+ void test5KeepBlankLines () throws DocumentException , IOException {
137
138
final XmlOutputFormat fmt = new XmlOutputFormat ();
138
139
fmt .setIndent (" " );
139
140
// Set to true to keep the new line given keep blank lines will not
@@ -149,7 +150,7 @@ public void test5KeepBlankLines() throws DocumentException, IOException {
149
150
* seems, they don't reach the XMLWriter. Not ideal, but believe we can leave with this exception
150
151
*/
151
152
@ Test
152
- public void test6 () throws DocumentException , IOException {
153
+ void test6 () throws DocumentException , IOException {
153
154
final XmlOutputFormat fmt = new XmlOutputFormat ();
154
155
fmt .setIndent (" " );
155
156
// Set to true to keep the new line given keep blank lines will not
@@ -160,22 +161,24 @@ public void test6() throws DocumentException, IOException {
160
161
testInOut (6 , fmt );
161
162
}
162
163
163
- @ Test (expected = DocumentException .class )
164
- public void testInvalid () throws DocumentException , IOException {
165
- try (InputStream in = getResource ("/invalid.xml" )) {
166
- final ByteArrayOutputStream out = new ByteArrayOutputStream ();
167
- format (in , out , new XmlOutputFormat ());
168
- }
164
+ @ Test
165
+ void testInvalid () throws DocumentException , IOException {
166
+ assertThrows (DocumentException .class , () -> {
167
+ try (InputStream in = getResource ("/invalid.xml" )) {
168
+ final ByteArrayOutputStream out = new ByteArrayOutputStream ();
169
+ format (in , out , new XmlOutputFormat ());
170
+ }
171
+ });
169
172
}
170
173
171
174
@ Test
172
- public void unformattedWillChange () throws DocumentException , IOException {
175
+ void unformattedWillChange () throws DocumentException , IOException {
173
176
inPlaceChange (UNFORMATTED_XML , true );
174
177
}
175
178
176
179
private void inPlaceChange (final String txt , final boolean shouldChange )
177
180
throws DocumentException , IOException {
178
- final File file = tmp . newFile ( );
181
+ final File file = File . createTempFile ( "junit" , null , tmp );
179
182
stringToFile (txt , file );
180
183
181
184
final XmlOutputFormat fmt = new XmlOutputFormat ();
0 commit comments