Package de.gebit.integrity.runner.callbacks

## Class TestFormatter

- java.lang.Object
- - de.gebit.integrity.runner.callbacks.TestFormatter

-     public class TestFormatter
      extends Object

  The `TestFormatter` is responsible for creating human-readable strings out of various test-related entities. This is usually done by using the descriptions attached to fixtures.
  Author:
    Rene Schneider - initial API and implementation

- - ### Field Summary

    Fields
    Modifier and Type | Field | Description
    --- | --- | ---
    `protected com.google.inject.Provider<ConversionContext>` | `conversionContextProvider` | The conversion context provider.
    `static String` | `NEWLINE` | Newline separator.
    `protected String` | `preferredDescriptionLocale` | The preferred locale of fixture descriptions to be used during formatting.

  - ### Constructor Summary

    Constructors
    Constructor | Description
    --- | ---
    `TestFormatter()` | Creates a new instance.

  - ### Method Summary

    All Methods Instance Methods Concrete Methods
    Modifier and Type | Method | Description
    --- | --- | ---
    `String` | `callToHumanReadableString​(Call aCall, ConversionContext aConversionContext)` | Creates a human-readable string for a call.
    `protected Optional<FixtureMethod.I18NDescription>` | `findI18NDescription​(FixtureMethod.I18NDescription[] someCandidates)` | Finds a `preferredDescriptionLocale` match from the provided `FixtureMethod.I18NDescription`s.
    `String` | `fixtureMethodToHumanReadableString​(MethodReference aFixtureMethod, SuiteStatementWithResult aStatement, Map<String,​Object> someParameters, ConversionContext aConversionContext)` | Creates a human-readable string for a fixture method.
    `protected String` | `replaceConditionalTextBlocks​(String anInput, Map<String,​Object> someParameters)` | Replaces all blocks of conditional text.
    `protected String` | `replaceParameters​(String anInput, Map<String,​Object> someParameters, ConversionContext aConversionContext)` | Replaces all parameters according to the `PARAMETER_PATTERN` with their respective value.
    `ConversionContext` | `safeguardConversionContext​(ConversionContext aContext)` | This method creates a default conversion context in case none is provided, and returns the provided context otherwise.
    `void` | `setPreferredDescriptionLocale​(String aPreferredLocale)` |
    `String` | `tableTestRowToHumanReadableString​(TableTest aTest, TableTestRow aRow, ConversionContext aConversionContext)` | Creates a human-readable string for a tabletest.
    `String` | `tableTestToHumanReadableString​(TableTest aTest, ConversionContext aConversionContext)` | Creates a human-readable string for a tabletest.
    `String` | `testTimeInfoSetToHumanReadableString​(Set<Map.Entry<String,​org.eclipse.xtext.util.Pair<ZonedDateTime,​Double>>> aTestTimeInfoSet)` | Converts a `Set` of test time info entries according to `testTimeInfoToHumanReadableString(Entry, boolean)`.
    `String` | `testTimeInfoToHumanReadableString​(Map.Entry<String,​org.eclipse.xtext.util.Pair<ZonedDateTime,​Double>> aTestTimeInfoEntry, boolean anIncludePrefixFlag)` | Converts a test time info entry to a human-readable string.
    `String` | `testToHumanReadableString​(Test aTest, ConversionContext aConversionContext)` | Creates a human-readable string for a test.
    `String` | `timeDifferenceToHumanReadableString​(TimeDifference aTimeDiff)` | Converts a `TimeDifference` to a human-readable string.
    `String` | `timeSetToHumanReadableString​(TimeSet aTimeSet, List<ForkDefinition> someForks)` | Converts a `TimeSet` command to a human-readable description.
    `String` | `variableAssignmentToHumanReadableString​(VariableAssignment anAssignment, ConversionContext aConversionContext)` | Creates a human-readable string for a variable assignment.

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

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

- - ### Field Detail

    - #### NEWLINE

          public static final String NEWLINE

      Newline separator.

    - #### conversionContextProvider

          @Inject
          protected com.google.inject.Provider<ConversionContext> conversionContextProvider

      The conversion context provider.

    - #### preferredDescriptionLocale

          protected String preferredDescriptionLocale

      The preferred locale of fixture descriptions to be used during formatting.

  - ### Constructor Detail

    - #### TestFormatter

          public TestFormatter()

      Creates a new instance.

  - ### Method Detail

    - #### setPreferredDescriptionLocale

          public void setPreferredDescriptionLocale​(String aPreferredLocale)

    - #### testToHumanReadableString

          public String testToHumanReadableString​(Test aTest,
                                                  ConversionContext aConversionContext)
                                           throws ClassNotFoundException,
                                                  UnexecutableException,
                                                  InstantiationException,
                                                  MethodNotFoundException

      Creates a human-readable string for a test.
      Parameters:
        `aTest` - the test
      Returns:
        the human-readable test description
      Throws:
        `ClassNotFoundException`
        `InstantiationException`
        `UnexecutableException`
        `MethodNotFoundException`

    - #### tableTestRowToHumanReadableString

          public String tableTestRowToHumanReadableString​(TableTest aTest,
                                                          TableTestRow aRow,
                                                          ConversionContext aConversionContext)
                                                   throws ClassNotFoundException,
                                                          UnexecutableException,
                                                          InstantiationException,
                                                          MethodNotFoundException

      Creates a human-readable string for a tabletest.
      Parameters:
        `aTest` - the test
        `aRow` - the row (may be null if the string shall be for the whole test)
      Returns:
        the human-readable description
      Throws:
        `ClassNotFoundException`
        `InstantiationException`
        `UnexecutableException`
        `MethodNotFoundException`

    - #### tableTestToHumanReadableString

          public String tableTestToHumanReadableString​(TableTest aTest,
                                                       ConversionContext aConversionContext)
                                                throws ClassNotFoundException,
                                                       UnexecutableException,
                                                       InstantiationException,
                                                       MethodNotFoundException

      Creates a human-readable string for a tabletest.
      Parameters:
        `aTest` - the test
      Returns:
        the human-readable string
      Throws:
        `ClassNotFoundException`
        `InstantiationException`
        `UnexecutableException`
        `MethodNotFoundException`

    - #### callToHumanReadableString

          public String callToHumanReadableString​(Call aCall,
                                                  ConversionContext aConversionContext)
                                           throws ClassNotFoundException,
                                                  UnexecutableException,
                                                  InstantiationException,
                                                  MethodNotFoundException

      Creates a human-readable string for a call.
      Parameters:
        `aCall` - the call
      Returns:
        the human-readable string
      Throws:
        `ClassNotFoundException`
        `InstantiationException`
        `UnexecutableException`
        `MethodNotFoundException`

    - #### variableAssignmentToHumanReadableString

          public String variableAssignmentToHumanReadableString​(VariableAssignment anAssignment,
                                                                ConversionContext aConversionContext)

      Creates a human-readable string for a variable assignment.
      Parameters:
        `anAssignment` - the assignment
        `aConversionContext` -
      Returns:
        the human-readable string

    - #### fixtureMethodToHumanReadableString

          public String fixtureMethodToHumanReadableString​(MethodReference aFixtureMethod,
                                                           SuiteStatementWithResult aStatement,
                                                           Map<String,​Object> someParameters,
                                                           ConversionContext aConversionContext)
                                                    throws ClassNotFoundException,
                                                           MethodNotFoundException

      Creates a human-readable string for a fixture method.
      Parameters:
        `aFixtureMethod` - the fixture method
        `aStatement` - the suite statement currently being executed, if known
        `someParameters` - a map of parameters used for the test
        `aConversionContext` - the conversion context to use for conversion of parameters, if necessary
      Returns:
        the human-readable string
      Throws:
        `ClassNotFoundException`
        `MethodNotFoundException`

    - #### findI18NDescription

          protected Optional<FixtureMethod.I18NDescription> findI18NDescription​(FixtureMethod.I18NDescription[] someCandidates)

      Finds a `preferredDescriptionLocale` match from the provided `FixtureMethod.I18NDescription`s.
      Parameters:
        `someCandidates` -
        `aLocale` -
      Returns:

    - #### replaceConditionalTextBlocks

          protected String replaceConditionalTextBlocks​(String anInput,
                                                        Map<String,​Object> someParameters)

      Replaces all blocks of conditional text. The syntax for these looks like this:<
      {someParameterName?some conditional text} or {^someParameterName?some conditional text}
      The first statement prints 'some conditional text' if the parameter 'someParameterName' is set to a value. The latter prints the text if the parameter is NOT set to a value (negation of the first example).
      Parameters may be used in the text itself according to the `PARAMETER_PATTERN`. Conditional statements may be nested.
      Parameters:
        `anInput` - the text to start with
        `someParameters` - the parameters
      Returns:
        the resulting text

    - #### replaceParameters

          protected String replaceParameters​(String anInput,
                                             Map<String,​Object> someParameters,
                                             ConversionContext aConversionContext)

      Replaces all parameters according to the `PARAMETER_PATTERN` with their respective value.
      Parameters:
        `anInput` - the text to start with
        `someParameters` - the parameters
        `aConversionContext` - the conversion context to use for conversion of parameters, if necessary
      Returns:
        the resulting text

    - #### safeguardConversionContext

          public ConversionContext safeguardConversionContext​(ConversionContext aContext)

      This method creates a default conversion context in case none is provided, and returns the provided context otherwise.
      Parameters:
        `aContext` - the context to safeguard
      Returns:
        a context (guaranteed not to return null)

    - #### timeSetToHumanReadableString

          public String timeSetToHumanReadableString​(TimeSet aTimeSet,
                                                     List<ForkDefinition> someForks)

      Converts a `TimeSet` command to a human-readable description.
      Parameters:
        `aTimeSet` - the timeset command to convert
        `someForks` - the forks onto which it is executed (null = master)
      Returns:

    - #### timeDifferenceToHumanReadableString

          public String timeDifferenceToHumanReadableString​(TimeDifference aTimeDiff)

      Converts a `TimeDifference` to a human-readable string.
      Parameters:
        `aTimeDiff` - the command to convert
      Returns:

    - #### testTimeInfoToHumanReadableString

          public String testTimeInfoToHumanReadableString​(Map.Entry<String,​org.eclipse.xtext.util.Pair<ZonedDateTime,​Double>> aTestTimeInfoEntry,
                                                          boolean anIncludePrefixFlag)

      Converts a test time info entry to a human-readable string.
      Parameters:
        `aTestTimeInfoEntry` -
        `anOmitPrefixFlag` -
      Returns:

    - #### testTimeInfoSetToHumanReadableString

          public String testTimeInfoSetToHumanReadableString​(Set<Map.Entry<String,​org.eclipse.xtext.util.Pair<ZonedDateTime,​Double>>> aTestTimeInfoSet)

      Converts a `Set` of test time info entries according to `testTimeInfoToHumanReadableString(Entry, boolean)`.
      Parameters:
        `aTestTimeInfoSet` -
      Returns: