Create custom Mockito verifiers for entities

Description

Overview

Hibernate requires equals not to be dependent on entity fields so our implementation uses getClass and id field for entities equality. That makes it impossible to compare expected and actual results inline in tests as well as proper mocking.

F.e. if we write when(repository.save(expectedEntity)).thenReturn(mockResult) then this repository call will return mockResult even if only id of entity passed to repository call matches with expectedEntity while other fields may differ.

See f.e. AuthoritySourceFileServiceTest::shouldUpdateAuthoritySourceFileModifiableFields where we have a separate assertion for each field in the end and using captor to intercept actual value passed to repository call.

Approach

Write custom Mockito verifiers for entities which will compare all fields separately instead of using equals (they can use equals and if it’s true - compare all other fields).

Requirements

  • Custom verifiers created for entities that are mostly used (AuthoritySourceFile, Authority…). We may not need to create verifiers for some small entities that may have only one test case and not a lot of assertions

  • Custom verifiers are used in tests, separate assertions for fields removed from test cases

Environment

None

Potential Workaround

None

CSP Request Details

None

CSP Rejection Details

None

Checklist

hide

Activity

Show:
Done

Details

Assignee

Reporter

Priority

Story Points

Sprint

Development Team

Spitfire

Fix versions

Release

Quesnelia (R1 2024)

TestRail: Cases

Open TestRail: Cases

TestRail: Runs

Open TestRail: Runs
Created February 8, 2024 at 3:14 PM
Updated March 25, 2024 at 4:07 PM
Resolved February 15, 2024 at 7:08 PM
TestRail: Cases
TestRail: Runs

Flag notifications