mardi 22 septembre 2020

What's the benefit of Assert Fluent Assertions over Sequential ones?

In my team the is a thread to write fluent assertions with AssertJ in the following way:

void checkPerson(Person person, String expectedName, Integer expectedAge) {
  assertThat(person)
    .isNotNull()
    .extracting(Person::getName, Person::getAge) 
    .containsExactly(expectedName, expectedAge)
}

but I prefer the other way:

void checkPerson(Person person, String expectedName, Integer expectedAge) {
  assertThat(person).isNotNull();
  assertThat(person.getName()).isEqualTo(expectedName);
  assertThat(person.getAge()).isEqualTo(expectedAge);
}

I think my way is more straightforward and type-safe. Are there any advantages of the first approach?

Aucun commentaire:

Enregistrer un commentaire