Package org.junit.jupiter.api
Class DisplayNameGenerator.IndicativeSentences
- java.lang.Object
-
- org.junit.jupiter.api.DisplayNameGenerator.IndicativeSentences
-
- All Implemented Interfaces:
DisplayNameGenerator
- Enclosing interface:
- DisplayNameGenerator
@API(status=EXPERIMENTAL, since="5.7") public static class DisplayNameGenerator.IndicativeSentences extends java.lang.Object implements DisplayNameGeneratorDisplayNameGeneratorthat generates complete sentences.This implements the functionality of
DisplayNameGeneratorby generating complete sentences display names, these sentences are divided with a separator, and the generator and separator can be customisable by using theIndicativeSentencesGenerationinterface as annotation.- Since:
- 5.7
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface org.junit.jupiter.api.DisplayNameGenerator
DisplayNameGenerator.IndicativeSentences, DisplayNameGenerator.ReplaceUnderscores, DisplayNameGenerator.Simple, DisplayNameGenerator.Standard
-
-
Field Summary
Fields Modifier and Type Field Description (package private) static DisplayNameGeneratorINSTANCE
-
Constructor Summary
Constructors Constructor Description IndicativeSentences()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description java.lang.StringgenerateDisplayNameForClass(java.lang.Class<?> testClass)Generate a display name for the given top-level orstaticnested test class.java.lang.StringgenerateDisplayNameForMethod(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)Generate a display name for the given method.java.lang.StringgenerateDisplayNameForNestedClass(java.lang.Class<?> nestedClass)Generate a display name for the given@Nestedinner test class.private DisplayNameGeneratorgetGeneratorForIndicativeSentence(java.lang.Class<?> testClass)Gets the generator forIndicativeSentencesGenerationwhen extracting the annotation fromIndicativeSentencesGeneration, if it doesn't find it, then search for the parent classes, if no generator value is found useDisplayNameGenerator.Standardby default.private java.util.Optional<IndicativeSentencesGeneration>getIndicativeSentencesGeneration(java.lang.Class<?> testClass)Finds theIndicativeSentencesGenerationannotation that is present, meta-present or if it doesn't find it, then search for the enclosing parent classes, if no annotation is found returns empty.private java.lang.StringgetSentenceBeginning(java.lang.Class<?> testClass)private java.lang.StringgetSentenceSeparator(java.lang.Class<?> testClass)Gets the separator forIndicativeSentencesGenerationwhen extracting the annotation fromIndicativeSentencesGeneration, if it doesn't find it, then search for the parent classes, if no separator is found use @code{", "} by default.
-
-
-
Field Detail
-
INSTANCE
static final DisplayNameGenerator INSTANCE
-
-
Method Detail
-
generateDisplayNameForClass
public java.lang.String generateDisplayNameForClass(java.lang.Class<?> testClass)
Description copied from interface:DisplayNameGeneratorGenerate a display name for the given top-level orstaticnested test class.- Specified by:
generateDisplayNameForClassin interfaceDisplayNameGenerator- Parameters:
testClass- the class to generate a name for; nevernull- Returns:
- the display name for the class; never
nullor blank
-
generateDisplayNameForNestedClass
public java.lang.String generateDisplayNameForNestedClass(java.lang.Class<?> nestedClass)
Description copied from interface:DisplayNameGeneratorGenerate a display name for the given@Nestedinner test class.- Specified by:
generateDisplayNameForNestedClassin interfaceDisplayNameGenerator- Parameters:
nestedClass- the class to generate a name for; nevernull- Returns:
- the display name for the nested class; never
nullor blank
-
generateDisplayNameForMethod
public java.lang.String generateDisplayNameForMethod(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)Description copied from interface:DisplayNameGeneratorGenerate a display name for the given method.- Specified by:
generateDisplayNameForMethodin interfaceDisplayNameGenerator- Parameters:
testClass- the class the test method is invoked on; nevernulltestMethod- method to generate a display name for; nevernull- Returns:
- the display name for the test; never
nullor blank
-
getSentenceBeginning
private java.lang.String getSentenceBeginning(java.lang.Class<?> testClass)
-
getSentenceSeparator
private java.lang.String getSentenceSeparator(java.lang.Class<?> testClass)
Gets the separator forIndicativeSentencesGenerationwhen extracting the annotation fromIndicativeSentencesGeneration, if it doesn't find it, then search for the parent classes, if no separator is found use @code{", "} by default.- Parameters:
testClass- Class to get Indicative sentence annotation separator either custom or default- Returns:
- the indicative sentence separator
-
getGeneratorForIndicativeSentence
private DisplayNameGenerator getGeneratorForIndicativeSentence(java.lang.Class<?> testClass)
Gets the generator forIndicativeSentencesGenerationwhen extracting the annotation fromIndicativeSentencesGeneration, if it doesn't find it, then search for the parent classes, if no generator value is found useDisplayNameGenerator.Standardby default.- Parameters:
testClass- Class to get Indicative sentence generator either custom or default- Returns:
- the
DisplayNameGeneratorinstance to use in indicative sentences generator
-
getIndicativeSentencesGeneration
private java.util.Optional<IndicativeSentencesGeneration> getIndicativeSentencesGeneration(java.lang.Class<?> testClass)
Finds theIndicativeSentencesGenerationannotation that is present, meta-present or if it doesn't find it, then search for the enclosing parent classes, if no annotation is found returns empty.- Parameters:
testClass- the test class to find theIndicativeSentencesGenerationannotation- Returns:
- the optional annotation retrieved from the test class.
-
-