Reputation: 29
When I try to run unit tests with Mockito using the following syntaxis for creating Lists
new ArrayList<>(Arrays.asList())
Arrays.asList()
The code always seems to return immutable lists and I get a unsupportedoperationexceptions all the time as I cannot remove elements from this List.
Upvotes: 0
Views: 807
Reputation: 144
This is by design, see also in the related JavaDoc of Arrays.asList()
:
The returned list implements the optional Collection methods, except those that would change the size of the returned list. Those methods leave the list unchanged and throw UnsupportedOperationException
Upvotes: 1