Slide 42
Slide 42 text
Enforcing Package Usage
(Java 8 with code-assert)
@Test
public void dependency() {
class ComHello extends DependencyRuler {
DependencyRule paymentApi, paymentImpl, invoiceApi;
public void defineRules() {
paymentApi().mayUse(invoiceApi);
paymentImpl().mayUse(paymentApi, invoiceApi);
}
}
AnalyzerConfig config = AnalyzerConfig.maven().main();
DependencyRules rules = DependencyRules.denyAll()
.withRelativeRules(new ComHello()).withExternals("java.sql");
DependencyResult result = new DependencyAnalyzer(config).rules(rules).analyze();
assertThat(result, matchesRulesExactly());
}
https://github.com/nidi3/code-assert