Search in sources :

Example 86 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterTest method imports_simple_static_nested_class.

@Test
@UseDataProvider("nested_static_classes")
public void imports_simple_static_nested_class(Class<?> nestedStaticClass) {
    JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/innerclassimport"));
    assertThat(classes.get(nestedStaticClass)).matches(nestedStaticClass).isTopLevelClass(false).isNestedClass(true).isMemberClass(true).isInnerClass(false).isLocalClass(false).isAnonymousClass(false).isRecord(false);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test) UseDataProvider(com.tngtech.java.junit.dataprovider.UseDataProvider)

Example 87 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterTest method imports_simple_class_names_of_generated_types_correctly.

@Test
public void imports_simple_class_names_of_generated_types_correctly() throws Exception {
    JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/simplenames"));
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.class);
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.Crazy$InnerClass$$LikeAByteCodeGenerator_might_create.class);
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.class.getName() + "$1");
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.class.getName() + "$1Crazy$LocalClass");
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.Crazy$InnerClass$$LikeAByteCodeGenerator_might_create.NestedInnerClass$Also$$_crazy.class);
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.Crazy$InnerClass$$LikeAByteCodeGenerator_might_create.class.getName() + "$1");
    assertSameSimpleNameOfArchUnitAndReflection(classes, SimpleNameExamples.Crazy$InnerClass$$LikeAByteCodeGenerator_might_create.class.getName() + "$1Crazy$$NestedLocalClass");
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) SimpleNameExamples(com.tngtech.archunit.core.importer.testexamples.simplenames.SimpleNameExamples) Test(org.junit.Test)

Example 88 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterTest method imports_generic_interfaces_in_correct_order.

@Test
public void imports_generic_interfaces_in_correct_order() {
    class Ascending implements OneGeneric<String>, TwoGeneric<String>, ThreeGeneric<String>, FourGeneric<String>, FiveGeneric<String> {
    }
    class Descending implements FiveGeneric<String>, FourGeneric<String>, ThreeGeneric<String>, TwoGeneric<String>, OneGeneric<String> {
    }
    JavaClasses classes = new ClassFileImporter().importClasses(Ascending.class, Descending.class);
    assertThatTypes(classes.get(Ascending.class).getInterfaces()).matchExactly(parameterizedType(OneGeneric.class).withTypeArguments(String.class), parameterizedType(TwoGeneric.class).withTypeArguments(String.class), parameterizedType(ThreeGeneric.class).withTypeArguments(String.class), parameterizedType(FourGeneric.class).withTypeArguments(String.class), parameterizedType(FiveGeneric.class).withTypeArguments(String.class));
    assertThatTypes(classes.get(Descending.class).getInterfaces()).matchExactly(parameterizedType(FiveGeneric.class).withTypeArguments(String.class), parameterizedType(FourGeneric.class).withTypeArguments(String.class), parameterizedType(ThreeGeneric.class).withTypeArguments(String.class), parameterizedType(TwoGeneric.class).withTypeArguments(String.class), parameterizedType(OneGeneric.class).withTypeArguments(String.class));
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ThreeGeneric(com.tngtech.archunit.core.importer.testexamples.interfaceorder.ThreeGeneric) TwoGeneric(com.tngtech.archunit.core.importer.testexamples.interfaceorder.TwoGeneric) OneGeneric(com.tngtech.archunit.core.importer.testexamples.interfaceorder.OneGeneric) FourGeneric(com.tngtech.archunit.core.importer.testexamples.interfaceorder.FourGeneric) FiveGeneric(com.tngtech.archunit.core.importer.testexamples.interfaceorder.FiveGeneric) Test(org.junit.Test)

Example 89 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterTest method imports_packages_even_if_jar_entry_for_package_is_missing.

/**
 * Compare {@link LocationsTest#locations_of_packages_within_JAR_URIs_that_do_not_contain_package_folder()}
 */
@Test
public void imports_packages_even_if_jar_entry_for_package_is_missing() {
    String packageToImport = independentClasspathRule.getIndependentTopLevelPackage();
    ClassFileImporter classFileImporter = new ClassFileImporter();
    JavaClasses classes = classFileImporter.importPackages(packageToImport);
    assertThat(classes).extracting("name").doesNotContain(independentClasspathRule.getNameOfSomeContainedClass());
    independentClasspathRule.configureClasspath();
    classes = classFileImporter.importUrl(independentClasspathRule.getOnlyUrl());
    assertThat(classes).extracting("name").containsAll(independentClasspathRule.getNamesOfClasses());
    assertThat(classes).extracting("packageName").containsAll(independentClasspathRule.getPackagesOfClasses());
    classes = classFileImporter.importPackages(packageToImport);
    assertThat(classes).extracting("name").contains(independentClasspathRule.getNameOfSomeContainedClass());
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) Test(org.junit.Test)

Example 90 with JavaClasses

use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.

the class ClassFileImporterTest method handles_static_modifier_of_nested_classes.

@Test
public void handles_static_modifier_of_nested_classes() {
    JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/nestedimport"));
    assertThat(classes.get(ClassWithNestedClass.class).getModifiers()).as("modifiers of ClassWithNestedClass").doesNotContain(STATIC);
    assertThat(classes.get(ClassWithNestedClass.NestedClass.class).getModifiers()).as("modifiers of ClassWithNestedClass.NestedClass").doesNotContain(STATIC);
    assertThat(classes.get(ClassWithNestedClass.StaticNestedClass.class).getModifiers()).as("modifiers of ClassWithNestedClass.StaticNestedClass").contains(STATIC);
    assertThat(classes.get(ClassWithNestedClass.NestedInterface.class).getModifiers()).as("modifiers of ClassWithNestedClass.NestedInterface").contains(STATIC);
    assertThat(classes.get(ClassWithNestedClass.StaticNestedInterface.class).getModifiers()).as("modifiers of ClassWithNestedClass.StaticNestedInterface").contains(STATIC);
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) ClassWithNestedClass(com.tngtech.archunit.core.importer.testexamples.nestedimport.ClassWithNestedClass) Test(org.junit.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