Class ReplaceCamelCaseAndUnderscoreAndNumber

  • All Implemented Interfaces:
    org.junit.jupiter.api.DisplayNameGenerator

    public class ReplaceCamelCaseAndUnderscoreAndNumber
    extends org.junit.jupiter.api.DisplayNameGenerator.Standard

    A class extending DisplayNameGenerator.Standard.

    This extension handles method names with CamelCase, underscore and numbers.

    The aim is to simplify unit test display names. Instead of using this method annotation DisplayName, we can just use this class annotation DisplayNameGeneration and use that method annotation if needed.

    This generator follows 3 rules:

    • Each uppercase letter is turned into its lowercase value prepended by space.
    • Each underscore is turned into space. Words bounded by underscores or just starting with underscore are not transformed. Usually these words represent classes, variables...
    • Each number is prepended by space.

    Usage example:

    
     @DisplayNameGeneration(ReplaceCamelCaseAndUnderscoreAndNumber.class)
     class ExampleTest {}
     
    Since:
    2.3.0
    See Also:
    DisplayNameGenerator.Standard, Usage example of ReplaceCamelCaseAndUnderscoreAndNumber
    • Nested Class Summary

      • Nested classes/interfaces inherited from interface org.junit.jupiter.api.DisplayNameGenerator

        org.junit.jupiter.api.DisplayNameGenerator.IndicativeSentences, org.junit.jupiter.api.DisplayNameGenerator.ReplaceUnderscores, org.junit.jupiter.api.DisplayNameGenerator.Simple, org.junit.jupiter.api.DisplayNameGenerator.Standard
    • Field Summary

      Fields 
      Modifier and Type Field Description
      static org.junit.jupiter.api.DisplayNameGenerator INSTANCE  
      • Fields inherited from interface org.junit.jupiter.api.DisplayNameGenerator

        DEFAULT_GENERATOR_PROPERTY_NAME
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      private java.lang.String formatCamelCase​(java.lang.String in)  
      java.lang.String generateDisplayNameForMethod​(java.lang.Class<?> testClass, java.lang.reflect.Method testMethod)  
      private boolean hasParameters​(java.lang.reflect.Method method)  
      private java.lang.String replaceCamelCaseAndUnderscoreAndNumber​(java.lang.String input)  
      • Methods inherited from class org.junit.jupiter.api.DisplayNameGenerator.Standard

        generateDisplayNameForClass, generateDisplayNameForNestedClass
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • INSTANCE

        public static final org.junit.jupiter.api.DisplayNameGenerator INSTANCE
    • Constructor Detail

      • ReplaceCamelCaseAndUnderscoreAndNumber

        private ReplaceCamelCaseAndUnderscoreAndNumber()
    • Method Detail

      • generateDisplayNameForMethod

        public java.lang.String generateDisplayNameForMethod​(java.lang.Class<?> testClass,
                                                             java.lang.reflect.Method testMethod)
        Specified by:
        generateDisplayNameForMethod in interface org.junit.jupiter.api.DisplayNameGenerator
        Overrides:
        generateDisplayNameForMethod in class org.junit.jupiter.api.DisplayNameGenerator.Standard
      • replaceCamelCaseAndUnderscoreAndNumber

        private java.lang.String replaceCamelCaseAndUnderscoreAndNumber​(java.lang.String input)
      • formatCamelCase

        private java.lang.String formatCamelCase​(java.lang.String in)
      • hasParameters

        private boolean hasParameters​(java.lang.reflect.Method method)