-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathCanonicalTemplateComposerPdfBoundaryTest.java
More file actions
47 lines (39 loc) · 1.69 KB
/
CanonicalTemplateComposerPdfBoundaryTest.java
File metadata and controls
47 lines (39 loc) · 1.69 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
package com.demcha.compose.document.templates.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 CanonicalTemplateComposerPdfBoundaryTest {
@Test
void templateComposersShouldNotDependOnPdfTypesOrPdfComposer() throws IOException {
Path projectRoot = Path.of("").toAbsolutePath().normalize();
Path sourceRoot = projectRoot.resolve("src/main/java/com/demcha/compose/document/templates/support");
try (var paths = Files.walk(sourceRoot)) {
List<String> violations = new TreeSet<>(paths
.filter(Files::isRegularFile)
.filter(path -> path.getFileName().toString().endsWith("TemplateComposer.java"))
.filter(this::containsForbiddenReferences)
.map(projectRoot::relativize)
.map(path -> path.toString().replace('\\', '/'))
.collect(Collectors.toList()))
.stream()
.toList();
assertThat(violations).isEmpty();
}
}
private boolean containsForbiddenReferences(Path path) {
try {
String source = Files.readString(path);
return source.contains("PDDocument")
|| source.contains("PDPage")
|| source.contains("PDRectangle")
|| source.contains("PdfComposer");
} catch (IOException e) {
throw new RuntimeException("Failed to inspect " + path, e);
}
}
}