- Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMultiLineTest.java
More file actions
Latest commit
92 lines (80 loc) · 2.43 KB
/
Copy pathStringMultiLineTest.java
File metadata and controls
92 lines (80 loc) · 2.43 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
packagebasics;
importorg.junit.jupiter.api.BeforeEach;
importorg.junit.jupiter.api.Test;
importjava.io.IOException;
importjava.io.PrintWriter;
importjava.io.StringWriter;
importjava.nio.file.Files;
importjava.nio.file.Paths;
publicclassStringMultiLineTest {
StringnewLine;
@BeforeEach
publicvoidsetUp() {
newLine = System.getProperty("line.separator");
}
@Test
publicvoidtext_block_test() {
Stringsentence = """
happy new year
Stay healthy always.
2025-01-30
""";
System.out.println(sentence);
}
@Test
publicvoidtext_concat_test() {
Stringsentence = "happy new year"
.concat(newLine)
.concat("Stay healthy always.")
.concat(newLine)
.concat("2025-01-30")
.concat(newLine);
System.out.println(sentence);
}
@Test
publicvoidtext_operator_test() {
Stringsentence = "happy new year"
+ newLine
+ "Stay healthy always."
+ newLine
+ "2025-01-30"
+ newLine;
System.out.println(sentence);
}
@Test
publicvoidjoin_string_test() {
Stringsentence = String.join(newLine
, "happy new year"
, "Stay healthy always."
, "2025-01-30");
System.out.println(sentence);
}
@Test
publicvoidbuilder_multiline_test() {
Stringsentence = newStringBuilder()
.append("happy new year")
.append(newLine)
.append("Stay healthy always.")
.append(newLine)
.append("2025-01-30")
.toString();
System.out.println(sentence);
}
@Test
publicvoidwriter_test() {
StringWriterstringWriter = newStringWriter();
PrintWriterprintWriter = newPrintWriter(stringWriter);
printWriter.println("happy new year");
printWriter.println("Stay healthy always.");
printWriter.println("2025-01-30");
System.out.println(stringWriter.toString());
}
@Test
publicvoidread_file_test() {
try {
System.out.println(newString(Files.readAllBytes(Paths.get("src/test/resources/multi-line.txt"))));
} catch (IOExceptione) {
System.out.println("error");
}
}
}