Class ComparingSnakeOrCamelCaseFields

java.lang.Object
org.assertj.core.api.recursive.comparison.ComparingNormalizedFields
org.assertj.core.api.recursive.comparison.ComparingSnakeOrCamelCaseFields
All Implemented Interfaces:
RecursiveComparisonIntrospectionStrategy

public class ComparingSnakeOrCamelCaseFields extends ComparingNormalizedFields
A RecursiveComparisonIntrospectionStrategy that transforms snake case field names into camel case.

The normalization also normalize uppercase acronyms by keeping only the first acronym letter uppercase so that profile_url and profileURL can be matched, both being normalized to profileUrl.

Since:
3.24.0
  • Field Details

  • Constructor Details

    • ComparingSnakeOrCamelCaseFields

      public ComparingSnakeOrCamelCaseFields()
  • Method Details

    • normalizeFieldName

      public String normalizeFieldName(String name)
      Transforms snake case field names into camel case (leave camel case fields as is).

      For example, this allows to compare Person object with camel case fields like firstName to a PersonDto object with snake case fields like first_name.

      Specified by:
      normalizeFieldName in class ComparingNormalizedFields
      Parameters:
      name - the field name to normalize
      Returns:
      camel case version of the field name
    • normalizeAcronyms

      private static String normalizeAcronyms(String name)
      Normalizes uppercase acronyms by keeping only the first acronym letter uppercase, ex: normalizeAcronyms("URl") gives "Url"
      Parameters:
      name - the name to normalize
      Returns:
      the normalized name
    • getDescription

      public String getDescription()
      Description copied from interface: RecursiveComparisonIntrospectionStrategy
      Returns a human-readable description of the strategy to be used in error messages.

      The default implementation returns this.getClass().getSimpleName().

      Specified by:
      getDescription in interface RecursiveComparisonIntrospectionStrategy
      Overrides:
      getDescription in class ComparingNormalizedFields
      Returns:
      a description of the strategy