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 generator generates display names that build up complete sentences by concatenating the names of the test and the enclosing classes. The sentence fragments are concatenated using a separator. The separator and the display name generator for individual sentence fragments can be configured via the @IndicativeSentencesGeneration 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)
      • getFragmentSeparator

        private static java.lang.String getFragmentSeparator​(java.lang.Class<?> testClass)
        Get the sentence fragment separator.

        If @IndicativeSentencesGeneration is present (searching enclosing classes if not found locally), the configured separator will be used. Otherwise, IndicativeSentencesGeneration.DEFAULT_SEPARATOR will be used.

        Parameters:
        testClass - the test class to search on for @IndicativeSentencesGeneration
        Returns:
        the sentence fragment separator
      • findDisplayNameGeneration

        private static java.util.Optional<DisplayNameGeneration> findDisplayNameGeneration​(java.lang.Class<?> testClass)
        Find the first DisplayNameGeneration annotation that is either directly present, meta-present, or indirectly present on the supplied testClass or on an enclosing class.
        Parameters:
        testClass - the test class on which to find the annotation; never null
        Returns:
        an Optional containing the annotation, potentially empty if not found
      • findIndicativeSentencesGeneration

        private static java.util.Optional<IndicativeSentencesGeneration> findIndicativeSentencesGeneration​(java.lang.Class<?> testClass)
        Find the first IndicativeSentencesGeneration annotation that is either directly present, meta-present, or indirectly present on the supplied testClass or on an enclosing class.
        Parameters:
        testClass - the test class on which to find the annotation; never null
        Returns:
        an Optional containing the annotation, potentially empty if not found
      • not

        private static java.util.function.Predicate<java.lang.Class<?>> not​(java.lang.Class<?> clazz)