Search in sources :

Example 51 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class JavaClassTest method predicate_containAnyCodeUnitsThat.

@Test
public void predicate_containAnyCodeUnitsThat() {
    @SuppressWarnings("unused")
    class Match {

        void right() {
        }
    }
    @SuppressWarnings("unused")
    class Mismatch {

        void wrong() {
        }
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
    assertThat(containAnyCodeUnitsThat(name("right"))).hasDescription("contain any code units that name 'right'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 52 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class JavaClassTest method predicate_containAnyFieldsThat.

@Test
public void predicate_containAnyFieldsThat() {
    @SuppressWarnings("unused")
    class Match {

        String right;
    }
    @SuppressWarnings("unused")
    class Mismatch {

        String wrong;
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
    assertThat(containAnyFieldsThat(name("right"))).hasDescription("contain any fields that name 'right'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 53 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class JavaClassTest method predicate_belong_to.

@Test
public void predicate_belong_to() {
    JavaClasses classes = new ClassFileImporter().importPackagesOf(getClass());
    JavaClass outerAnonymous = getOnlyClassSettingField(classes, ClassWithNamedAndAnonymousInnerClasses.name_of_fieldIndicatingOuterAnonymousInnerClass);
    JavaClass nestedAnonymous = getOnlyClassSettingField(classes, ClassWithNamedAndAnonymousInnerClasses.name_of_fieldIndicatingNestedAnonymousInnerClass);
    assertThat(belongToAnyOf(Object.class, ClassWithNamedAndAnonymousInnerClasses.class)).hasDescription(String.format("belong to any of [%s, %s]", Object.class.getName(), ClassWithNamedAndAnonymousInnerClasses.class.getName())).accepts(classes.get(ClassWithNamedAndAnonymousInnerClasses.class)).accepts(classes.get(ClassWithNamedAndAnonymousInnerClasses.NamedInnerClass.class)).accepts(classes.get(ClassWithNamedAndAnonymousInnerClasses.NamedInnerClass.NestedNamedInnerClass.class)).accepts(outerAnonymous).accepts(nestedAnonymous).rejects(classes.get(getClass()));
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 54 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class JavaClassTest method predicate_containAnyStaticInitializersThat.

@Test
public void predicate_containAnyStaticInitializersThat() {
    @SuppressWarnings("unused")
    class Mismatch {
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Data_of_predicate_containAnyStaticInitializersThat.Match.class, Mismatch.class);
    assertThat(containAnyStaticInitializersThat(DescribedPredicate.<JavaMember>alwaysTrue())).hasDescription("contain any static initializers that always true").accepts(classes.get(Data_of_predicate_containAnyStaticInitializersThat.Match.class)).rejects(classes.get(Mismatch.class));
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 55 with ClassFileImporter

use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.

the class JavaClassTest method predicate_containAnyConstructorsThat.

@Test
public void predicate_containAnyConstructorsThat() {
    @SuppressWarnings("unused")
    class Match {

        Match(Serializable param) {
        }
    }
    @SuppressWarnings("unused")
    class Mismatch {

        Mismatch(String param) {
        }
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Match.class, Mismatch.class);
    String regex = ".*" + Serializable.class.getSimpleName() + ".*";
    assertThat(containAnyConstructorsThat(fullNameMatching(regex))).hasDescription("contain any constructors that full name matching '" + regex + "'").accepts(classes.get(Match.class)).rejects(classes.get(Mismatch.class));
}
Also used : Serializable(java.io.Serializable) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.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