Search in sources :

Example 1 with ThrowsDeclaration

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

the class ClassFileImporterMembersTest method classes_know_which_method_throws_clauses_contain_their_type.

@Test
public void classes_know_which_method_throws_clauses_contain_their_type() {
    JavaClasses classes = new ClassFileImporter().importClasses(ClassWithThrowingMethod.class, FirstCheckedException.class);
    Set<ThrowsDeclaration<JavaMethod>> throwsDeclarations = classes.get(FirstCheckedException.class).getMethodThrowsDeclarationsWithTypeOfSelf();
    assertThatType(getOnlyElement(throwsDeclarations).getDeclaringClass()).matches(ClassWithThrowingMethod.class);
    assertThat(classes.get(FirstCheckedException.class).getConstructorsWithParameterTypeOfSelf()).isEmpty();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) FirstCheckedException(com.tngtech.archunit.core.importer.testexamples.FirstCheckedException) ThrowsDeclaration(com.tngtech.archunit.core.domain.ThrowsDeclaration) Test(org.junit.Test)

Example 2 with ThrowsDeclaration

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

the class ClassFileImporterMembersTest method classes_know_which_constructor_throws_clauses_contain_their_type.

@Test
public void classes_know_which_constructor_throws_clauses_contain_their_type() {
    JavaClasses classes = new ClassFileImporter().importClasses(ClassWithThrowingConstructor.class, FirstCheckedException.class);
    Set<ThrowsDeclaration<JavaConstructor>> throwsDeclarations = classes.get(FirstCheckedException.class).getConstructorsWithThrowsDeclarationTypeOfSelf();
    assertThatType(getOnlyElement(throwsDeclarations).getDeclaringClass()).matches(ClassWithThrowingConstructor.class);
    assertThat(classes.get(FirstCheckedException.class).getMethodThrowsDeclarationsWithTypeOfSelf()).isEmpty();
}
Also used : JavaClasses(com.tngtech.archunit.core.domain.JavaClasses) FirstCheckedException(com.tngtech.archunit.core.importer.testexamples.FirstCheckedException) ThrowsDeclaration(com.tngtech.archunit.core.domain.ThrowsDeclaration) Test(org.junit.Test)

Aggregations

JavaClasses (com.tngtech.archunit.core.domain.JavaClasses)2 ThrowsDeclaration (com.tngtech.archunit.core.domain.ThrowsDeclaration)2 FirstCheckedException (com.tngtech.archunit.core.importer.testexamples.FirstCheckedException)2 Test (org.junit.Test)2