Skip to content
This repository was archived by the owner on Aug 30, 2024. It is now read-only.

Commit bfe8c84

Browse files
using Java 17 text blocks and var
1 parent 5f1ece5 commit bfe8c84

File tree

2 files changed

+37
-28
lines changed

2 files changed

+37
-28
lines changed

standalone/src/test/java/com/trivadis/plsql/formatter/AbstractTvdFormatTest.java

Lines changed: 6 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,9 @@
44

55
import java.io.File;
66
import java.io.IOException;
7-
import java.net.URL;
87
import java.nio.file.Files;
98
import java.nio.file.Path;
109
import java.nio.file.Paths;
11-
import java.util.List;
1210
import java.util.stream.Collectors;
1311

1412
public abstract class AbstractTvdFormatTest {
@@ -18,14 +16,14 @@ public abstract class AbstractTvdFormatTest {
1816
public void setup() {
1917
try {
2018
tempDir = Files.createTempDirectory("tvdformat-test-");
21-
final URL url = Thread.currentThread().getContextClassLoader().getResource("input");
19+
var url = Thread.currentThread().getContextClassLoader().getResource("input");
2220
assert url != null;
23-
final Path resourceDir = Paths.get(url.getPath());
24-
final List<Path> sources = Files.walk(resourceDir)
21+
var resourceDir = Paths.get(url.getPath());
22+
var sources = Files.walk(resourceDir)
2523
.filter(Files::isRegularFile)
2624
.collect(Collectors.toList());
2725
for (Path source : sources) {
28-
final Path target = Paths.get(tempDir.toString() + File.separator + source.getFileName());
26+
var target = Paths.get(tempDir.toString() + File.separator + source.getFileName());
2927
Files.copy(source, target);
3028
}
3129
} catch (IOException e) {
@@ -42,12 +40,12 @@ private String getFileContent(Path file) {
4240
}
4341

4442
public String getFormattedContent(String fileName) {
45-
Path file = Paths.get(tempDir.toString() + File.separator + fileName);
43+
var file = Paths.get(tempDir.toString() + File.separator + fileName);
4644
return getFileContent(file);
4745
}
4846

4947
public String getExpectedContent(String fileName) {
50-
final URL url = Thread.currentThread().getContextClassLoader().getResource("expected");
48+
var url = Thread.currentThread().getContextClassLoader().getResource("expected");
5149
assert url != null;
5250
return getFileContent(Paths.get(url.getPath() + File.separator + fileName));
5351
}

standalone/src/test/java/com/trivadis/plsql/formatter/TvdFormatTest.java

Lines changed: 31 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -7,52 +7,63 @@
77
import java.io.File;
88
import java.io.IOException;
99
import java.nio.file.Files;
10-
import java.nio.file.Path;
1110
import java.nio.file.Paths;
1211

1312
public class TvdFormatTest extends AbstractTvdFormatTest {
1413

1514
@Test
1615
public void jsonArrayDirTest() throws ScriptException, IOException {
17-
final String configFileContent = "[\"" + tempDir.toString() + "\"]";
18-
final Path configFile = Paths.get(tempDir + File.separator + "config.json");
16+
var configFileContent = """
17+
[
18+
"#TEMP_DIR#"
19+
]
20+
""".replace("#TEMP_DIR#", tempDir.toString());
21+
var configFile = Paths.get(tempDir + File.separator + "config.json");
1922
Files.write(configFile, configFileContent.getBytes());
20-
String[] args = new String[]{tempDir + File.separator + "config.json",
23+
var args = new String[]{tempDir + File.separator + "config.json",
2124
"xml=" + tempDir + File.separator + "trivadis_advanced_format.xml",
2225
"arbori=" + tempDir + File.separator + "trivadis_custom_format.arbori"};
2326
TvdFormat.main(args);
24-
String expected = getExpectedContent("query.sql");
25-
String actual = getFormattedContent("query.sql");
27+
var expected = getExpectedContent("query.sql");
28+
var actual = getFormattedContent("query.sql");
2629
Assertions.assertEquals(expected, actual);
2730
}
2831

2932
@Test
3033
public void jsonArrayFileTest() throws ScriptException, IOException {
31-
final String configFileContent = "[\"" + tempDir.toString() + File.separator + "query.sql\"]";
32-
final Path configFile = Paths.get(tempDir + File.separator + "config.json");
34+
var configFileContent = """
35+
[
36+
"#TEMP_DIR##FILE_SEP#query.sql"
37+
]
38+
""".replace("#TEMP_DIR#", tempDir.toString()).replace("#FILE_SEP#", File.separator);
39+
var configFile = Paths.get(tempDir + File.separator + "config.json");
3340
Files.write(configFile, configFileContent.getBytes());
34-
String[] args = new String[]{tempDir + File.separator + "config.json",
41+
var args = new String[]{tempDir + File.separator + "config.json",
3542
"xml=" + tempDir + File.separator + "trivadis_advanced_format.xml",
3643
"arbori=" + tempDir + File.separator + "trivadis_custom_format.arbori"};
3744
TvdFormat.main(args);
38-
String expected = getExpectedContent("query.sql");
39-
String actual = getFormattedContent("query.sql");
45+
var expected = getExpectedContent("query.sql");
46+
var actual = getFormattedContent("query.sql");
4047
Assertions.assertEquals(expected, actual);
4148
}
4249

4350
@Test
4451
public void jsonObjectFileTest() throws ScriptException, IOException {
45-
final String configFileContent = "{\n"
46-
+ " \"xml\": \"" + tempDir + File.separator + "trivadis_advanced_format.xml\",\n"
47-
+ " \"arbori\": \"" + tempDir + File.separator + "trivadis_custom_format.arbori\",\n"
48-
+ " \"files\": [\"" + tempDir.toString() + File.separator + "query.sql\"]\n"
49-
+ "}";
50-
final Path configFile = Paths.get(tempDir + File.separator + "config.json");
52+
var configFileContent = """
53+
{
54+
"xml": "#TEMP_DIR##FILE_SEP#trivadis_advanced_format.xml",
55+
"arbori": "#TEMP_DIR##FILE_SEP#trivadis_custom_format.arbori",
56+
"files": [
57+
"#TEMP_DIR##FILE_SEP#query.sql"
58+
]
59+
}
60+
""".replace("#TEMP_DIR#", tempDir.toString()).replace("#FILE_SEP#", File.separator);
61+
var configFile = Paths.get(tempDir + File.separator + "config.json");
5162
Files.write(configFile, configFileContent.getBytes());
52-
String[] args = new String[]{tempDir + File.separator + "config.json"};
63+
var args = new String[]{tempDir + File.separator + "config.json"};
5364
TvdFormat.main(args);
54-
String expected = getExpectedContent("query.sql");
55-
String actual = getFormattedContent("query.sql");
65+
var expected = getExpectedContent("query.sql");
66+
var actual = getFormattedContent("query.sql");
5667
Assertions.assertEquals(expected, actual);
5768
}
5869
}

0 commit comments

Comments
 (0)