use of com.tngtech.archunit.core.domain.JavaClasses 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.JavaClasses 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.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterTest method creates_JavaPackages_for_each_JavaClass.
@Test
public void creates_JavaPackages_for_each_JavaClass() {
JavaClasses classes = new ClassFileImporter().importPackagesOf(getClass());
JavaPackage javaPackage = classes.get(SomeClass.class).getPackage();
assertThat(javaPackage.containsClass(SomeEnum.class)).as("Package contains " + SomeEnum.class).isTrue();
assertThatTypes(javaPackage.getParent().get().getClasses()).contain(getClass());
}
use of com.tngtech.archunit.core.domain.JavaClasses 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.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterTest method import_is_resilient_against_broken_class_files.
@Test
public void import_is_resilient_against_broken_class_files() throws Exception {
Class<?> expectedClass = getClass();
File folder = temporaryFolder.newFolder();
copyClassFile(expectedClass, folder);
Files.write(new File(folder, "Evil.class").toPath(), "broken".getBytes(UTF_8));
logTest.watch(ClassFileProcessor.class, Level.WARN);
JavaClasses classes = new ClassFileImporter().importPath(folder.toPath());
assertThatTypes(classes).matchExactly(expectedClass);
logTest.assertLogMessage(Level.WARN, "Evil.class");
}
Aggregations