Class StatusCodeDetector

java.lang.Object
com.arc_e_tect.gradle.doppelganger.scan.StatusCodeDetector

public final class StatusCodeDetector extends Object
Best-effort detection of the HTTP status code a test method asserts, from the same List<MethodCallExpr> a ContractVerificationSource AST scanner already collects for that method - not exhaustive, since a test can assert a response's status in ways this cannot recognise (a variable, a helper method, a custom matcher); such tests still count towards an endpoint's overall contract test count, they simply contribute no evidence to any specific response code's count.

Recognises three independent shapes, matched by simple method name only, the same way the scanners that use this class already match request-builder calls:

  • MockMvc: status().isOk() / status().isNotFound() / ... (a fixed set of well-known org.springframework.test.web.servlet.result.StatusResultMatchers method names), or the numeric status().is(404).
  • REST Assured: .statusCode(404).
  • WebTestClient: .expectStatus().isNotFound(), or the numeric .expectStatus().isEqualTo(404).
  • Method Details

    • detect

      public static Optional<String> detect(List<com.github.javaparser.ast.expr.MethodCallExpr> calls)
      Detects the status code asserted anywhere among calls, or Optional.empty() when none of the recognised shapes are present.
      Parameters:
      calls - every method call expression found in a test method's body
      Returns:
      the detected status code, e.g. "404", or Optional.empty()