Search in sources :

Example 16 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project micrometer by micrometer-metrics.

the class JvmGcMetricsTest method noJvmImplementationSpecificApiSignatures.

@Test
void noJvmImplementationSpecificApiSignatures() {
    JavaClasses importedClasses = new ClassFileImporter().importPackages("io.micrometer.binder.jvm");
    ArchRule noSunManagementInMethodSignatures = methods().should().notHaveRawReturnType(resideInAPackage("com.sun.management..")).andShould().notHaveRawParameterTypes(DescribedPredicate.anyElementThat(resideInAPackage("com.sun.management..")));
    noSunManagementInMethodSignatures.check(importedClasses);
}
Also used : ArchRule(com.tngtech.archunit.lang.ArchRule) JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 17 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-sample-app-websocket by jhipster.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("io.github.jhipster.sample");
    noClasses().that().resideInAnyPackage("io.github.jhipster.sample.service..").or().resideInAnyPackage("io.github.jhipster.sample.repository..").should().dependOnClassesThat().resideInAnyPackage("..io.github.jhipster.sample.web..").because("Services and repositories should not depend on web layer").check(importedClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 18 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-sample-app-elasticsearch by jhipster.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("io.github.jhipster.sample");
    noClasses().that().resideInAnyPackage("io.github.jhipster.sample.service..").or().resideInAnyPackage("io.github.jhipster.sample.repository..").should().dependOnClassesThat().resideInAnyPackage("..io.github.jhipster.sample.web..").because("Services and repositories should not depend on web layer").check(importedClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 19 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project jhipster-sample-app-dto by jhipster.

the class ArchTest method servicesAndRepositoriesShouldNotDependOnWebLayer.

@Test
void servicesAndRepositoriesShouldNotDependOnWebLayer() {
    JavaClasses importedClasses = new ClassFileImporter().withImportOption(ImportOption.Predefined.DO_NOT_INCLUDE_TESTS).importPackages("io.github.jhipster.sample");
    noClasses().that().resideInAnyPackage("io.github.jhipster.sample.service..").or().resideInAnyPackage("io.github.jhipster.sample.repository..").should().dependOnClassesThat().resideInAnyPackage("..io.github.jhipster.sample.web..").because("Services and repositories should not depend on web layer").check(importedClasses);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Example 20 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project solarthing by wildmountainfarms.

the class ArchTest method classes_contain_both_equals_and_hash_code_or_contain_neither.

@Test
void classes_contain_both_equals_and_hash_code_or_contain_neither() {
    // TODO Note this only checks the method name, so someone could overload equals or hashCode and cause errors
    JavaClasses importedClasses = new ClassFileImporter().importPackages("me.retrodaredevil");
    for (JavaClass javaClass : importedClasses) {
        boolean overridesEquals = javaClass.getMethods().stream().anyMatch(method -> "equals".equals(method.getName()));
        boolean overridesHashCode = javaClass.getMethods().stream().anyMatch(method -> "hashCode".equals(method.getName()));
        if (overridesEquals != overridesHashCode) {
            if (overridesEquals) {
                fail(javaClass + " overrides equals but not hashCode()!");
            } else {
                fail(javaClass + " overrides hashCode() but not equals()!");
            }
        }
    }
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) JavaClass(com.tngtech.archunit.core.domain.JavaClass) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.jupiter.api.Test)

Aggregations

ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)136 JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)98 Test (org.junit.Test)76 Test (org.junit.jupiter.api.Test)52 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaClass (com.tngtech.archunit.core.domain.JavaClass)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 ArchRule (com.tngtech.archunit.lang.ArchRule)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10 JavaPackage (com.tngtech.archunit.core.domain.JavaPackage)5 LayeredArchitecture (com.tngtech.archunit.library.Architectures.LayeredArchitecture)5 OnionArchitecture (com.tngtech.archunit.library.Architectures.OnionArchitecture)5 Optional (java.util.Optional)5 Artifact (org.archifacts.core.model.Artifact)5 MiscArtifact (org.archifacts.core.model.MiscArtifact)5