Class ComparisonFailureWithFacts

  • All Implemented Interfaces:
    ErrorWithFacts, java.io.Serializable

    final class ComparisonFailureWithFacts
    extends Platform.PlatformComparisonFailure
    implements ErrorWithFacts
    An AssertionError (usually a JUnit ComparisonFailure, but not under GWT) composed of structured Fact instances and other string messages.

    This class includes logic to format expected and actual values for easier reading.

    • Field Summary

      Fields 
      Modifier and Type Field Description
      private static int CONTEXT  
      (package private) com.google.common.collect.ImmutableList<Fact> facts  
      private static int WORTH_HIDING  
    • Constructor Summary

      Constructors 
      Modifier Constructor Description
      private ComparisonFailureWithFacts​(com.google.common.collect.ImmutableList<java.lang.String> messages, com.google.common.collect.ImmutableList<Fact> facts, java.lang.String expected, java.lang.String actual, java.lang.Throwable cause)  
    • Method Summary

      All Methods Static Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      (package private) static ComparisonFailureWithFacts create​(com.google.common.collect.ImmutableList<java.lang.String> messages, com.google.common.collect.ImmutableList<Fact> headFacts, com.google.common.collect.ImmutableList<Fact> tailFacts, java.lang.String expected, java.lang.String actual, java.lang.Throwable cause)  
      com.google.common.collect.ImmutableList<Fact> facts()  
      (package private) static com.google.common.collect.ImmutableList<Fact> formatExpectedAndActual​(java.lang.String expected, java.lang.String actual)
      Returns one or more facts describing the difference between the given expected and actual values.
      private static com.google.common.collect.ImmutableList<Fact> makeFacts​(com.google.common.collect.ImmutableList<Fact> headFacts, com.google.common.collect.ImmutableList<Fact> tailFacts, java.lang.String expected, java.lang.String actual)  
      private static com.google.common.collect.ImmutableList<Fact> removeCommonPrefixAndSuffix​(java.lang.String expected, java.lang.String actual)  
      private static boolean validSurrogatePairAt​(java.lang.CharSequence string, int index)  
      • Methods inherited from class org.junit.ComparisonFailure

        getActual, getExpected
      • Methods inherited from class java.lang.Throwable

        addSuppressed, fillInStackTrace, getLocalizedMessage, getStackTrace, getSuppressed, initCause, printStackTrace, printStackTrace, printStackTrace, setStackTrace
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
    • Constructor Detail

      • ComparisonFailureWithFacts

        private ComparisonFailureWithFacts​(com.google.common.collect.ImmutableList<java.lang.String> messages,
                                           com.google.common.collect.ImmutableList<Fact> facts,
                                           java.lang.String expected,
                                           java.lang.String actual,
                                           java.lang.Throwable cause)
    • Method Detail

      • create

        static ComparisonFailureWithFacts create​(com.google.common.collect.ImmutableList<java.lang.String> messages,
                                                 com.google.common.collect.ImmutableList<Fact> headFacts,
                                                 com.google.common.collect.ImmutableList<Fact> tailFacts,
                                                 java.lang.String expected,
                                                 java.lang.String actual,
                                                 java.lang.Throwable cause)
      • facts

        public com.google.common.collect.ImmutableList<Fact> facts()
        Specified by:
        facts in interface ErrorWithFacts
      • makeFacts

        private static com.google.common.collect.ImmutableList<Fact> makeFacts​(com.google.common.collect.ImmutableList<Fact> headFacts,
                                                                               com.google.common.collect.ImmutableList<Fact> tailFacts,
                                                                               java.lang.String expected,
                                                                               java.lang.String actual)
      • formatExpectedAndActual

        static com.google.common.collect.ImmutableList<Fact> formatExpectedAndActual​(java.lang.String expected,
                                                                                     java.lang.String actual)
        Returns one or more facts describing the difference between the given expected and actual values.

        Currently, that means either 2 facts (one each for expected and actual) or 1 fact with a diff-like (but much simpler) view.

        In the case of 2 facts, the facts contain either the full expected and actual values or, if the values have a long prefix or suffix in common, abbreviated values with "…" at the beginning or end.

      • removeCommonPrefixAndSuffix

        private static com.google.common.collect.ImmutableList<Fact> removeCommonPrefixAndSuffix​(java.lang.String expected,
                                                                                                 java.lang.String actual)
      • validSurrogatePairAt

        private static boolean validSurrogatePairAt​(java.lang.CharSequence string,
                                                    int index)