1. Overview

Sometimes when writing unit tests, we need to make order agnostic comparison of lists. In this short tutorial, we’ll take a look at different examples of how we can write such unit tests.

2. Setup

As per the List#equals Java documentation, two lists are equal if they contain the same elements in the same order. Therefore we can’t merely use the equals method as we want to do order agnostic comparison.

#java collections #testing #assertj #junit

Assert Two Lists for Equality Ignoring Order in Java
31.40 GEEK