Class TestFormatter
- java.lang.Object
-
- de.gebit.integrity.runner.callbacks.TestFormatter
-
public class TestFormatter extends java.lang.Object
TheTestFormatter
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 java.lang.String
NEWLINE
Newline separator.protected java.lang.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 java.lang.String
callToHumanReadableString(Call aCall, ConversionContext aConversionContext)
Creates a human-readable string for a call.protected java.util.Optional<FixtureMethod.I18NDescription>
findI18NDescription(FixtureMethod.I18NDescription[] someCandidates)
Finds apreferredDescriptionLocale
match from the providedFixtureMethod.I18NDescription
s.java.lang.String
fixtureMethodToHumanReadableString(MethodReference aFixtureMethod, SuiteStatementWithResult aStatement, java.util.Map<java.lang.String,java.lang.Object> someParameters, ConversionContext aConversionContext)
Creates a human-readable string for a fixture method.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.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 thePARAMETER_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(java.lang.String aPreferredLocale)
java.lang.String
tableTestRowToHumanReadableString(TableTest aTest, TableTestRow aRow, ConversionContext aConversionContext)
Creates a human-readable string for a tabletest.java.lang.String
tableTestToHumanReadableString(TableTest aTest, ConversionContext aConversionContext)
Creates a human-readable string for a tabletest.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 aSet
of test time info entries according totestTimeInfoToHumanReadableString(Entry, boolean)
.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.java.lang.String
testToHumanReadableString(Test aTest, ConversionContext aConversionContext)
Creates a human-readable string for a test.java.lang.String
timeDifferenceToHumanReadableString(TimeDifference aTimeDiff)
Converts aTimeDifference
to a human-readable string.java.lang.String
timeSetToHumanReadableString(TimeSet aTimeSet, java.util.List<ForkDefinition> someForks)
Converts aTimeSet
command to a human-readable description.java.lang.String
variableAssignmentToHumanReadableString(VariableAssignment anAssignment, ConversionContext aConversionContext)
Creates a human-readable string for a variable assignment.
-
-
-
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.
-
-
Method Detail
-
setPreferredDescriptionLocale
public void setPreferredDescriptionLocale(java.lang.String aPreferredLocale)
-
testToHumanReadableString
public java.lang.String testToHumanReadableString(Test aTest, ConversionContext aConversionContext) throws java.lang.ClassNotFoundException, UnexecutableException, java.lang.InstantiationException, MethodNotFoundException
Creates a human-readable string for a test.- Parameters:
aTest
- the test- Returns:
- the human-readable test description
- Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
UnexecutableException
MethodNotFoundException
-
tableTestRowToHumanReadableString
public java.lang.String tableTestRowToHumanReadableString(TableTest aTest, TableTestRow aRow, ConversionContext aConversionContext) throws java.lang.ClassNotFoundException, UnexecutableException, java.lang.InstantiationException, MethodNotFoundException
Creates a human-readable string for a tabletest.- Parameters:
aTest
- the testaRow
- the row (may be null if the string shall be for the whole test)- Returns:
- the human-readable description
- Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
UnexecutableException
MethodNotFoundException
-
tableTestToHumanReadableString
public java.lang.String tableTestToHumanReadableString(TableTest aTest, ConversionContext aConversionContext) throws java.lang.ClassNotFoundException, UnexecutableException, java.lang.InstantiationException, MethodNotFoundException
Creates a human-readable string for a tabletest.- Parameters:
aTest
- the test- Returns:
- the human-readable string
- Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
UnexecutableException
MethodNotFoundException
-
callToHumanReadableString
public java.lang.String callToHumanReadableString(Call aCall, ConversionContext aConversionContext) throws java.lang.ClassNotFoundException, UnexecutableException, java.lang.InstantiationException, MethodNotFoundException
Creates a human-readable string for a call.- Parameters:
aCall
- the call- Returns:
- the human-readable string
- Throws:
java.lang.ClassNotFoundException
java.lang.InstantiationException
UnexecutableException
MethodNotFoundException
-
variableAssignmentToHumanReadableString
public java.lang.String variableAssignmentToHumanReadableString(VariableAssignment anAssignment, ConversionContext aConversionContext)
Creates a human-readable string for a variable assignment.- Parameters:
anAssignment
- the assignmentaConversionContext
-- 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 methodaStatement
- the suite statement currently being executed, if knownsomeParameters
- a map of parameters used for the testaConversionContext
- the conversion context to use for conversion of parameters, if necessary- Returns:
- the human-readable string
- Throws:
java.lang.ClassNotFoundException
MethodNotFoundException
-
findI18NDescription
protected java.util.Optional<FixtureMethod.I18NDescription> findI18NDescription(FixtureMethod.I18NDescription[] someCandidates)
Finds apreferredDescriptionLocale
match from the providedFixtureMethod.I18NDescription
s.- Parameters:
someCandidates
-aLocale
-- Returns:
-
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 thePARAMETER_PATTERN
. Conditional statements may be nested.- Parameters:
anInput
- the text to start withsomeParameters
- 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 thePARAMETER_PATTERN
with their respective value.- Parameters:
anInput
- the text to start withsomeParameters
- the parametersaConversionContext
- 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 aTimeSet
command to a human-readable description.- Parameters:
aTimeSet
- the timeset command to convertsomeForks
- the forks onto which it is executed (null = master)- Returns:
-
timeDifferenceToHumanReadableString
public java.lang.String timeDifferenceToHumanReadableString(TimeDifference aTimeDiff)
Converts aTimeDifference
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 aSet
of test time info entries according totestTimeInfoToHumanReadableString(Entry, boolean)
.- Parameters:
aTestTimeInfoSet
-- Returns:
-
-