Search in sources :

Example 1 with ClassWithSimpleConstructors

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);
}
Also used : JavaClass(com.tngtech.archunit.core.domain.JavaClass) ClassWithSimpleConstructors(com.tngtech.archunit.core.importer.testexamples.constructorimport.ClassWithSimpleConstructors) OtherClass(com.tngtech.archunit.core.importer.testexamples.OtherClass) JavaClass(com.tngtech.archunit.core.domain.JavaClass) SomeClass(com.tngtech.archunit.core.importer.testexamples.SomeClass) BaseClass(com.tngtech.archunit.core.importer.testexamples.classhierarchyimport.BaseClass) Test(org.junit.Test)

Aggregations

JavaClass (com.tngtech.archunit.core.domain.JavaClass)1 OtherClass (com.tngtech.archunit.core.importer.testexamples.OtherClass)1 SomeClass (com.tngtech.archunit.core.importer.testexamples.SomeClass)1 BaseClass (com.tngtech.archunit.core.importer.testexamples.classhierarchyimport.BaseClass)1 ClassWithSimpleConstructors (com.tngtech.archunit.core.importer.testexamples.constructorimport.ClassWithSimpleConstructors)1 Test (org.junit.Test)1