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);
}
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");
}
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));
}
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());
}
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);
}
Aggregations