Class 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 DisplayNameGenerator
    DisplayNameGenerator that generates complete sentences.

    This implements the functionality of DisplayNameGenerator by generating complete sentences display names, these sentences are divided with a separator, and the generator and separator can be customisable by using the IndicativeSentencesGeneration interface as annotation.

    Since:
    5.7
    • Constructor Detail

      • IndicativeSentences

        public IndicativeSentences()
    • Method Detail

      • generateDisplayNameForClass

        public java.lang.String generateDisplayNameForClass​(java.lang.Class<?> testClass)
        Description copied from interface: DisplayNameGenerator
        Generate a display name for the given top-level or static nested test class.
        Specified by:
        generateDisplayNameForClass in interface DisplayNameGenerator
        Parameters:
        testClass - the class to generate a name for; never null
        Returns:
        the display name for the class; never null or blank
      • generateDisplayNameForNestedClass

        public java.lang.String generateDisplayNameForNestedClass​(java.lang.Class<?> nestedClass)
        Description copied from interface: DisplayNameGenerator
        Generate a display name for the given @Nested inner test class.
        Specified by:
        generateDisplayNameForNestedClass in interface DisplayNameGenerator
        Parameters:
        nestedClass - the class to generate a name for; never null
        Returns:
        the display name for the nested class; never null or blank
      • generateDisplayNameForMethod

        public java.lang.String generateDisplayNameForMethod​(java.lang.Class<?> testClass,
                                                             java.lang.reflect.Method testMethod)
        Description copied from interface: DisplayNameGenerator
        Generate a display name for the given method.
        Specified by:
        generateDisplayNameForMethod in interface DisplayNameGenerator
        Parameters:
        testClass - the class the test method is invoked on; never null
        testMethod - method to generate a display name for; never null
        Returns:
        the display name for the test; never null or blank
      • getSentenceBeginning

        private java.lang.String getSentenceBeginning​(java.lang.Class<?> testClass)
      • getSentenceSeparator

        private java.lang.String getSentenceSeparator​(java.lang.Class<?> testClass)
        Gets the separator for IndicativeSentencesGeneration when extracting the annotation from IndicativeSentencesGeneration, 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 for IndicativeSentencesGeneration when extracting the annotation from IndicativeSentencesGeneration, if it doesn't find it, then search for the parent classes, if no generator value is found use DisplayNameGenerator.Standard by default.
        Parameters:
        testClass - Class to get Indicative sentence generator either custom or default
        Returns:
        the DisplayNameGenerator instance to use in indicative sentences generator
      • getIndicativeSentencesGeneration

        private java.util.Optional<IndicativeSentencesGeneration> getIndicativeSentencesGeneration​(java.lang.Class<?> testClass)
        Finds the IndicativeSentencesGeneration annotation 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 the IndicativeSentencesGeneration annotation
        Returns:
        the optional annotation retrieved from the test class.