0

Suppose I have a list of User userList.

class User {
    String firstName;
    String lastName;
}

Is there a way I can compare using AssertJ like

assertThat(userList).lastName.equalsTo(List.of("A","B","C"));

?

Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35
LunaticJape
  • 1,446
  • 4
  • 21
  • 39

1 Answers1

4
List<User> users = Arrays.asList(
        new User("a", "A"),
        new User("b", "B"),
        new User("c", "C"));

assertThat(users)
        .extracting(User::getLastName)
        .containsExactly("A", "B", "C");
Oleg Cherednik
  • 17,377
  • 4
  • 21
  • 35