use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method imports_members_with_sourceCodeLocation.
@Test
public void imports_members_with_sourceCodeLocation() {
JavaClasses importedClasses = new ClassFileImporter().importUrl(getClass().getResource("testexamples/methodimport"));
String sourceFileName = "ClassWithMultipleMethods.java";
JavaClass javaClass = importedClasses.get(ClassWithMultipleMethods.class);
assertThat(javaClass.getField("usage").getSourceCodeLocation()).hasToString(// the byte code has no line number associated with a field
"(" + sourceFileName + ":0)");
assertThat(javaClass.getConstructor().getSourceCodeLocation()).hasToString(// auto-generated constructor seems to get line of class definition
"(" + sourceFileName + ":4)");
assertThat(javaClass.getStaticInitializer().get().getSourceCodeLocation()).hasToString(// auto-generated static initializer seems to get line of first static variable definition
"(" + sourceFileName + ":5)");
assertThat(javaClass.getMethod("methodDefinedInLine7").getSourceCodeLocation()).hasToString("(" + sourceFileName + ":7)");
assertThat(javaClass.getMethod("methodWithBodyStartingInLine10").getSourceCodeLocation()).hasToString("(" + sourceFileName + ":10)");
assertThat(javaClass.getMethod("emptyMethodDefinedInLine15").getSourceCodeLocation()).hasToString("(" + sourceFileName + ":15)");
assertThat(javaClass.getMethod("emptyMethodEndingInLine19").getSourceCodeLocation()).hasToString("(" + sourceFileName + ":19)");
javaClass = importedClasses.get(ClassWithMultipleMethods.InnerClass.class);
assertThat(javaClass.getMethod("methodWithBodyStartingInLine24").getSourceCodeLocation()).hasToString("(" + sourceFileName + ":24)");
javaClass = importedClasses.get(ClassWithMultipleMethods.InnerClass.class.getName() + "$1");
assertThat(javaClass.getMethod("run").getSourceCodeLocation()).hasToString("(" + sourceFileName + ":27)");
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method imports_overridden_methods_correctly.
@Test
public void imports_overridden_methods_correctly() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/classhierarchyimport"));
JavaClass baseClass = classes.get(BaseClass.class);
JavaClass subClass = classes.get(Subclass.class);
assertThat(baseClass.getCodeUnitWithParameterTypes("getSomeField").getModifiers()).containsOnly(PROTECTED);
assertThat(subClass.getCodeUnitWithParameterTypes("getSomeField").getModifiers()).containsOnly(PUBLIC);
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method classes_know_which_methods_have_their_type_as_parameter.
@Test
public void classes_know_which_methods_have_their_type_as_parameter() {
JavaClasses classes = new ClassFileImporter().importClasses(SomeClass.class, OtherClass.class, SomeEnum.class);
assertThat(classes.get(SomeEnum.class).getMethodsWithParameterTypeOfSelf()).extracting("name").contains("methodWithSomeEnumParameter", "otherMethodWithSomeEnumParameter");
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method classes_know_which_methods_have_their_type_as_return_type.
@Test
public void classes_know_which_methods_have_their_type_as_return_type() {
JavaClasses classes = new ClassFileImporter().importClasses(SomeClass.class, OtherClass.class, SomeEnum.class);
assertThat(classes.get(SomeEnum.class).getMethodsWithReturnTypeOfSelf()).extracting("name").contains("methodWithSomeEnumReturnType", "otherMethodWithSomeEnumReturnType");
}
use of com.tngtech.archunit.core.domain.JavaClasses in project ArchUnit by TNG.
the class ClassFileImporterMembersTest method classes_know_which_fields_have_their_type.
@Test
public void classes_know_which_fields_have_their_type() {
JavaClasses classes = new ClassFileImporter().importClasses(SomeClass.class, OtherClass.class, SomeEnum.class);
assertThat(classes.get(SomeEnum.class).getFieldsWithTypeOfSelf()).extracting("name").contains("other", "someEnum");
}
Aggregations