use of com.tngtech.archunit.lang.ConditionEvents in project ArchUnit by TNG.
the class CodeUnitsShouldTest method types_match_for_methods.
@Test
public void types_match_for_methods() {
EvaluationResult result = methods().that().arePrivate().should(new ArchCondition<JavaMember>("exist") {
@Override
public void check(JavaMember item, ConditionEvents events) {
}
}).andShould(new ArchCondition<JavaMethod>("not exist") {
@Override
public void check(JavaMethod method, ConditionEvents events) {
events.add(SimpleConditionEvent.violated(method, "expected violation"));
}
}).evaluate(importClasses(ClassWithVariousMembers.class));
assertThat(Joiner.on(" ").join(result.getFailureReport().getDetails())).contains("expected violation");
}
use of com.tngtech.archunit.lang.ConditionEvents in project ArchUnit by TNG.
the class FieldAccessConditionTest method checkCondition.
private ConditionEvents checkCondition(FieldAccessCondition getFieldCondition, JavaFieldAccess access) {
ConditionEvents events = new ConditionEvents();
getFieldCondition.check(access, events);
return events;
}
use of com.tngtech.archunit.lang.ConditionEvents in project ArchUnit by TNG.
the class FieldAccessConditionTest method assertViolatedWithMessage.
private void assertViolatedWithMessage(FieldAccessCondition getFieldCondition, JavaFieldAccess access, String accessDescription) {
ConditionEvents events = checkCondition(getFieldCondition, access);
boolean satisfied = !events.containViolation();
assertThat(satisfied).as("Events are satisfied").isFalse();
assertThat(events.getAllowed()).isEmpty();
assertDescription(access, accessDescription, messageOf(events.getViolating()));
}
use of com.tngtech.archunit.lang.ConditionEvents in project ArchUnit by TNG.
the class NeverConditionTest method inverts_condition.
@Test
@UseDataProvider("conditions")
public void inverts_condition(ArchCondition<Object> condition) {
ConditionEvents events = new ConditionEvents();
condition.check(new Object(), events);
condition.finish(events);
assertThat(events).containAllowed(ORIGINALLY_NO_MISMATCH);
assertThat(events).containViolations(ORIGINALLY_MISMATCH);
events = new ConditionEvents();
never(condition).check(new Object(), events);
never(condition).finish(events);
assertThat(events).containAllowed(ORIGINALLY_MISMATCH);
assertThat(events).containViolations(ORIGINALLY_NO_MISMATCH);
}
use of com.tngtech.archunit.lang.ConditionEvents in project ArchUnit by TNG.
the class ClassAccessesFieldConditionTest method condition_works.
@Theory
public void condition_works(NegativeTestCase testCase) {
ConditionEvents events = new ConditionEvents();
testCase.condition.check(CALLER_CLASS, events);
assertThat(events).haveOneViolationMessageContaining(testCase.violationMessageParts());
}
Aggregations