Class Verify

java.lang.Object
org.apache.juneau.assertions.Verify

public class Verify extends Object
Utility class for performing simple validations on objects.

Verifications that pass return a null string. Verifications that don't pass return a string with a useful error message.

Example:

// Validates that our POJO is of type MyBean. String errorMessage = verify(myPojo).isType(MyBean.class); if (errorMessage != null) throw new RuntimeException(errorMessage);

See Also:
  • Constructor Details

    • Verify

      protected Verify(Object o)
      Create a new verifier object.
      Parameters:
      o - The object being verified.
  • Method Details

    • verify

      public static Verify verify(Object o)
      Create a new verifier object.
      Parameters:
      o - The object being verified.
      Returns:
      A new verifier object.
    • msg

      public Verify msg(String msg, Object args)
      Overrides the default error message produced by the verification.
      Parameters:
      msg - The error message.
      args - Optional message arguments.
      Returns:
      This object.
    • isType

      public String isType(Class<?> type)
      Verifies that this object is of the specified type.
      Parameters:
      type - The type to test against.
      Returns:
      An error message if the object is not of the specified type, otherwise null.
    • is

      public String is(Object expected)
      Verifies that this object is equal to the specified object.
      Parameters:
      expected - The object to test against for equality.
      Returns:
      An error message if the object is not equal to the specified object, otherwise null.
    • isTrue

      public String isTrue()
      Verifies that this object is equal to Boolean.TRUE.
      Returns:
      An error message if the object is not true, otherwise null.
    • isFalse

      public String isFalse()
      Verifies that this object is equal to Boolean.FALSE.
      Returns:
      An error message if the object is not false, otherwise null.