Class ReplaceCamelCaseAndUnderscoreAndNumber

java.lang.Object
org.junit.jupiter.api.DisplayNameGenerator.Standard
org.junitpioneer.jupiter.displaynamegenerator.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:
  • 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 final org.junit.jupiter.api.DisplayNameGenerator
     

    Fields inherited from interface org.junit.jupiter.api.DisplayNameGenerator

    DEFAULT_GENERATOR_PROPERTY_NAME
  • Constructor Summary

    Constructors
    Modifier
    Constructor
    Description
    private
     
  • Method Summary

    Modifier and Type
    Method
    Description
    private String
     
    generateDisplayNameForMethod(Class<?> testClass, Method testMethod)
     
    private boolean
     
    private String
     

    Methods inherited from class org.junit.jupiter.api.DisplayNameGenerator.Standard

    generateDisplayNameForClass, generateDisplayNameForMethod, generateDisplayNameForNestedClass

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait

    Methods inherited from interface org.junit.jupiter.api.DisplayNameGenerator

    generateDisplayNameForNestedClass
  • Field Details

    • INSTANCE

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

    • ReplaceCamelCaseAndUnderscoreAndNumber

      private ReplaceCamelCaseAndUnderscoreAndNumber()
  • Method Details

    • generateDisplayNameForMethod

      public String generateDisplayNameForMethod(Class<?> testClass, Method testMethod)
    • replaceCamelCaseAndUnderscoreAndNumber

      private String replaceCamelCaseAndUnderscoreAndNumber(String input)
    • formatCamelCase

      private String formatCamelCase(String in)
    • hasParameters

      private boolean hasParameters(Method method)