AssertJ `.extracting`

AssertJ is a pretty nice library for assertions, way more powerful than what JUnit Assertions offers.
In particular, it has nice list assertions, and I want to talk about .extracting.

Generally, extracting is used as in the following example: ProductPlanningSchemaBLTest.java test_1Product_3Schema_expect2PP L232-L237, where you hardcode the field names that you want to check, and afterwards create the tuples that you expect.

However, I really do not like hardcoding those fields in there, and yesterday I figured out i can use a lambda to extract my fields.
I believe my method is better than hardcoding, and easier to understand as well: BankStatementImportProcessTest.java integrationAllAmtFormats L358-L366.

It also lets me pre-process the fields that i want to extract, for easier testing afterwards (i don’t need all the new BigDecimal() ceremony for all my amounts):

Lambda version (my version):

final List<I_C_BankStatementLine> lines = bankStatementDAO.getLinesByBankStatementId(bankStatementId);
assertThat(lines)
        .extracting(l -> tuple(l.getStmtAmt().toString(), l.getTrxAmt().toString(), l.getDescription()))
        .containsExactlyInAnyOrder(
                tuple("-123.456", "-123.456", "1. A+I"),
                tuple("-223.456", "-223.456", "2. D+C"),
                tuple("323.456", "323.456", "3. D+C"),
                tuple("423.456", "423.456", "4. S")
        );

Hardcoded field names version:

final List<I_C_BankStatementLine> lines = bankStatementDAO.getLinesByBankStatementId(bankStatementId);
assertThat(lines)
        .extracting("StmtAmt", "TrxAmt", "description")
        .containsExactlyInAnyOrder(
                tuple(new BigDecimal("-123.456"), new BigDecimal("-123.456"), "1. A+I"),
                tuple(new BigDecimal("-223.456"), new BigDecimal("-223.456"), "2. D+C"),
                tuple(new BigDecimal("323.456"), new BigDecimal("323.456"), "3. D+C"),
                tuple(new BigDecimal("423.456"), new BigDecimal("423.456"), "4. S")
        );