简体   繁体   中英

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?

The main benefit for me is the readability - the fluent code is (at least for me) easier to read and it takes less space. Exactly for the same reason You call the fluent methods in for instance builder classes.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM