Class DefaultResultComparator

  • All Implemented Interfaces:
    ResultComparator

    public class DefaultResultComparator
    extends java.lang.Object
    implements ResultComparator
    The standard result comparator component.
    Author:
    Rene Schneider - initial API and implementation
    • Field Detail

      • valueConverter

        @Inject
        protected ValueConverter valueConverter
        The value converter to use.
      • parameterResolver

        @Inject
        protected ParameterResolver parameterResolver
        The parameter resolver to use.
    • Constructor Detail

      • DefaultResultComparator

        public DefaultResultComparator()
    • Method Detail

      • compareResult

        public ComparisonResult compareResult​(java.lang.Object aFixtureResult,
                                              ValueOrEnumValueOrOperationCollection anExpectedResult,
                                              FixtureWrapper<?> aFixtureInstance,
                                              MethodReference aFixtureMethod,
                                              java.lang.String aPropertyName)
                                       throws java.lang.ClassNotFoundException,
                                              UnexecutableException,
                                              java.lang.InstantiationException
        Description copied from interface: ResultComparator
        Compares the expected result with the actual result obtained from a test fixture.
        Specified by:
        compareResult in interface ResultComparator
        Parameters:
        aFixtureResult - the test fixture result
        anExpectedResult - the expected result as specified in the test script
        aFixtureInstance - the fixture instance that was used
        aFixtureMethod - the fixture method that was called
        aPropertyName - the name of the result property to be compared (null if it's the default result)
        Returns:
        true if the comparison was successful, false if the results are not considered equal
        Throws:
        java.lang.ClassNotFoundException
        UnexecutableException
        java.lang.InstantiationException
      • convertAndPerformEqualityCheck

        protected ComparisonResult convertAndPerformEqualityCheck​(java.lang.Object aSingleFixtureResult,
                                                                  ValueOrEnumValueOrOperation aSingleExpectedResult,
                                                                  java.lang.Class<?> aConversionTargetType)
                                                           throws ParameterUtil.UnresolvableVariableException,
                                                                  UnexecutableException
        Converts a fixture result and an expected result value for comparison (usually by converting the expected result to match the fixture result, but nested objects are handled differently and converted to maps for comparison). The final results are then compared.
        Parameters:
        aSingleFixtureResult - the fixture result
        aSingleExpectedResult - the expected result
        aConversionTargetType - the target type for conversion
        Returns:
        true if both values are considered equal, false if not
        Throws:
        ParameterUtil.UnresolvableVariableException
        UnexecutableException
      • performRegexCheck

        protected ComparisonResult performRegexCheck​(java.lang.String aFixtureResult,
                                                     RegexValue anExpectedResult)
        Performs the regular expression based comparison between a fixture result and an expected regex. The pattern provided must be "found" in the value (it does not have to match the entire value, except if the pattern is anchored to the start and/or end).
        Parameters:
        aFixtureResult - the fixture result as a String
        anExpectedResult - the expected result
        Returns:
        SimpleComparisonResult.EQUAL (pattern found) or SimpleComparisonResult.NOT_EQUAL (pattern not found)
      • performEqualityCheck

        protected ComparisonResult performEqualityCheck​(java.lang.Object aConvertedResult,
                                                        java.lang.Object aConvertedExpectedResult,
                                                        ValueOrEnumValueOrOperation aRawExpectedResult)
        Perform the actual equality check between a real result returned from a fixture and a converted result gathered from the test scripts. A few special cases are handled here, but if no special case applies, this just runs a standard equals() comparison.
        Parameters:
        aConvertedResult - the actual result
        aConvertedExpectedResult - the expected result from the scripts, converted to the same type as the actual result
        aRawExpectedResult - the raw expected result object from the scripts (if determinable, null otherwise)
        Returns:
        true if equal, false otherwise
      • performEqualityCheckForMaps

        protected MapComparisonResult performEqualityCheckForMaps​(java.util.Map<?,​?> aResult,
                                                                  java.util.Map<?,​?> anExpectedResult,
                                                                  ValueOrEnumValueOrOperation aRawExpectedResult)
        Compare two Maps for equality. Maps are considered equal if all the values in the expected result are found in the actual result (there may well be more keys in the actual result than expected, except if one of the maps declares one of these "inexistent", in which case it may NOT exist in the other!).
        Parameters:
        aResult - the result returned by the fixture
        anExpectedResult - the expected result as in the script, converted for comparison
        aRawExpectedResult - the raw expected result as in the script, before conversion
        Returns:
        true if equal, false otherwise
      • performEqualityCheckForDates

        protected ComparisonResult performEqualityCheckForDates​(java.util.Date aResult,
                                                                java.util.Date anExpectedResult,
                                                                java.lang.Object aRawExpectedResult)
        Compare two Dates for equality.
        Parameters:
        aResult - the result returned by the fixture
        anExpectedResult - the expected result as in the script, converted for comparison
        aRawExpectedResult - the raw expected result as in the script, before conversion
        Returns:
        true if equal, false otherwise
      • performEqualityCheckForJava8Dates

        protected ComparisonResult performEqualityCheckForJava8Dates​(java.time.temporal.Temporal aResult,
                                                                     java.time.temporal.Temporal anExpectedResult,
                                                                     java.lang.Object aRawExpectedResult)
        Compare two Temporals for equality.
        Parameters:
        aResult - the result returned by the fixture
        anExpectedResult - the expected result as in the script, converted for comparison
        aRawExpectedResult - the raw expected result as in the script, before conversion
        Returns:
        true if equal, false otherwise
      • performEqualityCheckForObjects

        protected ComparisonResult performEqualityCheckForObjects​(java.lang.Object aResult,
                                                                  java.lang.Object anExpectedResult,
                                                                  java.lang.Object aRawExpectedResult)
        Compare two objects. At this point it is expected that the previous stages have done all conversion work, iteration through arrays etc.
        Parameters:
        aResult - the result returned by the fixture
        anExpectedResult - the expected result as in the script, converted for comparison
        aRawExpectedResult - the raw expected result as in the script, before conversion
        Returns:
        true if equal, false otherwise