Class ConditionalRequestDefinition


public class ConditionalRequestDefinition extends RequestDefinition
A conditional (if-then-else) request matcher.

Unlike the default AND-only matching (where every field of a single HttpRequest must match), a conditional matcher evaluates one of two branches depending on whether a guard request definition matches:

   if (ifMatches.matches(request)) {
       require thenMatches.matches(request)
   } else {
       require elseMatches.matches(request)   // when elseMatches is absent the
                                              // expectation matches whenever the
                                              // guard is false
   }
 

Each branch reuses the existing RequestDefinition matching machinery, so any request definition (an HttpRequest, an OpenAPIDefinition, even a nested ConditionalRequestDefinition) may be used as the if, then or else branch.

This construct is entirely additive and opt-in: existing AND-only expectations are unchanged.

Author:
jamesdbloom