AssertThrowsMultipleStatements
The lambda passed to assertThrows should contain exactly one statement

Severity
WARNING

The problem

If the body of the lambda passed to assertThrows contains multiple statements, execution of the lambda will stop at the first statement that throws an exception and all subsequent statements will be ignored.

This means that:

Don’t do this:

assertThrows(
    UnsupportedOperationException.class,
    () -> {
        AppendOnlyList list = new AppendOnlyList();
        list.add(0, "a");
        list.remove(0);
        assertThat(list).containsExactly("a");
    });

Do this instead:

AppendOnlyList list = new AppendOnlyList();
list.add(0, "a");
assertThrows(
    UnsupportedOperationException.class,
    () -> list.remove(0));
assertThat(list).containsExactly("a");

Suppression

Suppress false positives by adding the suppression annotation @SuppressWarnings("AssertThrowsMultipleStatements") to the enclosing element.