use of com.tngtech.archunit.core.importer.testexamples.constructorimport.ClassWithSimpleConstructors in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method imports_simple_constructors_with_correct_parameters.
@Test
public void imports_simple_constructors_with_correct_parameters() throws Exception {
JavaClass clazz = new ClassFileImporter().importUrl(getClass().getResource("testexamples/constructorimport")).get(ClassWithSimpleConstructors.class);
assertThat(clazz.getConstructors()).as("Constructors").hasSize(3);
Constructor<ClassWithSimpleConstructors> expectedConstructor = ClassWithSimpleConstructors.class.getDeclaredConstructor();
assertThat(clazz.getConstructor()).isEquivalentTo(expectedConstructor);
assertThat(clazz.tryGetConstructor().get()).isEquivalentTo(expectedConstructor);
Class<?>[] parameterTypes = { Object.class };
expectedConstructor = ClassWithSimpleConstructors.class.getDeclaredConstructor(parameterTypes);
assertThat(clazz.getConstructor(parameterTypes)).isEquivalentTo(expectedConstructor);
assertThat(clazz.getConstructor(Objects.namesOf(parameterTypes))).isEquivalentTo(expectedConstructor);
assertThat(clazz.tryGetConstructor(parameterTypes).get()).isEquivalentTo(expectedConstructor);
assertThat(clazz.tryGetConstructor(Objects.namesOf(parameterTypes)).get()).isEquivalentTo(expectedConstructor);
parameterTypes = new Class[] { int.class, int.class };
expectedConstructor = ClassWithSimpleConstructors.class.getDeclaredConstructor(parameterTypes);
assertThat(clazz.getConstructor(parameterTypes)).isEquivalentTo(expectedConstructor);
assertThat(clazz.getConstructor(Objects.namesOf(parameterTypes))).isEquivalentTo(expectedConstructor);
assertThat(clazz.tryGetConstructor(parameterTypes).get()).isEquivalentTo(expectedConstructor);
assertThat(clazz.tryGetConstructor(Objects.namesOf(parameterTypes)).get()).isEquivalentTo(expectedConstructor);
}
Aggregations