Search in sources :

Example 61 with ClassFileImporter

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

the class DependencyTest method Dependencies_from_field_with_component_type.

@Test
@UseDataProvider("field_array_types")
public void Dependencies_from_field_with_component_type(Field reflectionArrayField) {
    Class<?> reflectionDeclaringClass = reflectionArrayField.getDeclaringClass();
    JavaField field = new ClassFileImporter().importClasses(reflectionDeclaringClass).get(reflectionDeclaringClass).getField(reflectionArrayField.getName());
    Set<Dependency> dependencies = Dependency.tryCreateFromField(field);
    DependenciesAssertion.ExpectedDependencies expectedDependencies = from(reflectionDeclaringClass).to(reflectionArrayField.getType()).withDescriptionContaining("Field <%s> has type <%s>", field.getFullName(), reflectionArrayField.getType().getName()).inLocation(DependencyTest.class, 0);
    Class<?> expectedComponentType = reflectionArrayField.getType().getComponentType();
    while (expectedComponentType != null) {
        expectedDependencies.from(reflectionDeclaringClass).to(expectedComponentType).withDescriptionContaining("Field <%s> depends on component type <%s>", field.getFullName(), expectedComponentType.getName()).inLocation(DependencyTest.class, 0);
        expectedComponentType = expectedComponentType.getComponentType();
    }
    assertThatDependencies(dependencies).containOnly(expectedDependencies);
}
Also used : DependenciesAssertion(com.tngtech.archunit.testutil.assertion.DependenciesAssertion) ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 62 with ClassFileImporter

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

the class JavaTypeVariableTest method erased_type_variable_bound_by_single_class_is_this_class.

@Test
public void erased_type_variable_bound_by_single_class_is_this_class() {
    @SuppressWarnings("unused")
    class ClassWithBoundTypeParameterWithSingleClassBound<T extends Serializable> {
    }
    JavaTypeVariable<JavaClass> type = new ClassFileImporter().importClass(ClassWithBoundTypeParameterWithSingleClassBound.class).getTypeParameters().get(0);
    assertThatType(type.toErasure()).matches(Serializable.class);
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 63 with ClassFileImporter

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

the class JavaTypeVariableTest method toString_upper_bounded_by_single_bound.

@Test
public void toString_upper_bounded_by_single_bound() {
    @SuppressWarnings("unused")
    class BoundedBySingleBound<NAME extends String> {
    }
    JavaTypeVariable<JavaClass> typeVariable = new ClassFileImporter().importClass(BoundedBySingleBound.class).getTypeParameters().get(0);
    assertThat(typeVariable.toString()).contains(JavaTypeVariable.class.getSimpleName()).contains("NAME extends java.lang.String");
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 64 with ClassFileImporter

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

the class JavaTypeVariableTest method toString_upper_bounded_by_multiple_bounds.

@Test
public void toString_upper_bounded_by_multiple_bounds() {
    @SuppressWarnings("unused")
    class BoundedByMultipleBounds<NAME extends String & Serializable> {
    }
    JavaTypeVariable<JavaClass> typeVariable = new ClassFileImporter().importClass(BoundedByMultipleBounds.class).getTypeParameters().get(0);
    assertThat(typeVariable.toString()).contains(JavaTypeVariable.class.getSimpleName()).contains("NAME extends java.lang.String & java.io.Serializable");
}
Also used : ClassFileImporter(com.tngtech.archunit.core.importer.ClassFileImporter) Test(org.junit.Test)

Example 65 with ClassFileImporter

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

the class JavaTypeVariableTest method type_variable_upper_bounds.

@Test
public void type_variable_upper_bounds() {
    @SuppressWarnings("unused")
    class ClassWithUnboundTypeParameter<T extends HashMap<Object, Object> & Serializable> {
    }
    JavaTypeVariable<JavaClass> type = new ClassFileImporter().importClass(ClassWithUnboundTypeParameter.class).getTypeParameters().get(0);
    assertThatTypeErasuresOf(type.getBounds()).matchExactly(HashMap.class, Serializable.class);
    assertThatTypeErasuresOf(type.getUpperBounds()).matchExactly(HashMap.class, Serializable.class);
}
Also used : 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