use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class DependencyTest method Dependencies_from_field_with_component_type.
@Test
@UseDataProvider("field_array_types")
public void Dependencies_from_field_with_component_type(Field reflectionArrayField) {
Class<?> reflectionDeclaringClass = reflectionArrayField.getDeclaringClass();
JavaField field = new ClassFileImporter().importClasses(reflectionDeclaringClass).get(reflectionDeclaringClass).getField(reflectionArrayField.getName());
Set<Dependency> dependencies = Dependency.tryCreateFromField(field);
DependenciesAssertion.ExpectedDependencies expectedDependencies = from(reflectionDeclaringClass).to(reflectionArrayField.getType()).withDescriptionContaining("Field <%s> has type <%s>", field.getFullName(), reflectionArrayField.getType().getName()).inLocation(DependencyTest.class, 0);
Class<?> expectedComponentType = reflectionArrayField.getType().getComponentType();
while (expectedComponentType != null) {
expectedDependencies.from(reflectionDeclaringClass).to(expectedComponentType).withDescriptionContaining("Field <%s> depends on component type <%s>", field.getFullName(), expectedComponentType.getName()).inLocation(DependencyTest.class, 0);
expectedComponentType = expectedComponentType.getComponentType();
}
assertThatDependencies(dependencies).containOnly(expectedDependencies);
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaTypeVariableTest method erased_type_variable_bound_by_single_class_is_this_class.
@Test
public void erased_type_variable_bound_by_single_class_is_this_class() {
@SuppressWarnings("unused")
class ClassWithBoundTypeParameterWithSingleClassBound<T extends Serializable> {
}
JavaTypeVariable<JavaClass> type = new ClassFileImporter().importClass(ClassWithBoundTypeParameterWithSingleClassBound.class).getTypeParameters().get(0);
assertThatType(type.toErasure()).matches(Serializable.class);
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaTypeVariableTest method toString_upper_bounded_by_single_bound.
@Test
public void toString_upper_bounded_by_single_bound() {
@SuppressWarnings("unused")
class BoundedBySingleBound<NAME extends String> {
}
JavaTypeVariable<JavaClass> typeVariable = new ClassFileImporter().importClass(BoundedBySingleBound.class).getTypeParameters().get(0);
assertThat(typeVariable.toString()).contains(JavaTypeVariable.class.getSimpleName()).contains("NAME extends java.lang.String");
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaTypeVariableTest method toString_upper_bounded_by_multiple_bounds.
@Test
public void toString_upper_bounded_by_multiple_bounds() {
@SuppressWarnings("unused")
class BoundedByMultipleBounds<NAME extends String & Serializable> {
}
JavaTypeVariable<JavaClass> typeVariable = new ClassFileImporter().importClass(BoundedByMultipleBounds.class).getTypeParameters().get(0);
assertThat(typeVariable.toString()).contains(JavaTypeVariable.class.getSimpleName()).contains("NAME extends java.lang.String & java.io.Serializable");
}
use of com.tngtech.archunit.core.importer.ClassFileImporter in project ArchUnit by TNG.
the class JavaTypeVariableTest method type_variable_upper_bounds.
@Test
public void type_variable_upper_bounds() {
@SuppressWarnings("unused")
class ClassWithUnboundTypeParameter<T extends HashMap<Object, Object> & Serializable> {
}
JavaTypeVariable<JavaClass> type = new ClassFileImporter().importClass(ClassWithUnboundTypeParameter.class).getTypeParameters().get(0);
assertThatTypeErasuresOf(type.getBounds()).matchExactly(HashMap.class, Serializable.class);
assertThatTypeErasuresOf(type.getUpperBounds()).matchExactly(HashMap.class, Serializable.class);
}
Aggregations