-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathPdfRenderInterfaceGuardTest.java
More file actions
49 lines (39 loc) · 1.66 KB
/
PdfRenderInterfaceGuardTest.java
File metadata and controls
49 lines (39 loc) · 1.66 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
package com.demcha.compose.engine.render.pdf;
import org.junit.jupiter.api.Test;
import java.io.IOException;
import java.nio.file.Files;
import java.nio.file.Path;
import java.util.Set;
import java.util.TreeSet;
import java.util.regex.Pattern;
import java.util.stream.Collectors;
import static org.assertj.core.api.Assertions.assertThat;
class PdfRenderInterfaceGuardTest {
private static final Set<String> ALLOWLIST = Set.of();
private static final Pattern PDF_RENDER_PATTERN = Pattern.compile(
"implements\\s+[^\\{;]*\\bPdfRender\\b",
Pattern.MULTILINE | Pattern.DOTALL
);
@Test
void shouldNotAllowBackendSpecificPdfRenderUsageInMainSources() throws IOException {
Path projectRoot = Path.of("").toAbsolutePath().normalize();
Path sourceRoot = projectRoot.resolve("src/main/java");
try (var paths = Files.walk(sourceRoot)) {
Set<String> actual = new TreeSet<>(paths
.filter(Files::isRegularFile)
.filter(path -> path.toString().endsWith(".java"))
.filter(this::implementsBackendSpecificPdfRender)
.map(projectRoot::relativize)
.map(path -> path.toString().replace('\\', '/'))
.collect(Collectors.toSet()));
assertThat(actual).containsExactlyInAnyOrderElementsOf(ALLOWLIST);
}
}
private boolean implementsBackendSpecificPdfRender(Path path) {
try {
return PDF_RENDER_PATTERN.matcher(Files.readString(path)).find();
} catch (IOException e) {
throw new RuntimeException("Failed to inspect " + path, e);
}
}
}