[ 
https://issues.apache.org/jira/browse/COLLECTIONS-898?page=com.atlassian.jira.plugin.system.issuetabpanels:all-tabpanel
 ]

Thomas Mortagne updated COLLECTIONS-898:
----------------------------------------
    Description: 
AbstractSetTest is very useful to validate the behavior of custom Set 
implementations, but there is unfortunately one small limitation preventing to 
test it with a typed Set (for example {{class MySet extends Set<MyType>}}): 
#testSetEquals calls #add with a hardcoded String, which immediately fail with 
a ClassCastException in such a case. It used to be possible to overwrite 
#testSetEquals(), but it moved to package private in 4.6.0, making it hard to 
workaround. So I cannot be lazy anymore and need to suggest a proper fix :)

I propose to rely on something like getFullElements() to find a proper element 
to add, instead of the hardcoded String. See 
https://github.com/apache/commons-collections/pull/727 for the pull request.

  was:
AbstractSetTest is very useful to validate the behavior of custom Set 
implementations, but there is unfortunately one small limitation preventing to 
test it with a typed Set (for example {{class MySet extends Set<MyType>}}): 
#testSetEquals calls #add with a hardcoded String, which immediately fail with 
a ClassCastException in such a case. It used to be possible to overwrite 
#testSetEquals(), but it moved to package private in 4.6.0, making it hard to 
workaround. So I cannot be lazy anymore and need to suggest a proper fix :)

I propose to rely on something like getFullElements() to find a proper element 
to add, instead of the harcoded String. Pull request coming up...


> AbstractSetTest cannot be used with an explicitly typed Set (unless it's 
> based on String)
> -----------------------------------------------------------------------------------------
>
>                 Key: COLLECTIONS-898
>                 URL: https://issues.apache.org/jira/browse/COLLECTIONS-898
>             Project: Commons Collections
>          Issue Type: Bug
>          Components: Set
>    Affects Versions: 4.0
>            Reporter: Thomas Mortagne
>            Priority: Major
>
> AbstractSetTest is very useful to validate the behavior of custom Set 
> implementations, but there is unfortunately one small limitation preventing 
> to test it with a typed Set (for example {{class MySet extends 
> Set<MyType>}}): #testSetEquals calls #add with a hardcoded String, which 
> immediately fail with a ClassCastException in such a case. It used to be 
> possible to overwrite #testSetEquals(), but it moved to package private in 
> 4.6.0, making it hard to workaround. So I cannot be lazy anymore and need to 
> suggest a proper fix :)
> I propose to rely on something like getFullElements() to find a proper 
> element to add, instead of the hardcoded String. See 
> https://github.com/apache/commons-collections/pull/727 for the pull request.



--
This message was sent by Atlassian Jira
(v8.20.10#820010)

Reply via email to