use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class ClassFileImporterCodeUnitReferencesTest method creates_correct_description_for_references.
@Test
public void creates_correct_description_for_references() {
JavaClasses javaClasses = new ClassFileImporter().importClasses(Origin.class, Target.class);
JavaClass originClass = javaClasses.get(Origin.class);
JavaClass targetClass = javaClasses.get(Target.class);
JavaMethod constructorReferenceOrigin = originClass.getMethod("referencesConstructor");
JavaConstructor targetConstructor = targetClass.getConstructor();
JavaMethod methodReferenceOrigin = originClass.getMethod("referencesMethod");
JavaMethod targetMethod = targetClass.getMethod("call");
JavaConstructorReference constructorReference = getOnlyElement(constructorReferenceOrigin.getConstructorReferencesFromSelf());
assertThat(constructorReference.getDescription()).isEqualTo(String.format("Method <%s> references constructor <%s> in (%s.java:%d)", constructorReferenceOrigin.getFullName(), targetConstructor.getFullName(), Origin.class.getSimpleName(), 9));
JavaMethodReference methodReference = getOnlyElement(originClass.getMethod("referencesMethod").getMethodReferencesFromSelf());
assertThat(methodReference.getDescription()).isEqualTo(String.format("Method <%s> references method <%s> in (%s.java:%d)", methodReferenceOrigin.getFullName(), targetMethod.getFullName(), Origin.class.getSimpleName(), 13));
}
use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method imports_constructor_with_correct_throws_declarations.
@Test
public void imports_constructor_with_correct_throws_declarations() {
JavaClass clazz = new ClassFileImporter().importUrl(getClass().getResource("testexamples/constructorimport")).get(ClassWithThrowingConstructor.class);
JavaConstructor constructor = getOnlyElement(clazz.getConstructors());
assertThatThrowsClause(constructor.getThrowsClause()).as("Throws types of sole constructor").matches(FirstCheckedException.class, SecondCheckedException.class);
assertThatTypes(constructor.getExceptionTypes()).matchExactly(FirstCheckedException.class, SecondCheckedException.class);
}
use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class ClassFileImporterGenericCodeUnitParameterTypesTest method imports_raw_parameter_types_and_generic_parameter_types_of_inner_class_constructor_like_Reflection_API.
@Test
public void imports_raw_parameter_types_and_generic_parameter_types_of_inner_class_constructor_like_Reflection_API() {
@SuppressWarnings("unused")
class LocalClassThatWillHaveEnclosingClassAsFirstRawConstructorParameter {
public LocalClassThatWillHaveEnclosingClassAsFirstRawConstructorParameter(ClassParameterWithSingleTypeParameter<String> param) {
}
}
JavaConstructor constructor = new ClassFileImporter().importClass(LocalClassThatWillHaveEnclosingClassAsFirstRawConstructorParameter.class).getConstructor(getClass(), ClassParameterWithSingleTypeParameter.class);
assertThatTypes(constructor.getRawParameterTypes()).matchExactly(getClass(), ClassParameterWithSingleTypeParameter.class);
assertThat(constructor.getParameterTypes()).hasSize(1);
assertThatType(constructor.getParameterTypes().get(0)).matches(parameterizedType(ClassParameterWithSingleTypeParameter.class).withTypeArguments(String.class));
}
Aggregations