use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_multiple_own_accesses.
@Test
public void imports_multiple_own_accesses() {
JavaClass classWithOwnFieldAccess = new ClassFileImporter().importUrl(getClass().getResource("testexamples/fieldaccessimport")).get(OwnFieldAccess.class);
Set<JavaFieldAccess> fieldAccesses = classWithOwnFieldAccess.getFieldAccessesFromSelf();
assertThat(fieldAccesses).hasSize(4);
assertThat(getOnly(fieldAccesses, "stringValue", GET).getLineNumber()).as("Line number of get stringValue").isEqualTo(8);
assertThat(getOnly(fieldAccesses, "stringValue", SET).getLineNumber()).as("Line number of set stringValue").isEqualTo(12);
assertThat(getOnly(fieldAccesses, "intValue", GET).getLineNumber()).as("Line number of get intValue").isEqualTo(16);
assertThat(getOnly(fieldAccesses, "intValue", SET).getLineNumber()).as("Line number of set intValue").isEqualTo(20);
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_own_get_field_access.
@Test
public void imports_own_get_field_access() {
JavaClass classWithOwnFieldAccess = new ClassFileImporter().importUrl(getClass().getResource("testexamples/fieldaccessimport")).get(OwnFieldAccess.class);
JavaMethod getStringValue = classWithOwnFieldAccess.getMethod("getStringValue");
JavaFieldAccess access = getOnlyElement(getStringValue.getFieldAccesses());
assertThatAccess(access).isOfType(GET).isFrom(getStringValue).isTo("stringValue").inLineNumber(8);
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_other_field_accesses_from_constructor.
@Test
public void imports_other_field_accesses_from_constructor() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/fieldaccessimport"));
JavaClass classWithOwnFieldAccess = classes.get(OwnFieldAccess.class);
JavaClass fieldAccessFromConstructor = classes.get(ForeignFieldAccessFromConstructor.class);
Set<JavaFieldAccess> accesses = fieldAccessFromConstructor.getFieldAccessesFromSelf();
assertThat(accesses).as("Number of field accesses from " + fieldAccessFromConstructor.getName()).hasSize(2);
assertThatAccess(getOnly(accesses, "stringValue", GET)).isFrom(fieldAccessFromConstructor.getCodeUnitWithParameterTypes(CONSTRUCTOR_NAME)).isTo(classWithOwnFieldAccess.getField("stringValue")).inLineNumber(5);
assertThatAccess(getOnly(accesses, "intValue", SET)).isFrom(fieldAccessFromConstructor.getCodeUnitWithParameterTypes(CONSTRUCTOR_NAME)).isTo(classWithOwnFieldAccess.getField("intValue")).inLineNumber(6);
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_other_field_accesses.
@Test
public void imports_other_field_accesses() {
JavaClasses classes = new ClassFileImporter().importUrl(getClass().getResource("testexamples/fieldaccessimport"));
JavaClass classWithOwnFieldAccess = classes.get(OwnFieldAccess.class);
JavaClass classWithForeignFieldAccess = classes.get(ForeignFieldAccess.class);
Set<JavaFieldAccess> accesses = classWithForeignFieldAccess.getFieldAccessesFromSelf();
assertThat(accesses).hasSize(4);
assertThatAccess(getOnly(accesses, "stringValue", GET)).isFrom(classWithForeignFieldAccess.getCodeUnitWithParameterTypes("getStringFromOther")).isTo(classWithOwnFieldAccess.getField("stringValue")).inLineNumber(5);
assertThatAccess(getOnly(accesses, "stringValue", SET)).isFrom(classWithForeignFieldAccess.getCodeUnitWithParameterTypes("setStringFromOther")).isTo(classWithOwnFieldAccess.getField("stringValue")).inLineNumber(9);
assertThatAccess(getOnly(accesses, "intValue", GET)).isFrom(classWithForeignFieldAccess.getCodeUnitWithParameterTypes("getIntFromOther")).isTo(classWithOwnFieldAccess.getField("intValue")).inLineNumber(13);
assertThatAccess(getOnly(accesses, "intValue", SET)).isFrom(classWithForeignFieldAccess.getCodeUnitWithParameterTypes("setIntFromOther")).isTo(classWithOwnFieldAccess.getField("intValue")).inLineNumber(17);
}
use of com.tngtech.archunit.core.domain.JavaFieldAccess in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_own_set_field_access.
@Test
public void imports_own_set_field_access() {
JavaClass classWithOwnFieldAccess = new ClassFileImporter().importUrl(getClass().getResource("testexamples/fieldaccessimport")).get(OwnFieldAccess.class);
JavaMethod setStringValue = classWithOwnFieldAccess.getMethod("setStringValue", String.class);
JavaFieldAccess access = getOnlyElement(setStringValue.getFieldAccesses());
assertThatAccess(access).isOfType(SET).isFrom(setStringValue).isTo(classWithOwnFieldAccess.getField("stringValue")).inLineNumber(12);
}
Aggregations