Class TestFormatter
- java.lang.Object
-
- de.gebit.integrity.runner.callbacks.TestFormatter
-
public class TestFormatter extends Object
TheTestFormatteris 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>conversionContextProviderThe conversion context provider.static StringNEWLINENewline separator.protected StringpreferredDescriptionLocaleThe 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 StringcallToHumanReadableString(Call aCall, ConversionContext aConversionContext)Creates a human-readable string for a call.protected Optional<FixtureMethod.I18NDescription>findI18NDescription(FixtureMethod.I18NDescription[] someCandidates)Finds apreferredDescriptionLocalematch from the providedFixtureMethod.I18NDescriptions.StringfixtureMethodToHumanReadableString(MethodReference aFixtureMethod, SuiteStatementWithResult aStatement, Map<String,Object> someParameters, ConversionContext aConversionContext)Creates a human-readable string for a fixture method.protected StringreplaceConditionalTextBlocks(String anInput, Map<String,Object> someParameters)Replaces all blocks of conditional text.protected StringreplaceParameters(String anInput, Map<String,Object> someParameters, ConversionContext aConversionContext)Replaces all parameters according to thePARAMETER_PATTERNwith their respective value.ConversionContextsafeguardConversionContext(ConversionContext aContext)This method creates a default conversion context in case none is provided, and returns the provided context otherwise.voidsetPreferredDescriptionLocale(String aPreferredLocale)StringtableTestRowToHumanReadableString(TableTest aTest, TableTestRow aRow, ConversionContext aConversionContext)Creates a human-readable string for a tabletest.StringtableTestToHumanReadableString(TableTest aTest, ConversionContext aConversionContext)Creates a human-readable string for a tabletest.StringtestTimeInfoSetToHumanReadableString(Set<Map.Entry<String,org.eclipse.xtext.util.Pair<ZonedDateTime,Double>>> aTestTimeInfoSet)Converts aSetof test time info entries according totestTimeInfoToHumanReadableString(Entry, boolean).StringtestTimeInfoToHumanReadableString(Map.Entry<String,org.eclipse.xtext.util.Pair<ZonedDateTime,Double>> aTestTimeInfoEntry, boolean anIncludePrefixFlag)Converts a test time info entry to a human-readable string.StringtestToHumanReadableString(Test aTest, ConversionContext aConversionContext)Creates a human-readable string for a test.StringtimeDifferenceToHumanReadableString(TimeDifference aTimeDiff)Converts aTimeDifferenceto a human-readable string.StringtimeSetToHumanReadableString(TimeSet aTimeSet, List<ForkDefinition> someForks)Converts aTimeSetcommand to a human-readable description.StringvariableAssignmentToHumanReadableString(VariableAssignment anAssignment, ConversionContext aConversionContext)Creates a human-readable string for a variable assignment.
-
-
-
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.
-
-
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:
ClassNotFoundExceptionInstantiationExceptionUnexecutableExceptionMethodNotFoundException
-
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 testaRow- the row (may be null if the string shall be for the whole test)- Returns:
- the human-readable description
- Throws:
ClassNotFoundExceptionInstantiationExceptionUnexecutableExceptionMethodNotFoundException
-
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:
ClassNotFoundExceptionInstantiationExceptionUnexecutableExceptionMethodNotFoundException
-
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:
ClassNotFoundExceptionInstantiationExceptionUnexecutableExceptionMethodNotFoundException
-
variableAssignmentToHumanReadableString
public 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 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 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:
ClassNotFoundExceptionMethodNotFoundException
-
findI18NDescription
protected Optional<FixtureMethod.I18NDescription> findI18NDescription(FixtureMethod.I18NDescription[] someCandidates)
Finds apreferredDescriptionLocalematch from the providedFixtureMethod.I18NDescriptions.- 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 thePARAMETER_PATTERN. Conditional statements may be nested.- Parameters:
anInput- the text to start withsomeParameters- the parameters- Returns:
- the resulting text
-
replaceParameters
protected String replaceParameters(String anInput, Map<String,Object> someParameters, ConversionContext aConversionContext)
Replaces all parameters according to thePARAMETER_PATTERNwith 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 String timeSetToHumanReadableString(TimeSet aTimeSet, List<ForkDefinition> someForks)
Converts aTimeSetcommand to a human-readable description.- Parameters:
aTimeSet- the timeset command to convertsomeForks- the forks onto which it is executed (null = master)- Returns:
-
timeDifferenceToHumanReadableString
public String timeDifferenceToHumanReadableString(TimeDifference aTimeDiff)
Converts aTimeDifferenceto 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 aSetof test time info entries according totestTimeInfoToHumanReadableString(Entry, boolean).- Parameters:
aTestTimeInfoSet-- Returns:
-
-