Skip to content

refactor: use AssertJ recursive comparison for object assertions in unit tests #33

Description

@emaarco

Summary

Replace repetitive per-field assertThat(...) chains with AssertJ's recursive object comparison where it makes the test clearer.

Current State

Several unit tests assert an object by comparing each attribute in its own assertThat statement, stacked one after another:

assertThat(result.id).isEqualTo(expected.id)
assertThat(result.name).isEqualTo(expected.name)
assertThat(result.status).isEqualTo(expected.status)
// ...N calls for one object

This is verbose, easy to leave incomplete (a new field silently goes unasserted), and noisy to read.

Desired State

A single assertion per object where a full-object comparison is intended:

assertThat(result)
    .usingRecursiveComparison()
    .isEqualTo(expected)

Added Value

  • Readability — one assertion expresses "this object equals that object".
  • Maintainability — new fields are covered automatically; no forgotten assertThat line.
  • Cleaner diffs — failures report all differing fields at once.

Technical Notes

  • Apply only where a whole-object equality check is the intent — keep targeted single-field assertions where that's what the test actually means.
  • Use .ignoringFields(...) / .ignoringFieldsOfTypes(...) for generated or non-deterministic fields (ids, timestamps).
  • Scope: backend unit + application-service tests under service/app.
  • Keep the mutation-testing gate (80) green — recursive comparison still kills the same mutants as long as the compared object is fully built.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions