@@ -49,17 +49,31 @@ private static void assertFormats(String input, String expected) throws Formatte
4949
5050 @ Test
5151 public void formatsAndFixesImports () throws FormatterException {
52- String input = "import module java.base;\n " + "class Example {}\n " ;
53- String expected = "import module java.base;\n " + "\n " + "class Example {}\n " ;
52+ String input = """
53+ import module java.base;
54+ class Example {}
55+ """ ;
56+ String expected = """
57+ import module java.base;
58+
59+ class Example {}
60+ """ ;
5461 assertFormats (input , expected );
5562 }
5663
5764 @ Test
5865 public void fixesImportsOnlyFromTheCommandLine () throws Exception {
5966 // The flag combination from the #1506 report, which failed with `Expected ; after import`.
60- String input = "import module java.base;\n " + "class Example {}\n " ;
67+ String input = """
68+ import module java.base;
69+ class Example {}
70+ """ ;
6171 // Reordering puts a blank line after the import block; nothing else changes.
62- String expected = "import module java.base;\n " + "\n " + "class Example {}\n " ;
72+ String expected = """
73+ import module java.base;
74+
75+ class Example {}
76+ """ ;
6377 StringWriter out = new StringWriter ();
6478 StringWriter err = new StringWriter ();
6579 Main main = new Main (
@@ -74,50 +88,88 @@ public void fixesImportsOnlyFromTheCommandLine() throws Exception {
7488
7589 @ Test
7690 public void keepsACommentBetweenModuleAndTheModuleName () throws FormatterException {
77- String input = "import module /* comment */ java.base;\n " + "class Example {}\n " ;
78- String expected = "import module /* comment */ java.base;\n " + "\n " + "class Example {}\n " ;
91+ String input = """
92+ import module /* comment */ java.base;
93+ class Example {}
94+ """ ;
95+ String expected = """
96+ import module /* comment */ java.base;
97+
98+ class Example {}
99+ """ ;
79100 assertFormats (input , expected );
80101 }
81102
82103 @ Test
83104 public void keepsACommentBetweenThePartsOfTheModuleName () throws FormatterException {
84- String input = "import module java./* comment */base;\n " + "class Example {}\n " ;
105+ String input = """
106+ import module java./* comment */base;
107+ class Example {}
108+ """ ;
85109 // Reordering normalizes the whitespace around the comment and leaves it between the parts.
86- String reordered = "import module java./* comment */ base;\n " + "\n " + "class Example {}\n " ;
110+ String reordered = """
111+ import module java./* comment */ base;
112+
113+ class Example {}
114+ """ ;
87115 assertThat (Formatter .create ().fixImports (input )).isEqualTo (reordered );
88116 assertThat (Formatter .create ().fixImports (reordered )).isEqualTo (reordered );
89117
90118 // Formatting then breaks the line after the dot, which is where the formatter puts a comment
91119 // in a qualified name; that output is stable too.
92- String formatted = "import module java.\n " + "/* comment */ base;\n " + "\n " + "class Example {}\n " ;
120+ String formatted = """
121+ import module java.
122+ /* comment */ base;
123+
124+ class Example {}
125+ """ ;
93126 assertThat (Formatter .create ().formatSourceAndFixImports (input )).isEqualTo (formatted );
94127 assertThat (Formatter .create ().formatSourceAndFixImports (formatted )).isEqualTo (formatted );
95128 }
96129
97130 @ Test
98131 public void normalizesWhitespaceInsideTheModuleName () throws FormatterException {
99- String input = "import module java . base;\n " + "class Example {}\n " ;
100- String expected = "import module java.base;\n " + "\n " + "class Example {}\n " ;
132+ String input = """
133+ import module java . base;
134+ class Example {}
135+ """ ;
136+ String expected = """
137+ import module java.base;
138+
139+ class Example {}
140+ """ ;
101141 assertFormats (input , expected );
102142 }
103143
104144 @ Test
105145 public void keepsBothCopiesOfADuplicateThatCarriesAComment () throws FormatterException {
106146 // Identical declarations collapse; ones that differ are both kept, so no comment is dropped.
107- String input = "import module /* explanation A */ java.base;\n "
108- + "import module /* explanation B */ java.base;\n "
109- + "class Example {}\n " ;
110- String expected = "import module /* explanation A */ java.base;\n "
111- + "import module /* explanation B */ java.base;\n "
112- + "\n "
113- + "class Example {}\n " ;
147+ String input = """
148+ import module /* explanation A */ java.base;
149+ import module /* explanation B */ java.base;
150+ class Example {}
151+ """ ;
152+ String expected = """
153+ import module /* explanation A */ java.base;
154+ import module /* explanation B */ java.base;
155+
156+ class Example {}
157+ """ ;
114158 assertFormats (input , expected );
115159 }
116160
117161 @ Test
118162 public void acceptsALineBreakAfterModule () throws FormatterException {
119- String input = "import module\n " + " java.base;\n " + "class Example {}\n " ;
120- String expected = "import module java.base;\n " + "\n " + "class Example {}\n " ;
163+ String input = """
164+ import module
165+ java.base;
166+ class Example {}
167+ """ ;
168+ String expected = """
169+ import module java.base;
170+
171+ class Example {}
172+ """ ;
121173 assertFormats (input , expected );
122174 }
123175}
0 commit comments