1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17 package org.apache.commons.io.output;
18
19 import static org.junit.jupiter.api.Assertions.assertEquals;
20
21 import org.junit.jupiter.api.BeforeEach;
22 import org.junit.jupiter.api.Test;
23
24
25
26
27 public class AppendableWriterTest {
28
29 private AppendableWriter<StringBuilder> out;
30
31 @BeforeEach
32 public void setUp() {
33 out = new AppendableWriter<>(new StringBuilder());
34 }
35
36 @SuppressWarnings("resource")
37 @Test
38 public void testAppendChar() throws Exception {
39 out.append('F');
40
41 assertEquals("F", out.getAppendable().toString());
42 }
43
44 @SuppressWarnings("resource")
45 @Test
46 public void testAppendCharSequence() throws Exception {
47 final String testData = "ABCD";
48
49 out.append(testData);
50 out.append(null);
51
52 assertEquals(testData + "null", out.getAppendable().toString());
53 }
54
55 @SuppressWarnings("resource")
56 @Test
57 public void testAppendSubSequence() throws Exception {
58 final String testData = "ABCD";
59
60 out.append(testData, 1, 3);
61 out.append(null, 1, 3);
62
63 assertEquals(testData.substring(1, 3) + "ul", out.getAppendable().toString());
64 }
65
66 @Test
67 public void testWriteChars() throws Exception {
68 final String testData = "ABCD";
69
70 out.write(testData.toCharArray());
71
72 assertEquals(testData, out.getAppendable().toString());
73 }
74
75 @Test
76 public void testWriteInt() throws Exception {
77 out.write('F');
78
79 assertEquals("F", out.getAppendable().toString());
80 }
81
82 @Test
83 public void testWriteString() throws Exception {
84 final String testData = "ABCD";
85
86 out.write(testData);
87
88 assertEquals(testData, out.getAppendable().toString());
89 }
90 }