-
Notifications
You must be signed in to change notification settings - Fork 75
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[Bug] withPrefabValuesForField() throws for fields declaring interfaces and super-types #1012
Comments
Vankog
changed the title
[Bug] withPrefabValuesForField() throws for type List if Prefab values are created via Collections.singletonList()
[Bug] withPrefabValuesForField() throws for interfaces and super-types
Nov 5, 2024
Vankog
changed the title
[Bug] withPrefabValuesForField() throws for interfaces and super-types
[Bug] withPrefabValuesForField() throws for fields declaring interfaces and super-types
Nov 5, 2024
The solution might probably, to use |
You're completely right. Thanks for the elaborate report, this made it very easy for me to make the fix. Version 3.17.2 is now syncing with Maven Central! |
Vankog
added a commit
to Vankog/equalsverifier
that referenced
this issue
Nov 5, 2024
See jqno#1012 [Bug] withPrefabValuesForField() throws for fields declaring interfaces and super-types
Oh, I was too slow ^^ |
Vankog
added a commit
to Vankog/equalsverifier
that referenced
this issue
Nov 5, 2024
See jqno#1012 [Bug] withPrefabValuesForField() throws for fields declaring interfaces and super-types
Vankog
added a commit
to Vankog/equalsverifier
that referenced
this issue
Nov 6, 2024
See jqno#1012 [Bug] withPrefabValuesForField() throws for fields declaring interfaces and super-types
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Describe the bug
withPrefabValuesForField()
throws precondition exception for interface fields (e.g.java.util.List
) if prefab values are interface-implementations or sub-implementations of the defined field type.e.g. for
List
it fails for:java.util.ArrayList
java.util.Arrays.ArrayList
viajava.util.Arrays.asList(T...)
java.util.Collections.SingletonList
, created viajava.util.Collections.singletonList(T)
Steps to reproduce
java.util.List
field..withPrefabValues(List.class, Collections.singletonList(red), Collections.singletonList(blue))
.withPrefabValuesForField("myListField", Collections.singletonList(red), Collections.singletonList(blue))
.withPrefabValuesForField("myListField", Arrays.asList(red), Arrays.asList(blue))
.withPrefabValuesForField("myListField", Collections.unmodifiableList(Arrays.asList(red)), Collections.unmodifiableList(Arrays.asList(blue)))
Error message and version number
EqualsVerifier v. 3.17.1
JDK 8 Temurin
Code: EqualsVerifier invocation
Code: class under test
Additional context
Using the old
.withPrefabValues(List.class, Collections.singletonList(red), Collections.singletonList(blue))
works.
Thus, the expectation is that it works for
withPrefabValuesForField()
as well.EDIT:
Looking at nl.jqno.equalsverifier.internal.util.Validations.validateFieldTypeMatches(Class, String, Class<?>) indicates that this happens with all type hierarchies, as the code uses
boolean sameFields = f.getType().equals(fieldType);
enforcing an exact type match, doesn't it?
EDIT 2: Yes, testing implies that also type hierarchies are affected.
I tested it against a field of type
java.lang.Object
with any sub-type as prefab values.The text was updated successfully, but these errors were encountered: