Enum RecursiveAssertionConfiguration.OptionalAssertionPolicy

    • Enum Constant Detail

      • OPTIONAL_VALUE_ONLY

        public static final RecursiveAssertionConfiguration.OptionalAssertionPolicy OPTIONAL_VALUE_ONLY
        Apply the Predicate (recursively) to the value of the optional field but not the optional field.

        Consider the following example:

         class Parent {
           Optional<String> greeting = Optional.of("Hi");
         }
        
         Parent parent = new Parent();
        
         assertThat(parent).usingRecursiveAssertion()
                           .allFieldsSatisfy(field -> myPredicate(field));
        With this policy, myPredicate(field) is applied to the optional value "Hi" but not to the greeting Optional field.
      • OPTIONAL_OBJECT_ONLY

        public static final RecursiveAssertionConfiguration.OptionalAssertionPolicy OPTIONAL_OBJECT_ONLY
        Apply the Predicate to the optional field but not to its value.

        Consider the following example:

         class Parent {
           Optional<String> greeting = Optional.of("Hi");
         }
        
         Parent parent = new Parent();
        
         assertThat(parent).usingRecursiveAssertion()
                           .allFieldsSatisfy(field -> myPredicate(field));
        With this policy, myPredicate(field) is applied to the greeting Optional field but not to the optional value "Hi".
      • OPTIONAL_OBJECT_AND_VALUE

        public static final RecursiveAssertionConfiguration.OptionalAssertionPolicy OPTIONAL_OBJECT_AND_VALUE
        Apply the Predicate to the optional field as well as to (recursively) its value.

        Consider the following example:

         class Parent {
           List<String> greetings = new Optional<>();
         }
        
         Parent parent = new Parent();
         parent.greetings.add("Hello");
         parent.greetings.add("Salut");
        
         assertThat(parent).usingRecursiveAssertion()
                           .allFieldsSatisfy(field -> myPredicate(field));
        With this policy, myPredicate(field) is applied to the greeting Optional field and its value "Hi".
    • Constructor Detail

      • OptionalAssertionPolicy

        private OptionalAssertionPolicy()
    • Method Detail

      • values

        public static RecursiveAssertionConfiguration.OptionalAssertionPolicy[] values()
        Returns an array containing the constants of this enum type, in the order they are declared. This method may be used to iterate over the constants as follows:
        for (RecursiveAssertionConfiguration.OptionalAssertionPolicy c : RecursiveAssertionConfiguration.OptionalAssertionPolicy.values())
            System.out.println(c);
        
        Returns:
        an array containing the constants of this enum type, in the order they are declared
      • valueOf

        public static RecursiveAssertionConfiguration.OptionalAssertionPolicy valueOf​(java.lang.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:
        java.lang.IllegalArgumentException - if this enum type has no constant with the specified name
        java.lang.NullPointerException - if the argument is null