use of com.tngtech.archunit.lang.ConditionEvent in project arch-unit-build-plugin-core by societe-generale.
the class NoTestIgnoreRuleTest method notBeenIgnore.
public static ArchCondition<JavaClass> notBeenIgnore() {
return new ArchCondition<JavaClass>(NO_JUNIT_IGNORE_VIOLATION_MESSAGE) {
@Override
@SuppressWarnings("squid:S1166")
public void check(JavaClass item, ConditionEvents events) {
// class level checks
String violationMessageAtClassLevel = item.getName() + ", at class level";
// class level checks
addViolationEvent(buildViolationIfAnnotationWithNoValueFound(item, Ignore.class, violationMessageAtClassLevel), events);
addViolationEvent(buildViolationIfAnnotationWithNoValueFound(item, Disabled.class, violationMessageAtClassLevel), events);
// method level checks
for (JavaMethod method : item.getMethods()) {
String violationMessageAtMethodLevel = item.getName() + " - " + method.getName() + ", at method level";
addViolationEvent(buildViolationIfAnnotationWithNoValueFound(method, Ignore.class, violationMessageAtMethodLevel), events);
addViolationEvent(buildViolationIfAnnotationWithNoValueFound(method, Disabled.class, violationMessageAtMethodLevel), events);
}
}
private void addViolationEvent(Optional<ConditionEvent> violation, ConditionEvents events) {
if (violation.isPresent()) {
events.add(violation.get());
}
}
private Optional<ConditionEvent> buildViolationIfAnnotationWithNoValueFound(HasAnnotations item, Class annotation, String violationMessage) {
try {
if (item.getAnnotationOfType(annotation) != null) {
return Optional.of(SimpleConditionEvent.violated(item, violationMessage));
}
} catch (IllegalArgumentException e) {
// if there's no Ignore annotation, IllegalArgument exception is thrown.
// we swallow it, as it means there's no annotation at class level.
}
return Optional.empty();
}
};
}
use of com.tngtech.archunit.lang.ConditionEvent in project gradle by gradle.
the class ArchUnitFixtureTest method array_types_are_allowed.
@Test
public void array_types_are_allowed() {
ConditionEvent event = checkThatHasOnlyAllowedTypes("validArrayTypeParameterInReturnType");
assertNoViolation(event);
}
use of com.tngtech.archunit.lang.ConditionEvent in project gradle by gradle.
the class ArchUnitFixtureTest method reports_invalid_generic_type_of_parameter.
@Test
public void reports_invalid_generic_type_of_parameter() {
ConditionEvent event = checkThatMethodHasOnlyAllowedArgumentTypesOrReturnTypes("invalidTypeParameterInParameterType", String.class, List.class);
// TODO: Should detect the violation
Assertions.assertThrows(AssertionError.class, () -> assertHasViolation(event, File.class));
}
use of com.tngtech.archunit.lang.ConditionEvent in project gradle by gradle.
the class ArchUnitFixtureTest method reports_invalid_array_types_return_type.
@Test
public void reports_invalid_array_types_return_type() {
ConditionEvent event = checkThatHasOnlyAllowedTypes("invalidArrayTypeParameterInReturnType");
assertHasViolation(event, File[].class);
}
use of com.tngtech.archunit.lang.ConditionEvent in project gradle by gradle.
the class ArchUnitFixtureTest method reports_invalid_parameter_types.
@Test
public void reports_invalid_parameter_types() {
ConditionEvent event = checkThatMethodHasOnlyAllowedArgumentTypesOrReturnTypes("invalidParameterType", String.class, File.class);
assertHasViolation(event, File.class);
}
Aggregations