Class TestResult


  • public final class TestResult
    extends java.lang.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.
    • Constructor Summary

      Constructors 
      Constructor Description
      TestResult()
      Creates a new result for a successful test.
      TestResult​(java.lang.Throwable causeForFailure)
      Creates a new result for a successful test if the exception is null, or a failed test otherwise.
    • Constructor Detail

      • TestResult

        public TestResult()
        Creates a new result for a successful test.
      • TestResult

        public TestResult​(java.lang.Throwable causeForFailure)
        Creates a new result for a successful test if the exception is null, or a failed test otherwise.
        Parameters:
        causeForFailure - the exception which caused the failure
    • Method Detail

      • success

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

        public static TestResult failure​(java.lang.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)
      • isUnsuccessful

        public boolean isUnsuccessful()
        Returns:
        whether the result indicates failure (exception given)
      • getCauseForFailure

        public java.util.Optional<java.lang.Throwable> getCauseForFailure()
        Returns:
        an optional containing the exception which caused the failure or an empty optional if the test was successful
      • equals

        public boolean equals​(java.lang.Object object)
        Overrides:
        equals in class java.lang.Object
      • hashCode

        public int hashCode()
        Overrides:
        hashCode in class java.lang.Object
      • toString

        public java.lang.String toString()
        Overrides:
        toString in class java.lang.Object