CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/maven-org-apache-flink--flink-architecture-tests-base

Base library for Apache Flink architecture tests that provides common ArchUnit extensions and utilities for validating architectural constraints in both production and test code

Pending
Overview
Eval results
Files

source-predicates.mddocs/

Source Predicates

Source-based predicates for filtering and validating Java classes by their source file characteristics. Essential for mixed Java/Scala projects where ArchUnit rules need to operate exclusively on Java classes.

Capabilities

Java Class Filtering

Tests whether a given class is actually a Java class (not Scala or other JVM languages).

/**
 * Tests that a given class is a Java class, not Scala or other JVM language
 * @return DescribedPredicate that returns true if class is a Java class
 */
public static DescribedPredicate<JavaClass> areJavaClasses();

/**
 * Checks whether the given JavaClass is actually a Java class, not Scala
 * @param clazz The JavaClass to test
 * @return true if the class is a Java class, false otherwise
 */
static boolean isJavaClass(JavaClass clazz);

Usage Examples:

import static org.apache.flink.architecture.common.SourcePredicates.areJavaClasses;
import static org.apache.flink.architecture.common.SourcePredicates.isJavaClass;

// Filter classes to only include Java classes
ArchRule javaOnlyRule = classes()
    .that(areJavaClasses())
    .should()
    .notBeInterfaces();

// Manual checking in custom predicates
DescribedPredicate<JavaClass> customJavaClassCheck = 
    DescribedPredicate.describe("are custom Java classes", clazz -> {
        return isJavaClass(clazz) && clazz.getSimpleName().startsWith("Flink");
    });

Integration with Other Components:

// Used internally by GivenJavaClasses
ClassesThat<GivenClassesConjunction> javaClasses = 
    GivenJavaClasses.javaClassesThat(); // Uses areJavaClasses() internally

// Used in Conditions for type filtering
ArchCondition<JavaMethod> leafTypeCondition = 
    Conditions.haveLeafTypes(areJavaClasses().and(other -> other.isTopLevel()));

Design Rationale

Mixed Language Support: ArchUnit doesn't fully support Scala yet, making these predicates essential for projects that contain both Java and Scala code. Without proper filtering, architecture rules may fail or produce incorrect results when encountering Scala classes.

Source File Detection: The implementation checks for .java extension in the source file name, providing a reliable heuristic for distinguishing Java classes from Scala classes (which typically have .scala extensions).

Performance Considerations: The predicates perform minimal checks on the JavaClass source information, making them suitable for use in large-scale architecture validation where performance matters.

Defensive Programming: Both methods handle edge cases where source information might not be available, returning false when the source file cannot be determined rather than throwing exceptions.

Install with Tessl CLI

npx tessl i tessl/maven-org-apache-flink--flink-architecture-tests-base

docs

field-analysis.md

general-predicates.md

import-control.md

index.md

java-only-rules.md

method-validation.md

source-predicates.md

tile.json