Skip to content

Commit 9263c50

Browse files
Refactor unit tests + PI mutation testing
1 parent 94ee62e commit 9263c50

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

49 files changed

+782
-846
lines changed

pom.xml

Lines changed: 25 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,8 @@
4848
<build-helper-maven-plugin.version>3.6.1</build-helper-maven-plugin.version>
4949
<maven-jar-plugin.version>3.4.2</maven-jar-plugin.version>
5050
<jacoco-maven-plugin.version>0.8.12</jacoco-maven-plugin.version>
51+
<pitest-maven.version>1.20.2</pitest-maven.version>
52+
<pitest-junit5-plugin.version>1.2.3</pitest-junit5-plugin.version>
5153

5254
</properties>
5355

@@ -69,7 +71,6 @@
6971
<version>${assertj.version}</version>
7072
<scope>test</scope>
7173
</dependency>
72-
7374
</dependencies>
7475

7576
<build>
@@ -108,6 +109,7 @@
108109
</execution>
109110
</executions>
110111
</plugin>
112+
111113
<plugin>
112114
<groupId>org.apache.maven.plugins</groupId>
113115
<artifactId>maven-jar-plugin</artifactId>
@@ -166,6 +168,28 @@
166168
</executions>
167169
</plugin>
168170

171+
<plugin>
172+
<groupId>org.pitest</groupId>
173+
<artifactId>pitest-maven</artifactId>
174+
<version>${pitest-maven.version}</version>
175+
<dependencies>
176+
<dependency>
177+
<groupId>org.pitest</groupId>
178+
<artifactId>pitest-junit5-plugin</artifactId>
179+
<version>${pitest-junit5-plugin.version}</version>
180+
</dependency>
181+
</dependencies>
182+
<configuration>
183+
<targetClasses>
184+
<param>io.github.computerdaddyguy.jfiletreeprettyprinter.*</param>
185+
</targetClasses>
186+
<targetTests>
187+
<param>io.github.computerdaddyguy.jfiletreeprettyprinter.*Test</param>
188+
</targetTests>
189+
</configuration>
190+
191+
</plugin>
192+
169193
</plugins>
170194

171195

src/main/java/io/github/computerdaddyguy/jfiletreeprettyprinter/renderer/depth/Depth.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -50,4 +50,17 @@ public String toString() {
5050
return symbols.toString();
5151
}
5252

53+
@Override
54+
public int hashCode() {
55+
return Objects.hash(symbols);
56+
}
57+
58+
@Override
59+
public boolean equals(Object obj) {
60+
if (obj instanceof Depth other) {
61+
return Objects.equals(symbols, other.symbols);
62+
}
63+
return false;
64+
}
65+
5366
}

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

Lines changed: 0 additions & 134 deletions
This file was deleted.
Lines changed: 83 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,83 @@
1+
package io.github.computerdaddyguy.jfiletreeprettyprinter;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import io.github.computerdaddyguy.jfiletreeprettyprinter.util.FileStructureCreator;
6+
import io.github.computerdaddyguy.jfiletreeprettyprinter.util.FileStructures;
7+
import java.nio.file.Path;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.io.TempDir;
10+
11+
class BasicUsageTest {
12+
13+
@TempDir
14+
private Path root;
15+
16+
private FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
17+
.build();
18+
19+
@Test
20+
void emptyDir() {
21+
var path = FileStructures.emptyDirectory(root);
22+
var result = printer.prettyPrint(path);
23+
var expected = "targetPath/";
24+
assertThat(result).isEqualTo(expected);
25+
}
26+
27+
@Test
28+
void dirWithFilesOnly() {
29+
var path = FileStructures.simpleDirectoryWithFiles(root, 3);
30+
var result = printer.prettyPrint(path);
31+
var expected = """
32+
targetPath/
33+
├─ file1
34+
├─ file2
35+
└─ file3""";
36+
assertThat(result).isEqualTo(expected);
37+
}
38+
39+
@Test
40+
void dirWithOneDir() {
41+
var path = FileStructureCreator.forTargetPath(root)
42+
.createDirectory("dir1")
43+
.getPath();
44+
var result = printer.prettyPrint(path);
45+
var expected = """
46+
targetPath/
47+
└─ dir1/""";
48+
assertThat(result).isEqualTo(expected);
49+
}
50+
51+
@Test
52+
void complex1() {
53+
// @formatter:off
54+
var path = FileStructureCreator
55+
.forTargetPath(root)
56+
.createAndEnterDirectory("level_1")
57+
.createAndEnterDirectory("level_1_1")
58+
.createFiles("file", 2)
59+
.up()
60+
.up()
61+
.createAndEnterDirectory("level_2")
62+
.createAndEnterDirectory("level_2_1")
63+
.createFiles("file", 2)
64+
.up()
65+
.up()
66+
.getPath()
67+
;
68+
// @formatter:on
69+
var result = printer.prettyPrint(path);
70+
var expected = """
71+
targetPath/
72+
├─ level_1/
73+
│ └─ level_1_1/
74+
│ ├─ file1
75+
│ └─ file2
76+
└─ level_2/
77+
└─ level_2_1/
78+
├─ file1
79+
└─ file2""";
80+
assertThat(result).isEqualTo(expected);
81+
}
82+
83+
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
package io.github.computerdaddyguy.jfiletreeprettyprinter;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import io.github.computerdaddyguy.jfiletreeprettyprinter.util.FileStructureCreator;
6+
import io.github.computerdaddyguy.jfiletreeprettyprinter.util.FileStructures;
7+
import java.nio.file.Path;
8+
import org.junit.jupiter.api.Test;
9+
import org.junit.jupiter.api.io.TempDir;
10+
11+
class ChildrenLimitDynamicTest {
12+
13+
@TempDir
14+
private Path root;
15+
16+
private FileTreePrettyPrinter printer = FileTreePrettyPrinter.builder()
17+
.customizeOptions(
18+
options -> options.withChildrenLimitFunction(
19+
p -> p.getFileName().toString().equals("limit_1") ? 1
20+
: p.getFileName().toString().equals("limit_3") ? 3
21+
: -1
22+
)
23+
)
24+
.build();
25+
26+
@Test
27+
void emptyDir() {
28+
var path = FileStructures.emptyDirectory(root);
29+
var result = printer.prettyPrint(path);
30+
var expected = "targetPath/";
31+
assertThat(result).isEqualTo(expected);
32+
}
33+
34+
@Test
35+
void not_limited_dir() {
36+
// @formatter:off
37+
var path = FileStructureCreator
38+
.forTargetPath(root)
39+
.createAndEnterDirectory("simpleDir")
40+
.createFiles("file", 5)
41+
.up()
42+
.getPath()
43+
;
44+
// @formatter:on
45+
46+
var result = printer.prettyPrint(path);
47+
var expected = """
48+
targetPath/
49+
└─ simpleDir/
50+
├─ file1
51+
├─ file2
52+
├─ file3
53+
├─ file4
54+
└─ file5""";
55+
assertThat(result).isEqualTo(expected);
56+
}
57+
58+
@Test
59+
void limited_dir_1() {
60+
// @formatter:off
61+
var path = FileStructureCreator
62+
.forTargetPath(root)
63+
.createAndEnterDirectory("limit_1")
64+
.createFiles("file", 5)
65+
.up()
66+
.getPath()
67+
;
68+
// @formatter:on
69+
70+
var result = printer.prettyPrint(path);
71+
var expected = """
72+
targetPath/
73+
└─ limit_1/
74+
├─ file1
75+
└─ ... (4 files skipped)""";
76+
assertThat(result).isEqualTo(expected);
77+
}
78+
79+
@Test
80+
void limited_dir_3() {
81+
// @formatter:off
82+
var path = FileStructureCreator
83+
.forTargetPath(root)
84+
.createAndEnterDirectory("limit_3")
85+
.createFiles("file", 5)
86+
.up()
87+
.getPath()
88+
;
89+
// @formatter:on
90+
91+
var result = printer.prettyPrint(path);
92+
var expected = """
93+
targetPath/
94+
└─ limit_3/
95+
├─ file1
96+
├─ file2
97+
├─ file3
98+
└─ ... (2 files skipped)""";
99+
assertThat(result).isEqualTo(expected);
100+
}
101+
102+
}

0 commit comments

Comments
 (0)