Java Code Examples for com.tngtech.archunit.lang.ConditionEvents#add()

The following examples show how to use com.tngtech.archunit.lang.ConditionEvents#add() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: DependencyRules.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(final JavaClass clazz, final ConditionEvents events) {
    for (Dependency dependency : clazz.getDirectDependenciesFromSelf()) {
        boolean dependencyOnUpperPackage = isDependencyOnUpperPackage(dependency.getOriginClass(), dependency.getTargetClass());
        events.add(new SimpleConditionEvent(dependency, dependencyOnUpperPackage, dependency.getDescription()));
    }
}
 
Example 2
Source File: ArchConditions.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(T member, ConditionEvents events) {
    boolean satisfied = predicate.apply(member);
    String message = createMessage(member,
            (satisfied ? "is " : "is not ") + eventDescription);
    events.add(new SimpleConditionEvent(member, satisfied, message));
}
 
Example 3
Source File: ArchConditions.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(T item, ConditionEvents events) {
    boolean satisfied = containing.apply(item);
    String message = createMessage(item,
            String.format("name %s '%s'", satisfied ? "contains" : "does not contain", infix));
    events.add(new SimpleConditionEvent(item, satisfied, message));
}
 
Example 4
Source File: GivenMembersTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
static ArchCondition<JavaMember> everythingViolationPrintMemberName() {
    return new ArchCondition<JavaMember>("condition text") {
        @Override
        public void check(JavaMember item, ConditionEvents events) {
            events.add(SimpleConditionEvent.violated(item, formatMember(item)));
        }
    };
}
 
Example 5
Source File: ArchConditions.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(JavaClass javaClass, ConditionEvents events) {
    boolean isInterface = javaClass.isInterface();
    String message = createMessage(javaClass,
            (isInterface ? "is an" : "is not an") + " interface");
    events.add(new SimpleConditionEvent(javaClass, isInterface, message));
}
 
Example 6
Source File: ArchConditions.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(JavaClass javaClass, ConditionEvents events) {
    boolean satisfied = predicate.apply(javaClass);
    String message = String.format("simple name of %s %s with '%s' in %s",
            javaClass.getName(),
            satisfied ? "starts" : "does not start",
            prefix,
            javaClass.getSourceCodeLocation());
    events.add(new SimpleConditionEvent(javaClass, satisfied, message));
}
 
Example 7
Source File: GivenSlicesInternal.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(Slice slice, ConditionEvents events) {
    Iterable<Dependency> relevantDependencies = filter(slice.getDependenciesFromSelf(), predicate);
    Slices dependencySlices = inputTransformer.transform(relevantDependencies);
    for (Slice dependencySlice : dependencySlices) {
        SliceDependency dependency = SliceDependency.of(slice, relevantDependencies, dependencySlice);
        events.add(SimpleConditionEvent.violated(dependency, dependency.getDescription()));
    }
}
 
Example 8
Source File: ContainAnyCondition.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(Collection<? extends T> collection, ConditionEvents events) {
    ConditionEvents subEvents = new ConditionEvents();
    for (T element : collection) {
        condition.check(element, subEvents);
    }
    if (!subEvents.isEmpty()) {
        events.add(new AnyConditionEvent(collection, subEvents));
    }
}
 
Example 9
Source File: PublicAPIRules.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private static ArchCondition<JavaClass> bePublicAPIForInheritance() {
    return new ArchCondition<JavaClass>("be public API for inheritance") {
        @Override
        public void check(JavaClass item, ConditionEvents events) {
            boolean satisfied = item.isAnnotatedWith(publicApiForInheritance()) ||
                    markedAsPublicAPIForInheritance().apply(item);
            events.add(new SimpleConditionEvent(item, satisfied,
                    String.format("class %s is %smeant for inheritance", item.getName(), satisfied ? "" : "not ")));
        }
    };
}
 
Example 10
Source File: PublicAPIRules.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
private static ArchCondition<? super JavaClass> beInterfaces() {
    return new ArchCondition<JavaClass>("be interfaces") {
        @Override
        public void check(JavaClass item, ConditionEvents events) {
            boolean satisfied = item.isInterface();
            events.add(new SimpleConditionEvent(item, satisfied,
                    String.format("class %s is %sinterface", item.getName(), satisfied ? "" : "no ")));
        }
    };
}
 
Example 11
Source File: ArchConditions.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
@Override
public void check(T item, ConditionEvents events) {
    boolean satisfied = predicate.apply(item);
    String message = createMessage(item,
            (satisfied ? "does " : "does not ") + predicate.getDescription());
    events.add(new SimpleConditionEvent(item, satisfied, message));
}
 
Example 12
Source File: GivenMembersTest.java    From ArchUnit with Apache License 2.0 5 votes vote down vote up
static ArchCondition<JavaMember> beAnnotatedWith(final Class<? extends Annotation> annotationType) {
    return new ArchCondition<JavaMember>("be annotated with @%s", annotationType.getSimpleName()) {
        @Override
        public void check(JavaMember member, ConditionEvents events) {
            boolean satisfied = member.isAnnotatedWith(annotationType);
            String message = String.format("Member '%s' %s @%s",
                    formatMember(member), satisfied ? "is annotated with" : "is not annotated with",
                    annotationType.getSimpleName());
            events.add(new SimpleConditionEvent(member, satisfied, message));
        }
    };
}
 
Example 13
Source File: ContainAnyCondition.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void addInvertedTo(ConditionEvents events) {
    events.add(new OnlyConditionEvent(correspondingObjects, violating, allowed));
}
 
Example 14
Source File: JavaAccessCondition.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void check(T item, ConditionEvents events) {
    events.add(new SimpleConditionEvent(item, predicate.apply(item), item.getDescription()));
}
 
Example 15
Source File: DependencyCondition.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void check(Dependency item, ConditionEvents events) {
    events.add(new SimpleConditionEvent(item, conditionPredicate.apply(item), item.getDescription()));
}
 
Example 16
Source File: FieldAccessCondition.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void check(JavaFieldAccess item, ConditionEvents events) {
    events.add(new SimpleConditionEvent(item, fieldAccessIdentifier.apply(item), item.getDescription()));
}
 
Example 17
Source File: ArchConditions.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void check(T object, ConditionEvents events) {
    boolean satisfied = rawType.apply(object);
    String message = createMessage(object, (satisfied ? "has " : "does not have ") + rawType.getDescription());
    events.add(new SimpleConditionEvent(object, satisfied, message));
}
 
Example 18
Source File: Architectures.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void finish(ConditionEvents events) {
    if (empty) {
        events.add(violated(layerDefinition, String.format("Layer '%s' is empty", layerDefinition.name)));
    }
}
 
Example 19
Source File: ArchUnitRunnerTestUtils.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void check(JavaClass item, ConditionEvents events) {
    events.add(SimpleConditionEvent.satisfied(item, "I'm always satisfied"));
}
 
Example 20
Source File: SessionBeanRulesTest.java    From ArchUnit with Apache License 2.0 4 votes vote down vote up
@Override
public void check(JavaClass businessInterface, ConditionEvents events) {
    events.add(new SimpleConditionEvent(businessInterface,
            businessInterface.getAllSubClasses().size() <= 1,
            describe(businessInterface)));
}