@@ -42,6 +42,9 @@ public class MainTest {
4242
4343 @ Rule public TemporaryFolder testFolder = new TemporaryFolder ();
4444
45+ // PrintWriter instances used below are hard-coded to use system-default line separator.
46+ private final Joiner joiner = Joiner .on (System .lineSeparator ());
47+
4548 @ Test
4649 public void testUsageOutput () {
4750 StringWriter out = new StringWriter ();
@@ -145,11 +148,11 @@ public void javadoc() throws Exception {
145148 "}" ,
146149 "" ,
147150 };
148- InputStream in = new ByteArrayInputStream (Joiner . on ( '\n' ) .join (input ).getBytes (UTF_8 ));
151+ InputStream in = new ByteArrayInputStream (joiner .join (input ).getBytes (UTF_8 ));
149152 StringWriter out = new StringWriter ();
150153 Main main = new Main (new PrintWriter (out , true ), new PrintWriter (System .err , true ), in );
151154 assertThat (main .format ("-" )).isEqualTo (0 );
152- assertThat (out .toString ()).isEqualTo (Joiner . on ( '\n' ) .join (expected ));
155+ assertThat (out .toString ()).isEqualTo (joiner .join (expected ));
153156 }
154157
155158 // end to end import fixing test
@@ -177,11 +180,11 @@ public void imports() throws Exception {
177180 " public static List<String> names;" ,
178181 "}" ,
179182 };
180- InputStream in = new ByteArrayInputStream (Joiner . on ( '\n' ) .join (input ).getBytes (UTF_8 ));
183+ InputStream in = new ByteArrayInputStream (joiner .join (input ).getBytes (UTF_8 ));
181184 StringWriter out = new StringWriter ();
182185 Main main = new Main (new PrintWriter (out , true ), new PrintWriter (System .err , true ), in );
183186 assertThat (main .format ("-" , "--fix-imports-only" )).isEqualTo (0 );
184- assertThat (out .toString ()).isEqualTo (Joiner . on ( '\n' ) .join (expected ));
187+ assertThat (out .toString ()).isEqualTo (joiner .join (expected ));
185188 }
186189 {
187190 String [] expected = {
@@ -191,13 +194,13 @@ public void imports() throws Exception {
191194 " public static List<String> names;" ,
192195 "}" ,
193196 };
194- InputStream in = new ByteArrayInputStream (Joiner . on ( '\n' ) .join (input ).getBytes (UTF_8 ));
197+ InputStream in = new ByteArrayInputStream (joiner .join (input ).getBytes (UTF_8 ));
195198 StringWriter out = new StringWriter ();
196199 Main main = new Main (new PrintWriter (out , true ), new PrintWriter (System .err , true ), in );
197200 assertThat (
198201 main .format ("-" , "--fix-imports-only" , "--experimental-remove-javadoc-only-imports" ))
199202 .isEqualTo (0 );
200- assertThat (out .toString ()).isEqualTo (Joiner . on ( '\n' ) .join (expected ));
203+ assertThat (out .toString ()).isEqualTo (joiner .join (expected ));
201204 }
202205 }
203206
@@ -224,9 +227,9 @@ public void importRemovalLines() throws Exception {
224227 new Main (
225228 new PrintWriter (out , true ),
226229 new PrintWriter (System .err , true ),
227- new ByteArrayInputStream (Joiner . on ( '\n' ) .join (input ).getBytes (UTF_8 )));
230+ new ByteArrayInputStream (joiner .join (input ).getBytes (UTF_8 )));
228231 assertThat (main .format ("-" , "-lines" , "4" )).isEqualTo (0 );
229- assertThat (out .toString ()).isEqualTo (Joiner . on ( '\n' ) .join (expected ));
232+ assertThat (out .toString ()).isEqualTo (joiner .join (expected ));
230233 }
231234
232235 // test that errors are reported on the right line when imports are removed
@@ -244,7 +247,7 @@ public void importRemoveErrorParseError() throws Exception {
244247 new Main (
245248 new PrintWriter (out , true ),
246249 new PrintWriter (err , true ),
247- new ByteArrayInputStream (Joiner . on ( '\n' ) .join (input ).getBytes (UTF_8 )));
250+ new ByteArrayInputStream (joiner .join (input ).getBytes (UTF_8 )));
248251 assertThat (main .format ("-" )).isEqualTo (1 );
249252 assertThat (err .toString ()).contains ("<stdin>:4:3: error: class, interface, or enum expected" );
250253 }
0 commit comments