Skip to content

Commit 84a0ac6

Browse files
committed
Refactor test setup
1 parent ab04dd1 commit 84a0ac6

1 file changed

Lines changed: 12 additions & 8 deletions

File tree

src/test/java/org/apache/commons/cli/example/XhtmlHelpAppendableTest.java

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -29,16 +29,25 @@ Licensed to the Apache Software Foundation (ASF) under one or more
2929
import org.apache.commons.cli.help.TableDefinition;
3030
import org.apache.commons.cli.help.TextStyle;
3131
import org.apache.commons.io.IOUtils;
32+
import org.junit.jupiter.api.BeforeEach;
3233
import org.junit.jupiter.api.Test;
3334

35+
/**
36+
* Tests {@link XhtmlHelpAppendable}.
37+
*/
3438
public class XhtmlHelpAppendableTest {
3539

36-
private final StringBuilder sb = new StringBuilder();
37-
private final XhtmlHelpAppendable underTest = new XhtmlHelpAppendable(sb);
40+
private StringBuilder sb;
41+
private XhtmlHelpAppendable underTest;
42+
43+
@BeforeEach
44+
public void beforeEach() {
45+
sb = new StringBuilder();
46+
underTest = new XhtmlHelpAppendable(sb);
47+
}
3848

3949
@Test
4050
public void testAppendHeaderTest() throws IOException {
41-
sb.setLength(0);
4251
underTest.appendHeader(1, "Hello World");
4352
assertEquals(String.format("<h1>Hello World</h1>%n"), sb.toString());
4453
sb.setLength(0);
@@ -51,7 +60,6 @@ public void testAppendHeaderTest() throws IOException {
5160
@Test
5261
public void testAppendListTest() throws IOException {
5362
final String[] entries = { "one", "two", "three" };
54-
sb.setLength(0);
5563
underTest.appendList(true, Arrays.asList(entries));
5664
assertEquals(String.format("<ol>%n <li>one</li>%n <li>two</li>%n <li>three</li>%n</ol>%n"), sb.toString());
5765
sb.setLength(0);
@@ -61,14 +69,12 @@ public void testAppendListTest() throws IOException {
6169

6270
@Test
6371
public void testAppendParagraphFormatTest() throws IOException {
64-
sb.setLength(0);
6572
underTest.appendParagraphFormat("Hello %s World %,d", "Joe", 309);
6673
assertEquals(String.format("<p>Hello Joe World 309</p>%n"), sb.toString());
6774
}
6875

6976
@Test
7077
public void testAppendParagraphTest() throws IOException {
71-
sb.setLength(0);
7278
underTest.appendParagraph("Hello World");
7379
assertEquals(String.format("<p>Hello World</p>%n"), sb.toString());
7480
}
@@ -109,7 +115,6 @@ public void testAppendTableTest() throws IOException {
109115
expected.add(" </tr>");
110116
expected.add("</table>");
111117
TableDefinition table = TableDefinition.from("The caption", styles, Arrays.asList(headers), rows);
112-
sb.setLength(0);
113118
underTest.appendTable(table);
114119
List<String> actual = IOUtils.readLines(new StringReader(sb.toString()));
115120
assertEquals(expected, actual, "full table failed");
@@ -136,7 +141,6 @@ public void testAppendTableTest() throws IOException {
136141

137142
@Test
138143
public void testAppendTitleTest() throws IOException {
139-
sb.setLength(0);
140144
underTest.appendTitle("Hello World");
141145
assertEquals(String.format("<span class='commons_cli_title'>Hello World</span>%n"), sb.toString());
142146
}

0 commit comments

Comments
 (0)