Class NoBlanketCatchArchTest

java.lang.Object
com.aim2be.platform.archunit.NoBlanketCatchArchTest

public final class NoBlanketCatchArchTest extends Object
Consumer-facing helper + template for NoBlanketCatch.

WARN mode (current sweep default). The L0-T0 #7 sweep introduces the rule in warn mode — services have ~115 pre-existing blanket catches that are being typed incrementally, so the rule must surface violations without breaking the build. A consuming service writes:

 @Test
 void noBlanketCatchWarn() {
     JavaClasses classes = new ClassFileImporter()
             .withImportOption(new ImportOption.DoNotIncludeTests())
             .importPackages("com.aim2be.user");
     String report = NoBlanketCatchArchTest.evaluateForWarning(classes);
     if (!report.isEmpty()) {
         LoggerFactory.getLogger(getClass()).warn("NoBlanketCatch (WARN):\n{}", report);
     }
     // intentionally no assertion — warn-only until the catches are typed
 }
 

BLOCK mode (post-W2 flip). Once a service's blanket catches are typed, replace the warn test with a hard gate:

 @AnalyzeClasses(packagesOf = UserServiceApplication.class,
                 importOptions = ImportOption.DoNotIncludeTests.class)
 class NoBlanketCatchGateTest { // distinct name — must NOT collide with this helper
     @ArchTest
     static final ArchRule rule = NoBlanketCatch.noBlanketCatchOutsideBoundary();
 }
 

Name the BLOCK-mode class distinctly (e.g. NoBlanketCatchGateTest), NOT NoBlanketCatchArchTest: a consumer class sharing this helper's simple name in the same package would shadow the import and break any evaluateForWarning(JavaClasses) callsite still present during the WARN→BLOCK transition.

On the *ArchTest name. Despite the suffix this is a consumer-facing helper/template, not a JUnit test class — it declares no @Test / @ArchTest member and is never auto-discovered (it lives in src/main, off the test classpath of this module). The name deliberately mirrors its sibling EntityVersionParityArchTest so the two shared-rule entry points read consistently (rule 10); the BLOCK-mode snippet above shows the actual @ArchTest wiring a consumer writes. The rule's own positive/negative self-test is NoBlanketCatchSelfTest in src/test.

  • Method Details

    • evaluateForWarning

      public static String evaluateForWarning(com.tngtech.archunit.core.domain.JavaClasses classes)
      Evaluates NoBlanketCatch.noBlanketCatchOutsideBoundary() against the given classes and returns the formatted failure report, or an empty string when there are no violations. The caller logs the report (warn mode) — no logging dependency is imposed on this module.
      Parameters:
      classes - the imported classes to evaluate (typically the service's production package, tests excluded)
      Returns:
      the failure-report text, or "" when compliant