Class TestResult


  • public final class TestResult
    extends Object
    Specifies the result of a test. Either a test threw no exception and was therefore successful, or it has an exception as a cause for failure.
    • Method Detail

      • success

        public static TestResult success()
        Descriptive convenience method for constructing a result for a successful test input.
        Returns:
        a successful result
      • exceptionalSuccess

        public static TestResult exceptionalSuccess​(Throwable exception)
        Descriptive convenience method for constructing a result for a exceptional-successful test input.
        Parameters:
        exception - thrown ErrorConstraintException
        Returns:
        an exceptional-successful result
      • failure

        public static TestResult failure​(Throwable causeForFailure)
        Descriptive convenience method for constructing a result for a failed test input.
        Parameters:
        causeForFailure - the exception which caused the test to fail, or indicates that it has failed
        Returns:
        a failed result
      • isSuccessful

        public boolean isSuccessful()
        Returns:
        whether the result indicates success (no exception given)
      • isExceptionalSuccessful

        public boolean isExceptionalSuccessful()
        Returns:
        whether the result indicates an exceptional-success (ErrorConstraintException given)
      • isUnsuccessful

        public boolean isUnsuccessful()
        Returns:
        whether the result indicates failure (exception given and not an ErrorConstraintException)
      • getResultValue

        public Optional<Throwable> getResultValue()
        Returns:
        an optional containing the exception which caused the failure or an empty optional if the test was successful
      • getRequiredResultValue

        public Throwable getRequiredResultValue()
        Returns:
        the required exception which caused the failure. Never null
        Throws:
        NullPointerException - if there was no exception (e.g. if the test was successful)
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class Object