Search in sources :

Example 26 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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 27 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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 28 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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 29 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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 30 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses 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

JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)248 Test (org.junit.Test)184 ClassFileImporter (com.tngtech.archunit.core.importer.ClassFileImporter)98 JavaClass (com.tngtech.archunit.core.domain.JavaClass)72 Test (org.junit.jupiter.api.Test)54 JavaMethodCall (com.tngtech.archunit.core.domain.JavaMethodCall)19 ArchRule (com.tngtech.archunit.lang.ArchRule)19 UseDataProvider (com.tngtech.java.junit.dataprovider.UseDataProvider)19 JavaFieldAccess (com.tngtech.archunit.core.domain.JavaFieldAccess)16 ParallelJVMTest (com.hazelcast.test.annotation.ParallelJVMTest)15 JavaMethod (com.tngtech.archunit.core.domain.JavaMethod)15 MethodCallTarget (com.tngtech.archunit.core.domain.AccessTarget.MethodCallTarget)14 EvaluationResult (com.tngtech.archunit.lang.EvaluationResult)13 Workspace (com.structurizr.Workspace)12 JavaConstructorCall (com.tngtech.archunit.core.domain.JavaConstructorCall)12 Set (java.util.Set)12 Application (org.archifacts.core.model.Application)12 Component (com.structurizr.model.Component)10 Container (com.structurizr.model.Container)10 ArtifactContainer (org.archifacts.core.model.ArtifactContainer)10