Skip to content

Commit 7c2c6e7

Browse files
eamonnmcmanusgoogle-java-format Team
authored andcommitted
Rewrite tests to use text blocks for improved readability.
PiperOrigin-RevId: 886963195
1 parent e573100 commit 7c2c6e7

File tree

10 files changed

+2486
-2223
lines changed

10 files changed

+2486
-2223
lines changed

core/src/test/java/com/google/googlejavaformat/java/DiagnosticTest.java

Lines changed: 33 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,6 @@
1717
import static com.google.common.truth.Truth.assertThat;
1818
import static java.nio.charset.StandardCharsets.UTF_8;
1919

20-
import com.google.common.base.Joiner;
2120
import java.io.ByteArrayInputStream;
2221
import java.io.IOException;
2322
import java.io.InputStream;
@@ -55,19 +54,19 @@ public void restoreLocale() throws Exception {
5554
@Test
5655
public void parseError() throws Exception {
5756
String input =
58-
Joiner.on('\n')
59-
.join(
60-
"public class InvalidSyntax {",
61-
" private static NumPrinter {",
62-
" public static void print(int n) {",
63-
" System.out.printf(\"%d%n\", n);",
64-
" }",
65-
" }",
66-
"",
67-
" public static void main(String[] args) {",
68-
" NumPrinter.print(args.length);",
69-
" }",
70-
"}");
57+
"""
58+
public class InvalidSyntax {
59+
private static NumPrinter {
60+
public static void print(int n) {
61+
System.out.printf("%d%n", n);
62+
}
63+
}
64+
65+
public static void main(String[] args) {
66+
NumPrinter.print(args.length);
67+
}
68+
}\
69+
""";
7170

7271
StringWriter stdout = new StringWriter();
7372
StringWriter stderr = new StringWriter();
@@ -150,7 +149,11 @@ public void oneFileParseErrorReplace() throws Exception {
150149

151150
@Test
152151
public void parseError2() throws FormatterException, IOException, UsageException {
153-
String input = "class Foo { void f() {\n g() } }";
152+
String input =
153+
"""
154+
class Foo { void f() {
155+
g() } }
156+
""";
154157

155158
Path tmpdir = testFolder.newFolder().toPath();
156159
Path path = tmpdir.resolve("A.java");
@@ -169,7 +172,11 @@ public void parseError2() throws FormatterException, IOException, UsageException
169172

170173
@Test
171174
public void parseErrorStdin() throws FormatterException, IOException, UsageException {
172-
String input = "class Foo { void f() {\n g() } }";
175+
String input =
176+
"""
177+
class Foo { void f() {
178+
g() } }
179+
""";
173180

174181
InputStream inStream = new ByteArrayInputStream(input.getBytes(UTF_8));
175182
StringWriter out = new StringWriter();
@@ -184,7 +191,11 @@ public void parseErrorStdin() throws FormatterException, IOException, UsageExcep
184191

185192
@Test
186193
public void lexError2() throws FormatterException, IOException, UsageException {
187-
String input = "class Foo { void f() {\n g('foo'); } }";
194+
String input =
195+
"""
196+
class Foo { void f() {
197+
g('foo'); } }
198+
""";
188199

189200
Path tmpdir = testFolder.newFolder().toPath();
190201
Path path = tmpdir.resolve("A.java");
@@ -203,7 +214,11 @@ public void lexError2() throws FormatterException, IOException, UsageException {
203214

204215
@Test
205216
public void lexErrorStdin() throws FormatterException, IOException, UsageException {
206-
String input = "class Foo { void f() {\n g('foo'); } }";
217+
String input =
218+
"""
219+
class Foo { void f() {
220+
g('foo'); } }
221+
""";
207222
InputStream inStream = new ByteArrayInputStream(input.getBytes(UTF_8));
208223
StringWriter out = new StringWriter();
209224
StringWriter err = new StringWriter();

0 commit comments

Comments
 (0)