Skip to content

Commit 899b345

Browse files
Adapt LineExtension tests
1 parent 279bdb6 commit 899b345

File tree

1 file changed

+19
-40
lines changed

1 file changed

+19
-40
lines changed

src/test/java/io/github/computerdaddyguy/jfiletreeprettyprinter/LineExtensionTest.java

Lines changed: 19 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -31,21 +31,12 @@ void example_dir_match() {
3131

3232
var printedPath = Path.of("src/example/resources/line_extension");
3333

34-
Function<Path, String> lineExtension = path -> {
35-
if (PathMatchers.hasRelativePathMatchingGlob(printedPath, "src/main/java/api").matches(path)) {
36-
return "\t\t\t// All API code: controllers, etc.";
37-
}
38-
if (PathMatchers.hasRelativePathMatchingGlob(printedPath, "src/main/java/domain").matches(path)) {
39-
return "\t\t\t// All domain code: value objects, etc.";
40-
}
41-
if (PathMatchers.hasRelativePathMatchingGlob(printedPath, "src/main/java/infra").matches(path)) {
42-
return "\t\t\t// All infra code: database, email service, etc.";
43-
}
44-
if (PathMatchers.hasNameMatchingGlob("*.properties").matches(path)) {
45-
return "\t// Config file";
46-
}
47-
return null;
48-
};
34+
Function<Path, String> lineExtension = LineExtensionBuilder.newInstance()
35+
.add(PathMatchers.hasRelativePathMatchingGlob(printedPath, "src/main/java/api"), "\t\t\t// All API code: controllers, etc.")
36+
.add(PathMatchers.hasRelativePathMatchingGlob(printedPath, "src/main/java/domain"), "\t\t\t// All domain code: value objects, etc.")
37+
.add(PathMatchers.hasRelativePathMatchingGlob(printedPath, "src/main/java/infra"), "\t\t\t// All infra code: database, email service, etc.")
38+
.add(PathMatchers.hasNameMatchingGlob("*.properties"), "\t// Config file")
39+
.build();
4940

5041
var printer = FileTreePrettyPrinter.builder()
5142
.customizeOptions(options -> options.withLineExtension(lineExtension))
@@ -71,12 +62,9 @@ void example_dir_match() {
7162
@Test
7263
void compact_dir_first_dir() {
7364

74-
Function<Path, String> lineExtension = p -> {
75-
if (PathMatchers.hasName("dirA").matches(p)) {
76-
return " // 1";
77-
}
78-
return null;
79-
};
65+
Function<Path, String> lineExtension = LineExtensionBuilder.newInstance()
66+
.add(PathMatchers.hasName("dirA"), " // 1")
67+
.build();
8068

8169
var expected = """
8270
targetPath/
@@ -91,14 +79,11 @@ void compact_dir_first_dir() {
9179
}
9280

9381
@Test
94-
void compact_dir_empty_string_workds() {
82+
void compact_dir_empty_string_creates_line_break() {
9583

96-
Function<Path, String> lineExtension = p -> {
97-
if (PathMatchers.hasName("dirA").matches(p)) {
98-
return "";
99-
}
100-
return null;
101-
};
84+
Function<Path, String> lineExtension = LineExtensionBuilder.newInstance()
85+
.addLineBreak(PathMatchers.hasName("dirA"))
86+
.build();
10287

10388
var expected = """
10489
targetPath/
@@ -115,12 +100,9 @@ void compact_dir_empty_string_workds() {
115100
@Test
116101
void compact_dir_middle_dir() {
117102

118-
Function<Path, String> lineExtension = p -> {
119-
if (PathMatchers.hasName("dirB").matches(p)) {
120-
return " // 2";
121-
}
122-
return null;
123-
};
103+
Function<Path, String> lineExtension = LineExtensionBuilder.newInstance()
104+
.add(PathMatchers.hasName("dirB"), " // 2")
105+
.build();
124106

125107
var expected = """
126108
targetPath/
@@ -137,12 +119,9 @@ void compact_dir_middle_dir() {
137119
@Test
138120
void compact_dir_last_dir() {
139121

140-
Function<Path, String> lineExtension = p -> {
141-
if (PathMatchers.hasName("dirC").matches(p)) {
142-
return " // 3";
143-
}
144-
return null;
145-
};
122+
Function<Path, String> lineExtension = LineExtensionBuilder.newInstance()
123+
.add(PathMatchers.hasName("dirC"), " // 3")
124+
.build();
146125

147126
var expected = """
148127
targetPath/

0 commit comments

Comments
 (0)