-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathEnginePdfBoundaryTest.java
More file actions
65 lines (54 loc) · 2.37 KB
/
EnginePdfBoundaryTest.java
File metadata and controls
65 lines (54 loc) · 2.37 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
package com.demcha.compose.engine.architecture;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.List;
import java.util.TreeSet;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
class EnginePdfBoundaryTest {
@Test
void componentsPackageShouldNotDependOnPdfboxOrPdfSystems() throws IOException {
Path projectRoot = Path.of("").toAbsolutePath().normalize();
Path sourceRoot = projectRoot.resolve("src/main/java/com/demcha/compose/engine/components");
try (var paths = Files.walk(sourceRoot)) {
List<String> violations = new TreeSet<>(paths
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".java"))
.filter(this::containsForbiddenImports)
.map(projectRoot::relativize)
.map(path -> path.toString().replace('\\', '/'))
.collect(Collectors.toList()))
.stream()
.toList();
assertThat(violations).isEmpty();
}
}
@Test
void engineRenderInterfacesShouldStayBackendNeutral() throws IOException {
Path projectRoot = Path.of("").toAbsolutePath().normalize();
Path sourceRoot = projectRoot.resolve("src/main/java/com/demcha/compose/engine/render");
try (var paths = Files.walk(sourceRoot, 1)) {
List<String> violations = new TreeSet<>(paths
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".java"))
.filter(this::containsForbiddenImports)
.map(projectRoot::relativize)
.map(path -> path.toString().replace('\\', '/'))
.collect(Collectors.toList()))
.stream()
.toList();
assertThat(violations).isEmpty();
}
}
private boolean containsForbiddenImports(Path path) {
try {
String source = Files.readString(path);
return source.contains("org.apache.pdfbox")
|| source.contains("com.demcha.compose.engine.render.pdf");
} catch (IOException e) {
throw new RuntimeException("Failed to inspect " + path, e);
}
}
}