Created
May 28, 2024 06:18
-
-
Save dsmiley/8a34cf16dd5827e5396e6da24e19afd2 to your computer and use it in GitHub Desktop.
ArchUnit dependency rule Zk and Netty
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package org.apache.zookeeper; | |
import static com.tngtech.archunit.core.importer.ImportOption.Predefined.DO_NOT_INCLUDE_TESTS; | |
import static com.tngtech.archunit.lang.syntax.ArchRuleDefinition.classes; | |
import com.tngtech.archunit.base.DescribedPredicate; | |
import com.tngtech.archunit.core.domain.JavaClass; | |
import com.tngtech.archunit.core.domain.JavaClasses; | |
import com.tngtech.archunit.core.importer.ClassFileImporter; | |
import com.tngtech.archunit.core.importer.ImportOption; | |
import com.tngtech.archunit.junit.AnalyzeClasses; | |
import com.tngtech.archunit.lang.ArchRule; | |
import com.tngtech.archunit.lang.syntax.ArchRuleDefinition; | |
import java.util.Collections; | |
import org.junit.jupiter.api.Test; | |
@AnalyzeClasses(importOptions = {ImportOption.DoNotIncludeTests.class, | |
ImportOption.DoNotIncludeJars.class}) | |
public class ZkArchUnitTest { | |
@Test | |
public void nettyRule() { | |
JavaClasses importedClasses = new ClassFileImporter( | |
Collections.singletonList(DO_NOT_INCLUDE_TESTS)).importPackages("org.apache.zookeeper") | |
.that(new DescribedPredicate<JavaClass>( | |
"ZK Non-Netty classes") { | |
@Override | |
public boolean test(JavaClass javaClass) { | |
return !javaClass.getName().contains("Netty"); | |
} | |
}); | |
ArchRule rule = ArchRuleDefinition.noClasses().should() | |
.dependOnClassesThat() | |
.resideInAnyPackage("io.netty..") | |
.orShould().dependOnClassesThat() | |
.haveSimpleNameContaining("Netty"); | |
rule.check(importedClasses); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment