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:
  • 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)
      Specified by:
      generateDisplayNameForMethod in interface org.junit.jupiter.api.DisplayNameGenerator
      Overrides:
      generateDisplayNameForMethod in class org.junit.jupiter.api.DisplayNameGenerator.Standard
    • replaceCamelCaseAndUnderscoreAndNumber

      private String replaceCamelCaseAndUnderscoreAndNumber(String input)
    • formatCamelCase

      private String formatCamelCase(String in)
    • hasParameters

      private boolean hasParameters(Method method)