Class TestFormatter


  • public class TestFormatter
    extends java.lang.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 Detail

      • NEWLINE

        public static final java.lang.String NEWLINE
        Newline separator.
      • conversionContextProvider

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

        protected java.lang.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​(java.lang.String aPreferredLocale)
      • variableAssignmentToHumanReadableString

        public java.lang.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 java.lang.String fixtureMethodToHumanReadableString​(MethodReference aFixtureMethod,
                                                                   SuiteStatementWithResult aStatement,
                                                                   java.util.Map<java.lang.String,​java.lang.Object> someParameters,
                                                                   ConversionContext aConversionContext)
                                                            throws java.lang.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:
        java.lang.ClassNotFoundException
        MethodNotFoundException
      • replaceConditionalTextBlocks

        protected java.lang.String replaceConditionalTextBlocks​(java.lang.String anInput,
                                                                java.util.Map<java.lang.String,​java.lang.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 java.lang.String replaceParameters​(java.lang.String anInput,
                                                     java.util.Map<java.lang.String,​java.lang.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 java.lang.String timeSetToHumanReadableString​(TimeSet aTimeSet,
                                                             java.util.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 java.lang.String timeDifferenceToHumanReadableString​(TimeDifference aTimeDiff)
        Converts a TimeDifference to a human-readable string.
        Parameters:
        aTimeDiff - the command to convert
        Returns:
      • testTimeInfoToHumanReadableString

        public java.lang.String testTimeInfoToHumanReadableString​(java.util.Map.Entry<java.lang.String,​org.eclipse.xtext.util.Pair<java.time.ZonedDateTime,​java.lang.Double>> aTestTimeInfoEntry,
                                                                  boolean anIncludePrefixFlag)
        Converts a test time info entry to a human-readable string.
        Parameters:
        aTestTimeInfoEntry -
        anOmitPrefixFlag -
        Returns:
      • testTimeInfoSetToHumanReadableString

        public java.lang.String testTimeInfoSetToHumanReadableString​(java.util.Set<java.util.Map.Entry<java.lang.String,​org.eclipse.xtext.util.Pair<java.time.ZonedDateTime,​java.lang.Double>>> aTestTimeInfoSet)
        Converts a Set of test time info entries according to testTimeInfoToHumanReadableString(Entry, boolean).
        Parameters:
        aTestTimeInfoSet -
        Returns: