Interface DisplayNameGenerator

All Known Implementing Classes:
DisplayNameGenerator.IndicativeSentences, DisplayNameGenerator.ReplaceUnderscores, DisplayNameGenerator.Simple, DisplayNameGenerator.Standard

@API(status=STABLE,
     since="5.7")
public interface DisplayNameGenerator
DisplayNameGenerator defines the SPI for generating display names programmatically.

Display names are typically used for test reporting in IDEs and build tools and may contain spaces, special characters, and even emoji.

Concrete implementations must have a default constructor.

Since:
5.4
See Also:
@DisplayName, @DisplayNameGeneration
  • Nested Class Summary

    Nested Classes
    Modifier and Type Interface Description
    static class  DisplayNameGenerator.IndicativeSentences
    DisplayNameGenerator that generates complete sentences.
    static class  DisplayNameGenerator.ReplaceUnderscores
    DisplayNameGenerator that replaces underscores with spaces.
    static class  DisplayNameGenerator.Simple
    Simple DisplayNameGenerator that removes trailing parentheses for methods with no parameters.
    static class  DisplayNameGenerator.Standard
    Standard DisplayNameGenerator.
  • Method Summary

    Modifier and Type Method Description
    java.lang.String generateDisplayNameForClass​(java.lang.Class<?> testClass)
    Generate a display name for the given top-level or static nested test class.
    java.lang.String generateDisplayNameForMethod​(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)
    Generate a display name for the given method.
    java.lang.String generateDisplayNameForNestedClass​(java.lang.Class<?> nestedClass)
    Generate a display name for the given @Nested inner test class.
    static DisplayNameGenerator getDisplayNameGenerator​(java.lang.Class<?> generatorClass)
    Return the DisplayNameGenerator instance corresponding to the given Class.
    static java.lang.String parameterTypesAsString​(java.lang.reflect.Method method)
    Generate a string representation of the formal parameters of the supplied method, consisting of the simple names of the parameter types, separated by commas, and enclosed in parentheses.
  • Method Details

    • generateDisplayNameForClass

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

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

      java.lang.String generateDisplayNameForMethod​(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)
      Generate a display name for the given method.
      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
      Implementation Note:
      The class instance supplied as testClass may differ from the class returned by testMethod.getDeclaringClass() — for example, when a test method is inherited from a superclass.
    • parameterTypesAsString

      static java.lang.String parameterTypesAsString​(java.lang.reflect.Method method)
      Generate a string representation of the formal parameters of the supplied method, consisting of the simple names of the parameter types, separated by commas, and enclosed in parentheses.
      Parameters:
      method - the method from to extract the parameter types from; never null
      Returns:
      a string representation of all parameter types of the supplied method or "()" if the method declares no parameters
    • getDisplayNameGenerator

      static DisplayNameGenerator getDisplayNameGenerator​(java.lang.Class<?> generatorClass)
      Return the DisplayNameGenerator instance corresponding to the given Class.
      Parameters:
      generatorClass - the generator's Class; never null, has to be a DisplayNameGenerator implementation
      Returns:
      a DisplayNameGenerator implementation instance