-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringMultiLineTest.java
More file actions
92 lines (80 loc) · 2.43 KB
/
StringMultiLineTest.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
package basics;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Files;
import java.nio.file.Paths;
public class StringMultiLineTest {
String newLine;
@BeforeEach
public void setUp() {
newLine = System.getProperty("line.separator");
}
@Test
public void text_block_test() {
String sentence = """
happy new year
Stay healthy always.
2025-01-30
""";
System.out.println(sentence);
}
@Test
public void text_concat_test() {
String sentence = "happy new year"
.concat(newLine)
.concat("Stay healthy always.")
.concat(newLine)
.concat("2025-01-30")
.concat(newLine);
System.out.println(sentence);
}
@Test
public void text_operator_test() {
String sentence = "happy new year"
+ newLine
+ "Stay healthy always."
+ newLine
+ "2025-01-30"
+ newLine;
System.out.println(sentence);
}
@Test
public void join_string_test() {
String sentence = String.join(newLine
, "happy new year"
, "Stay healthy always."
, "2025-01-30");
System.out.println(sentence);
}
@Test
public void builder_multiline_test() {
String sentence = new StringBuilder()
.append("happy new year")
.append(newLine)
.append("Stay healthy always.")
.append(newLine)
.append("2025-01-30")
.toString();
System.out.println(sentence);
}
@Test
public void writer_test() {
StringWriter stringWriter = new StringWriter();
PrintWriter printWriter = new PrintWriter(stringWriter);
printWriter.println("happy new year");
printWriter.println("Stay healthy always.");
printWriter.println("2025-01-30");
System.out.println(stringWriter.toString());
}
@Test
public void read_file_test() {
try {
System.out.println(new String(Files.readAllBytes(Paths.get("src/test/resources/multi-line.txt"))));
} catch (IOException e) {
System.out.println("error");
}
}
}