[
https://issues.apache.org/jira/browse/COLLECTIONS-809?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=17892875#comment-17892875
]
Ashirvad Mohanty edited comment on COLLECTIONS-809 at 10/25/24 5:04 PM:
------------------------------------------------------------------------
I looked through the codebase and found try-catch-fail being used in
* AbstractCollectionTest.java
* AbstractMapIteratorTest.java
* AbstractMapTest.java
assertThrows() tests for only one exception type but here we are catching two
exception types at each occurance of try-catch-fail. So I was thinking maybe I
could use assertThrows() to get an Exception and then assertTrue() to see if
they are one of the two types we were catching for. Is that okay?
Ex: at AbstractMapIteratorTest.java (line: 141)
{quote}{{try {}}
{{ it.setValue(addSetValues()[0]);}}
{{ fail();}}
{{} catch (final UnsupportedOperationException |
IllegalStateException ex) {}}
{{ // ignore}}
{{}}}{color:#172b4d} {color}
{quote}
could be changed to
{quote}{{Exception exception = assertThrows(Exception.class, () ->
it.setValue(addSetValues()[0]));}}
{{assertTrue(exception instanceof UnsupportedOperationException || exception
instanceof IllegalStateException);}}
{quote}
was (Author: JIRAUSER307528):
I looked through the codebase and found try-catch-fail being used in
* AbstractCollectionTest.java
* AbstractMapIteratorTest.java
* AbstractMapTest.java
assertThrows() tests for only one exception type but here we are catching two
exception types at each occurance of try-catch-fail. So I was thinking maybe I
could use assertThrows() to get an Exception and then assertTrue() to see if
they are one of the two types we were catching for. Is that okay?
Ex: at AbstractMapIteratorTest.java (line: 141)
{quote}{{try {}}
{{ it.setValue(addSetValues()[0]);}}
{{ fail();}}
{{} catch (final UnsupportedOperationException |
IllegalStateException ex) {}}
{{ // ignore}}
{{}}}{color:#172b4d} {color}
{quote}
could be changed to
{quote}{{Exception exception = assertThrows(Exception.class, }}{{() }}{{->
}}{{it.setValue(addSetValues()[0]));}}
{{assertTrue(exception instanceof UnsupportedOperationException || exception
instanceof IllegalStateException);}}
{quote}
> Update try/catch/fail logic to assertThrows
> -------------------------------------------
>
> Key: COLLECTIONS-809
> URL: https://issues.apache.org/jira/browse/COLLECTIONS-809
> Project: Commons Collections
> Issue Type: Sub-task
> Reporter: John Patrick
> Priority: Major
> Time Spent: 1h 20m
> Remaining Estimate: 0h
>
--
This message was sent by Atlassian Jira
(v8.20.10#820010)