use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterTest method imports_simple_local_class.
@Test
public void imports_simple_local_class() throws Exception {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/innerclassimport"));
JavaClass localClass = classes.get(ClassWithInnerClass.class.getName() + "$1LocalCaller");
assertThat(localClass).matches(Class.forName(localClass.getName())).isTopLevelClass(false).isNestedClass(true).isMemberClass(false).isInnerClass(true).isLocalClass(true).isAnonymousClass(false).isRecord(false);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterTest method imports_interfaces_and_classes.
@Test
public void imports_interfaces_and_classes() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/classhierarchyimport"));
JavaClass baseClass = classes.get(BaseClass.class);
JavaClass parentInterface = classes.get(ParentInterface.class);
assertThat(baseClass).isInterface(false);
assertThat(parentInterface).isInterface(true);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterTest method imports_interfaces.
@Test
public void imports_interfaces() {
JavaClass simpleInterface = new ClassFileImporter().importUrl(getClass().getResource("testexamples/simpleimport")).get(InterfaceToImport.class);
assertThat(simpleInterface).matches(InterfaceToImport.class).hasNoSuperclass().hasNoInterfaces().isInterface(true).isEnum(false).isRecord(false);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterTest method creates_relations_between_classes_and_interfaces.
@Test
public void creates_relations_between_classes_and_interfaces() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/classhierarchyimport"));
JavaClass baseClass = classes.get(BaseClass.class);
JavaClass otherInterface = classes.get(OtherInterface.class);
JavaClass subclass = classes.get(Subclass.class);
JavaClass subinterface = classes.get(Subinterface.class);
JavaClass otherSubclass = classes.get(OtherSubclass.class);
JavaClass parentInterface = classes.get(ParentInterface.class);
JavaClass grandParentInterface = classes.get(GrandParentInterface.class);
JavaClass someCollection = classes.get(SomeCollection.class);
JavaClass collectionInterface = classes.get(CollectionInterface.class);
assertThat(baseClass.getRawInterfaces()).containsOnly(otherInterface);
assertThat(baseClass.getAllRawInterfaces()).containsOnly(otherInterface, grandParentInterface);
assertThat(subclass.getRawInterfaces()).containsOnly(subinterface);
assertThat(subclass.getAllRawInterfaces()).containsOnly(subinterface, otherInterface, parentInterface, grandParentInterface);
assertThat(otherSubclass.getRawInterfaces()).containsOnly(parentInterface);
assertThat(otherSubclass.getAllRawInterfaces()).containsOnly(parentInterface, grandParentInterface, otherInterface);
assertThat(someCollection.getRawInterfaces()).containsOnly(collectionInterface, otherInterface, subinterface);
assertThat(someCollection.getAllRawInterfaces()).extractingResultOf("reflect").containsOnly(CollectionInterface.class, OtherInterface.class, Subinterface.class, ParentInterface.class, GrandParentInterface.class, Collection.class, Iterable.class);
}
use of com.tngtech.archunit.core.domain.JavaClass in project ArchUnit by TNG.
the class ClassFileImporterTest method adds_package_of_component_type_to_arrays.
// we want to diverge from the Reflection API in this place, because it is way more useful for dependency checks,
// if com.some.SomeArray[].getPackageName() reports 'com.some' instead of '' (which would be ArchUnit's equivalent of null)
@Test
@UseDataProvider("array_types")
public void adds_package_of_component_type_to_arrays(Class<?> classAccessingArray) {
JavaClass javaClass = new ClassFileImporter().importPackagesOf(classAccessingArray).get(classAccessingArray);
JavaClass arrayType = getOnlyElement(javaClass.getFieldAccessesFromSelf()).getTarget().getRawType();
assertThat(arrayType.getPackageName()).isEqualTo(ClassUsedInArray.class.getPackage().getName());
assertThat(arrayType.getPackage().getName()).isEqualTo(ClassUsedInArray.class.getPackage().getName());
}
Aggregations