Package de.gebit.integrity.runner.comparator

## Class DefaultResultComparator

- java.lang.Object
- - de.gebit.integrity.runner.comparator.DefaultResultComparator

- All Implemented Interfaces:
    `ResultComparator`

      public class DefaultResultComparator
      extends Object
      implements ResultComparator

  The standard result comparator component.
  Author:
    Rene Schneider - initial API and implementation

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected ParameterResolver` | `parameterResolver` | The parameter resolver to use.
    `protected ValueConverter` | `valueConverter` | The value converter to use.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `DefaultResultComparator()` |

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `ComparisonResult` | `compareResult​(Object aFixtureResult, ValueOrEnumValueOrOperationCollection anExpectedResult, FixtureWrapper<?> aFixtureInstance, MethodReference aFixtureMethod, String aPropertyName)` | Compares the expected result with the actual result obtained from a test fixture.
    `protected ComparisonResult` | `convertAndPerformEqualityCheck​(Object aSingleFixtureResult, ValueOrEnumValueOrOperation aSingleExpectedResult, Class<?> aConversionTargetType)` | 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).
    `protected ComparisonResult` | `convertAndPerformEqualityCheck​(Object aSingleFixtureResult, Object aSingleExpectedResult, ValueOrEnumValueOrOperation anOriginalSingleExpectedResult, Class<?> aConversionTargetType, boolean anExpectedResultWasEmptyOptionalFlag)` |
    `protected ComparisonResult` | `performEqualityCheck​(Object aConvertedResult, 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.
    `protected ComparisonResult` | `performEqualityCheckForDates​(Date aResult, Date anExpectedResult, Object aRawExpectedResult)` | Compare two `Date`s for equality.
    `protected ComparisonResult` | `performEqualityCheckForJava8Dates​(Temporal aResult, Temporal anExpectedResult, Object aRawExpectedResult)` | Compare two `Temporal`s for equality.
    `protected MapComparisonResult` | `performEqualityCheckForMaps​(Map<?,​?> aResult, Map<?,​?> anExpectedResult, ValueOrEnumValueOrOperation aRawExpectedResult)` | Compare two `Map`s for equality.
    `protected ComparisonResult` | `performEqualityCheckForObjects​(Object aResult, Object anExpectedResult, Object aRawExpectedResult)` | Compare two objects.
    `protected ComparisonResult` | `performRegexCheck​(String aFixtureResult, RegexValue anExpectedResult)` | Performs the regular expression based comparison between a fixture result and an expected regex.

    - ### Methods inherited from class java.lang.Object

      `clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait`

- - ### 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​(Object aFixtureResult,
                                                ValueOrEnumValueOrOperationCollection anExpectedResult,
                                                FixtureWrapper<?> aFixtureInstance,
                                                MethodReference aFixtureMethod,
                                                String aPropertyName)
                                         throws ClassNotFoundException,
                                                UnexecutableException,
                                                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:
        `ClassNotFoundException`
        `UnexecutableException`
        `InstantiationException`

    - #### convertAndPerformEqualityCheck

          protected ComparisonResult convertAndPerformEqualityCheck​(Object aSingleFixtureResult,
                                                                    ValueOrEnumValueOrOperation aSingleExpectedResult,
                                                                    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`

    - #### convertAndPerformEqualityCheck

          protected ComparisonResult convertAndPerformEqualityCheck​(Object aSingleFixtureResult,
                                                                    Object aSingleExpectedResult,
                                                                    ValueOrEnumValueOrOperation anOriginalSingleExpectedResult,
                                                                    Class<?> aConversionTargetType,
                                                                    boolean anExpectedResultWasEmptyOptionalFlag)
                                                             throws ParameterUtil.UnresolvableVariableException,
                                                                    UnexecutableException

      Throws:
        `ParameterUtil.UnresolvableVariableException`
        `UnexecutableException`

    - #### performRegexCheck

          protected ComparisonResult performRegexCheck​(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​(Object aConvertedResult,
                                                          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​(Map<?,​?> aResult,
                                                                    Map<?,​?> anExpectedResult,
                                                                    ValueOrEnumValueOrOperation aRawExpectedResult)

      Compare two `Map`s 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​(Date aResult,
                                                                  Date anExpectedResult,
                                                                  Object aRawExpectedResult)

      Compare two `Date`s 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​(Temporal aResult,
                                                                       Temporal anExpectedResult,
                                                                       Object aRawExpectedResult)

      Compare two `Temporal`s 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​(Object aResult,
                                                                    Object anExpectedResult,
                                                                    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