Skip to content

Commit 3409754

Browse files
committed
Factor out helper method
1 parent 778f485 commit 3409754

File tree

1 file changed

+10
-8
lines changed

1 file changed

+10
-8
lines changed

lib/src/testCompatKtLint0Dot48Dot0/java/com/diffplug/spotless/glue/ktlint/compat/KtLintCompat0Dot48Dot0AdapterTest.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -32,10 +32,7 @@ public class KtLintCompat0Dot48Dot0AdapterTest {
3232
@Test
3333
public void testDefaults(@TempDir Path path) throws IOException {
3434
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
35-
try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/empty_class_body.kt")) {
36-
Files.copy(is, path.resolve("empty_class_body.kt"));
37-
}
38-
String text = new String(Files.readAllBytes(path.resolve("empty_class_body.kt")), StandardCharsets.UTF_8);
35+
String text = loadAndWriteText(path, "empty_class_body.kt");
3936

4037
Map<String, String> userData = new HashMap<>();
4138

@@ -48,10 +45,7 @@ public void testDefaults(@TempDir Path path) throws IOException {
4845
@Test
4946
public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
5047
KtLintCompat0Dot48Dot0Adapter ktLintCompat0Dot48Dot0Adapter = new KtLintCompat0Dot48Dot0Adapter();
51-
try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/fails_no_semicolons.kt")) {
52-
Files.copy(is, path.resolve("fails_no_semicolons.kt"));
53-
}
54-
String text = new String(Files.readAllBytes(path.resolve("fails_no_semicolons.kt")), StandardCharsets.UTF_8);
48+
String text = loadAndWriteText(path, "fails_no_semicolons.kt");
5549

5650
Map<String, String> userData = new HashMap<>();
5751

@@ -62,4 +56,12 @@ public void testEditorConfigCanDisable(@TempDir Path path) throws IOException {
6256
String formatted = ktLintCompat0Dot48Dot0Adapter.format(text, "fails_no_semicolons.kt", false, false, userData, editorConfigOverrideMap);
6357
assertEquals("class fails_no_semicolons {\n\tval i = 0;\n}\n", formatted);
6458
}
59+
60+
private static String loadAndWriteText(Path path, String name) throws IOException {
61+
try (InputStream is = KtLintCompat0Dot48Dot0AdapterTest.class.getResourceAsStream("/" + name)) {
62+
Files.copy(is, path.resolve(name));
63+
}
64+
return new String(Files.readAllBytes(path.resolve(name)), StandardCharsets.UTF_8);
65+
}
66+
6567
}

0 commit comments

Comments
 (0)