Class Capture

java.lang.Object
software.amazon.jsii.JsiiObject
software.amazon.awscdk.assertions.Matcher
software.amazon.awscdk.assertions.Capture
All Implemented Interfaces:
software.amazon.jsii.JsiiSerializable

@Generated(value="jsii-pacmak/1.84.0 (build 5404dcf)", date="2023-06-19T16:29:55.195Z") @Stability(Stable) public class Capture extends Matcher
Capture values while matching templates.

Using an instance of this class within a Matcher will capture the matching value. The as*() APIs on the instance can be used to get the captured value.

Example:

 // Given a template -
 // {
 //   "Resources": {
 //     "MyBar": {
 //       "Type": "Foo::Bar",
 //       "Properties": {
 //         "Fred": "Flob",
 //       }
 //     },
 //     "MyBaz": {
 //       "Type": "Foo::Bar",
 //       "Properties": {
 //         "Fred": "Quib",
 //       }
 //     }
 //   }
 // }
 Capture fredCapture = new Capture();
 template.hasResourceProperties("Foo::Bar", Map.of(
         "Fred", fredCapture));
 fredCapture.asString(); // returns "Flob"
 fredCapture.next(); // returns true
 fredCapture.asString();
 
  • Nested Class Summary

    Nested classes/interfaces inherited from class software.amazon.jsii.JsiiObject

    software.amazon.jsii.JsiiObject.InitializationMode
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
     
    Initialize a new capture.
     
    Capture(Object pattern)
    Initialize a new capture.
    protected
    Capture(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
     
    protected
    Capture(software.amazon.jsii.JsiiObjectRef objRef)
     
  • Method Summary

    Modifier and Type
    Method
    Description
    Retrieve the captured value as an array.
    Retrieve the captured value as a boolean.
    Retrieve the captured value as a number.
    Retrieve the captured value as a JSON object.
    Retrieve the captured value as a string.
    A name for the matcher.
    When multiple results are captured, move the iterator to the next result.
    test(Object actual)
    Test whether a target matches the provided pattern.

    Methods inherited from class software.amazon.awscdk.assertions.Matcher

    isMatcher

    Methods inherited from class software.amazon.jsii.JsiiObject

    jsiiAsyncCall, jsiiAsyncCall, jsiiCall, jsiiCall, jsiiGet, jsiiGet, jsiiSet, jsiiStaticCall, jsiiStaticCall, jsiiStaticGet, jsiiStaticGet, jsiiStaticSet, jsiiStaticSet

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface software.amazon.jsii.JsiiSerializable

    $jsii$toJson
  • Constructor Details

    • Capture

      protected Capture(software.amazon.jsii.JsiiObjectRef objRef)
    • Capture

      protected Capture(software.amazon.jsii.JsiiObject.InitializationMode initializationMode)
    • Capture

      @Stability(Stable) public Capture(@Nullable Object pattern)
      Initialize a new capture.

      Parameters:
      pattern - a nested pattern or Matcher.
    • Capture

      @Stability(Stable) public Capture()
      Initialize a new capture.
  • Method Details

    • asArray

      @Stability(Stable) @NotNull public List<Object> asArray()
      Retrieve the captured value as an array.

      An error is generated if no value is captured or if the value is not an array.

    • asBoolean

      @Stability(Stable) @NotNull public Boolean asBoolean()
      Retrieve the captured value as a boolean.

      An error is generated if no value is captured or if the value is not a boolean.

    • asNumber

      @Stability(Stable) @NotNull public Number asNumber()
      Retrieve the captured value as a number.

      An error is generated if no value is captured or if the value is not a number.

    • asObject

      @Stability(Stable) @NotNull public Map<String,Object> asObject()
      Retrieve the captured value as a JSON object.

      An error is generated if no value is captured or if the value is not an object.

    • asString

      @Stability(Stable) @NotNull public String asString()
      Retrieve the captured value as a string.

      An error is generated if no value is captured or if the value is not a string.

    • next

      @Stability(Stable) @NotNull public Boolean next()
      When multiple results are captured, move the iterator to the next result.

      Returns:
      true if another capture is present, false otherwise
    • test

      @Stability(Stable) @NotNull public MatchResult test(@NotNull Object actual)
      Test whether a target matches the provided pattern.

      Every Matcher must implement this method. This method will be invoked by the assertions framework. Do not call this method directly.

      Specified by:
      test in class Matcher
      Parameters:
      actual - This parameter is required.
      Returns:
      the list of match failures. An empty array denotes a successful match.
    • getName

      @Stability(Stable) @NotNull public String getName()
      A name for the matcher.

      This is collected as part of the result and may be presented to the user.

      Specified by:
      getName in class Matcher