java.lang.Object
io.github.teceli.resiliencia.test.FakeResilient<T>
All Implemented Interfaces:
Resilient<T>

public final class FakeResilient<T> extends Object implements Resilient<T>
A pass-through Resilient for testing code that composes or accepts patterns (e.g. Policy chains) without pulling in real pattern behavior. Executes the operation directly, counts invocations, and can impersonate any PatternKind / pattern name. Configured via withX copy methods like the real patterns; each returns a new instance with a fresh call count.
  • Method Details

    • passthrough

      public static <T> FakeResilient<T> passthrough()
      A fake that simply executes the operation, reporting itself as a CUSTOM pattern.
    • withPatternName

      public FakeResilient<T> withPatternName(String patternName)
    • withPatternKind

      public FakeResilient<T> withPatternKind(PatternKind patternKind)
    • withOnCall

      public FakeResilient<T> withOnCall(Runnable onCall)
      Run the given hook each time this fake executes, before the operation — useful for recording execution order across a chain of fakes.
    • callCount

      public int callCount()
    • patternName

      public String patternName()
      Description copied from interface: Resilient
      The name of this pattern, e.g. "retry", "timeout", "circuit-breaker". Used for identification (e.g. by Policy) without coupling to concrete pattern types. Defaults to "custom" for user-defined Resilient implementations.
      Specified by:
      patternName in interface Resilient<T>
    • patternKind

      public PatternKind patternKind()
      Description copied from interface: Resilient
      The kind of this pattern, used for internal comparisons (e.g. Policy order validation). Unlike Resilient.patternName(), which is a free-form observability label, this is a closed enum the library can reason about exhaustively. Defaults to PatternKind.CUSTOM for user-defined Resilient implementations.
      Specified by:
      patternKind in interface Resilient<T>
    • call

      public T call(Resilient.Operation<T> operation) throws ResilientException
      Description copied from interface: Resilient
      Execute an operation with resilience guarantees. May throw ResilienciaException or a specific pattern exception.
      Specified by:
      call in interface Resilient<T>
      Throws:
      ResilientException
    • outcome

      public Outcome<T> outcome(Resilient.Operation<T> operation)
      Description copied from interface: Resilient
      Execute an operation and capture the result or failure as an Outcome. Never throws for a recorded Exception — always returns Success, Failure, or a pattern-specific outcome. An Error thrown by the operation propagates uncaught instead of being captured as a Failure: fatal JVM conditions (e.g. OutOfMemoryError) should not be treated as a recoverable result.
      Specified by:
      outcome in interface Resilient<T>