use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class GivenCodeUnitsTest method types_match_for_constructors.
@Test
public void types_match_for_constructors() {
EvaluationResult result = constructors().that(new DescribedPredicate<JavaMember>("are there") {
@Override
public boolean test(JavaMember input) {
return true;
}
}).and(new DescribedPredicate<JavaConstructor>("are there") {
@Override
public boolean test(JavaConstructor input) {
return true;
}
}).should(new ArchCondition<JavaConstructor>("not exist") {
@Override
public void check(JavaConstructor constructor, ConditionEvents events) {
events.add(SimpleConditionEvent.violated(constructor, "expected violation"));
}
}).evaluate(importClasses(ClassWithVariousMembers.class));
assertThat(Joiner.on(" ").join(result.getFailureReport().getDetails())).contains("expected violation");
}
use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method imports_complex_nested_try_catch_blocks.
@Test
public void imports_complex_nested_try_catch_blocks() {
JavaClass javaClass = new ClassFileImporter().importClass(ClassWithComplexTryCatchBlocks.class);
JavaConstructor constructor = javaClass.getConstructor();
Set<TryCatchBlock> tryCatchBlocks = constructor.getTryCatchBlocks();
assertThat(tryCatchBlocks).hasSize(3).areExactly(1, tryCatchBlock().declaredIn(constructor).catching(Exception.class).atLocation(ClassWithComplexTryCatchBlocks.class, 14)).areExactly(1, tryCatchBlock().declaredIn(constructor).catching(IllegalArgumentException.class, UnsupportedOperationException.class).atLocation(ClassWithComplexTryCatchBlocks.class, 17)).areExactly(1, tryCatchBlock().declaredIn(constructor).catching(Throwable.class).atLocation(ClassWithComplexTryCatchBlocks.class, 26));
}
use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class ClassFileImporterAccessesTest method resolve.
// only temporary to make sure resolveMember() and resolve() are in sync. Inline again when we throw out resolve()
private JavaConstructor resolve(ConstructorCallTarget target) {
JavaConstructor constructor = target.resolveMember().get();
assertThat(target.resolve()).containsExactly(constructor);
return constructor;
}
use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class ClassFileImporterAnnotationsTest method imports_constructors_with_complex_annotations_correctly.
@Test
public void imports_constructors_with_complex_annotations_correctly() throws Exception {
JavaConstructor constructor = new ClassFileImporter().importPackagesOf(ClassWithAnnotatedMethods.class).get(ClassWithAnnotatedMethods.class).getConstructor();
JavaAnnotation<JavaConstructor> annotation = constructor.getAnnotationOfType(ClassWithAnnotatedMethods.MethodAnnotationWithEnumAndArrayValue.class.getName());
assertThat((Object[]) annotation.get("classes").get()).extracting("name").containsExactly(Object.class.getName(), Serializable.class.getName());
assertThat(annotation.getOwner()).isEqualTo(constructor);
JavaAnnotation<?> subAnnotation = (JavaAnnotation<?>) annotation.get("subAnnotation").get();
assertThat(subAnnotation.get("value").get()).isEqualTo("changed");
assertThat(subAnnotation.getOwner()).isEqualTo(annotation);
assertThat(subAnnotation.getAnnotatedElement()).isEqualTo(constructor);
JavaAnnotation<?>[] subAnnotationArray = (JavaAnnotation<?>[]) annotation.get("subAnnotationArray").get();
assertThat(subAnnotationArray[0].get("value").get()).isEqualTo("another");
assertThat(subAnnotationArray[0].getOwner()).isEqualTo(annotation);
assertThat(subAnnotationArray[0].getAnnotatedElement()).isEqualTo(constructor);
assertThat(constructor).isEquivalentTo(ClassWithAnnotatedMethods.class.getConstructor());
}
use of com.tngtech.archunit.core.domain.JavaConstructor in project ArchUnit by TNG.
the class CodeUnitsShouldTest method types_match_for_constructors.
@Test
public void types_match_for_constructors() {
EvaluationResult result = constructors().that().arePrivate().should(new ArchCondition<JavaMember>("exist") {
@Override
public void check(JavaMember item, ConditionEvents events) {
}
}).andShould(new ArchCondition<JavaConstructor>("not exist") {
@Override
public void check(JavaConstructor constructor, ConditionEvents events) {
events.add(SimpleConditionEvent.violated(constructor, "expected violation"));
}
}).evaluate(importClasses(ClassWithVariousMembers.class));
assertThat(Joiner.on(" ").join(result.getFailureReport().getDetails())).contains("expected violation");
}
Aggregations