Omair Iqbal
Omair Iqbal

Reputation: 29

Spring boot test always returns an immutable list

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

Answers (1)

void
void

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

Related Questions