Enum RestResourceProducer.Scope

java.lang.Object
java.lang.Enum<RestResourceProducer.Scope>
dev.resteasy.junit.extension.api.RestResourceProducer.Scope
All Implemented Interfaces:
Serializable, Comparable<RestResourceProducer.Scope>
Enclosing interface:
RestResourceProducer

public static enum RestResourceProducer.Scope extends Enum<RestResourceProducer.Scope>
Defines the lifecycle scope for resources produced by a RestResourceProducer.

The scope determines when AutoCloseable resources are automatically closed after injection. This allows producers to balance performance (class-scoped reuse) with isolation (method-scoped cleanup).

Since:
1.0
Author:
James R. Perkins
  • Enum Constant Details

    • DEFAULT

      public static final RestResourceProducer.Scope DEFAULT
      Use the natural scope of the injection point.
      • Static fields: Cleaned up when the test class completes
      • Instance fields: Cleaned up when the test class completes
      • Method parameters: Cleaned up when the test method completes

      This is the default scope and is appropriate for most custom producers where method-level isolation is desired for parameters (e.g., temporary files, test-specific resources).

      See Also:
    • CLASS

      public static final RestResourceProducer.Scope CLASS
      Always use class scope for all injection points.

      Resources are cleaned up when the test class completes, regardless of whether injected into a field or method parameter. This scope is appropriate for expensive-to-create resources that are safe to share across test methods.

      Example use cases:

      • REST clients (thread-safe, expensive to create)
      • Database connection pools (designed for reuse)
      • Immutable configuration objects

      Built-in producers (Client, URI, Configuration) use CLASS scope for performance.

      See Also:
    • NEW

      public static final RestResourceProducer.Scope NEW
      Create a new instance for every injection point.

      The producer's RestResourceProducer.produce(ExtensionContext, Class, Annotation...) method is invoked every time the resource is injected, completely bypassing any caching. This means:

      • Multiple field injections create separate instances
      • Each method parameter injection creates a fresh instance
      • No instance is ever shared or reused

      This scope is appropriate for mutable or stateful resources that must be isolated between injection points to prevent cross-contamination or unexpected behavior.

      Example use cases:

      • Mutable API clients that maintain request state (e.g., WebTarget)
      • Builder instances that accumulate state across method calls
      • Resources with per-injection configuration requirements

      Performance consideration: Since produce() is called for every injection, this scope should only be used when instance isolation is required. Use CLASS for expensive, thread-safe resources.

      Built-in producers that use NEW scope: WebTarget

      See Also:
  • Method Details

    • values

      public static RestResourceProducer.Scope[] values()
      Returns an array containing the constants of this enum type, in the order they are declared.
      Returns:
      an array containing the constants of this enum type, in the order they are declared
    • valueOf

      public static RestResourceProducer.Scope valueOf(String name)
      Returns the enum constant of this type with the specified name. The string must match exactly an identifier used to declare an enum constant in this type. (Extraneous whitespace characters are not permitted.)
      Parameters:
      name - the name of the enum constant to be returned.
      Returns:
      the enum constant with the specified name
      Throws:
      IllegalArgumentException - if this enum type has no constant with the specified name
      NullPointerException - if the argument is null