Skip to content

[Equivalence] Add factory methods for multiple and/or nested fields #3707

Open
@NathanJAdams

Description

Use Case
My use case is for the Equivalence class and is to enable checking against multiple nested fields. It isn't yet supported I'd like to add support for it. There's an added benefit too - it would reduce and simplify the amount of client code needed to create Equivalence objects.

Issues

  1. There is an Equivalence.onResultOf() method but it only takes one Function, if you only need to test one field that's fine, but if you want to test multiple fields then you have to create your own Functions that delegate to each in turn.
  2. The onResultOf() method can be chained, but it creates an extra object for each Function tested. It should be possible to create only one object for multiple Functions.
  3. The code needed to create the chain is quite verbose and could be reduced and simplified with the right method declarations.

Solution
Add factory methods to create Equivalence objects that take multiple Functions or multiple Equivalences. This will solve all 3 issues above and would be invoked something like eg.

ofFields(Class1::getField1, Class1::getField2);
or
ofSubFields(Class1::getField1, ofFields(Field1::getSubField1, Field1::getSubField2));

Any thoughts on this would be much appreciated

Activity

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions