Class FixtureWrapper<C>

  • Type Parameters:
    C - the fixture class

    public class FixtureWrapper<C>
    extends java.lang.Object
    This wrapper is used to encapsulate fixture instances.
    Author:
    Rene Schneider - initial API and implementation
    • Field Detail

      • conversionContextProvider

        @Inject
        protected com.google.inject.Provider<ConversionContext> conversionContextProvider
        The conversion context provider.
    • Constructor Detail

      • FixtureWrapper

        public FixtureWrapper​(MethodReference aMethodReference,
                              com.google.inject.Injector anInjector)
                       throws java.lang.InstantiationException,
                              java.lang.IllegalAccessException,
                              java.lang.ClassNotFoundException
        Creates a new instance. This also instantiates the given fixture class!
        Parameters:
        aMethodReference - the fixture method reference to be wrapped
        anInjector - The injector required to inject dependencies into fixture instances and factories. (I don't really like to provide this explicitly here, but cannot use injection, since that happens after the constructor. Maybe I'll refactor this some time later...)
        Throws:
        java.lang.InstantiationException
        java.lang.IllegalAccessException
        java.lang.ClassNotFoundException
    • Method Detail

      • release

        public void release()
        Releases the fixture instance.
      • getFixtureClass

        protected java.lang.Class<?> getFixtureClass()
      • getFixtureInstance

        protected java.lang.Object getFixtureInstance()
      • isCustomComparatorFixture

        public boolean isCustomComparatorFixture()
        Checks whether the wrapped fixture is a CustomComparatorFixture.
        Returns:
        true if it is
      • isCustomComparatorAndConversionFixture

        public boolean isCustomComparatorAndConversionFixture()
        Checks whether the wrapped fixture is a CustomComparatorAndConversionFixture.
        Returns:
        true if it is
      • isCustomStringConversionFixture

        public boolean isCustomStringConversionFixture()
        Checks whether the wrapped fixture is a CustomStringConversionFixture.
        Returns:
        true if it is
      • isResultAwareFixture

        public boolean isResultAwareFixture()
        Checks whether the wrapped fixture is a ResultAwareFixture.
        Returns:
        true if it is
      • isFinalizationTestFixture

        public boolean isFinalizationTestFixture()
        Checks whether the wrapped fixture is a isFinalizationTestFixture().
        Returns:
        true if it is
      • performCustomComparation

        public ComparisonResult performCustomComparation​(java.lang.Object anExpectedResult,
                                                         java.lang.Object aFixtureResult,
                                                         java.lang.String aMethodName,
                                                         java.lang.String aPropertyName)
        Performs a custom comparation using the wrapped fixture, which must be a CustomComparatorFixture. Only usable if isCustomComparatorFixture() returns true.
        Parameters:
        anExpectedResult - the expected result
        aFixtureResult - the result actually returned by the fixture
        aMethodName - the name of the fixture method
        aPropertyName - the name of the result property to be compared (null if it's the default result)
        Returns:
        true if comparation was successful, false otherwise
      • determineCustomConversionTargetType

        public java.lang.Class<?> determineCustomConversionTargetType​(java.lang.Object aFixtureResult,
                                                                      java.lang.String aMethodName,
                                                                      java.lang.String aPropertyName)
        Returns the type to which the expected result (the data given in the test script) that corresponds to the given fixture result is to be converted. This can only be used for CustomComparatorAndConversionFixture instances, which can be checked via isCustomComparatorAndConversionFixture().
        Parameters:
        aFixtureResult - the result value returned by the fixture call
        aMethodName - the fixture method that was called
        aPropertyName - the property name that is to be compared (null if it's the default result)
        Returns:
        the desired target type. "null" chooses the default conversion, but note that this does NOT mean "the conversion that would have been used if the fixture was just a CustomComparatorFixture", but "the conversion that has the highest priority for the data type found in the script".
      • performValueToFormattedStringConversion

        public FormattedString performValueToFormattedStringConversion​(java.lang.Object aValue,
                                                                       java.lang.String aFixtureMethod,
                                                                       boolean aForceIntermediateMapFlag,
                                                                       ConversionContext aConversionContext)
        Converts the given value to a string. This method either calls the ValueConverter#convertValueToString(Object, ConversionContext) method or delegates the conversion to the contained fixture instance, if it does implement the CustomStringConversionFixture interface.
        Parameters:
        aValue - the value to convert
        aFixtureMethod - the fixture method that was called to return the given value
        aForceIntermediateMapFlag - whether the conversion should force the usage of an intermediate map (useful for bean types)
        aConversionContext - the conversion context to use (may be null if the default shall be used)
        Returns:
        the converted string
      • execute

        public java.lang.Object execute​(java.util.Map<java.lang.String,​java.lang.Object> someParameters)
                                 throws java.lang.Throwable
        Executes the fixture method, using the given set of parameters.
        Parameters:
        someParameters - a map of parameters
        Returns:
        the resulting object
        Throws:
        java.lang.Throwable
      • convertParameterValuesToFixtureDefinedTypes

        public void convertParameterValuesToFixtureDefinedTypes​(java.lang.reflect.Method aFixtureMethod,
                                                                java.util.Map<java.lang.String,​java.lang.Object> aParameterMap,
                                                                boolean anIncludeArbitraryParametersFlag)
                                                         throws ParameterUtil.UnresolvableVariableException,
                                                                java.lang.ClassNotFoundException,
                                                                UnexecutableException,
                                                                java.lang.InstantiationException
        Replaces all values in the given parameter map with converted versions that match the types that are expected by the given fixture method.
        Parameters:
        aFixtureMethod - the method
        aParameterMap - the parameter map
        anIncludeArbitraryParametersFlag - whether arbitrary parameters shall be included
        Throws:
        java.lang.InstantiationException
        UnexecutableException
        java.lang.ClassNotFoundException
        ParameterUtil.UnresolvableVariableException
      • performNullCheck

        protected void performNullCheck​(FixtureParameter anAnnotation,
                                        java.lang.Object aValue)
        Validates given parameter values to comply with the FixtureParameter.nullable() setting.
        Parameters:
        anAnnotation - the fixture parameter annotation setting the rules
        aValue - the parameter value
      • retrieveExtendedResults

        public java.util.List<ExtendedResultFixture.ExtendedResult> retrieveExtendedResults​(ExtendedResultFixture.FixtureInvocationResult anInvocationResult)
        Call ExtendedResultFixture#provideExtendedResults() on the fixture - if it is an extended result fixture - and return the extended results.
        Returns:
        the extended result list, or null if the fixture does not support the protocol or didn't return anything
      • announceTestResults

        public void announceTestResults​(ValueOrEnumValueOrOperationCollection aDefaultResult,
                                        java.util.List<NamedResult> someNamedResults)
        Invoke the ResultAwareFixture method for the case of a 'test' type fixture invocation, if the fixture is a ResultAwareFixture.
        Parameters:
        aDefaultResult - The default result as given in the test script
        someNamedResults - A list of named results used by the test
      • announceTableTestResults

        public void announceTableTestResults​(ValueOrEnumValueOrOperationCollection aDefaultResult,
                                             java.util.List<ResultTableHeader> someResultHeaders)
        Invoke the ResultAwareFixture method for the case of a 'tabletest' type fixture invocation.
        Parameters:
        aDefaultResult - The default result as given in the test script
        someResultHeaders - A list of named results used by the test
      • announceTestResultsInternal

        protected void announceTestResultsInternal​(ValueOrEnumValueOrOperationCollection aDefaultResult,
                                                   java.util.Set<java.lang.String> aNamedResultSet)
        Actually performs the test result announcement call.
        Parameters:
        aDefaultResult - The default result as given in the test script
        aNamedResultSet - A list of named results used by the test
      • runFinalizationTest

        public java.lang.String runFinalizationTest()
        Executes the finalization test for FinalizationTestFixtures.
        Returns:
        null if successful, an error message otherwise