An assertion or mock setup is started but never completed, so it checks or does nothing

tx0/java:unfinished-test-checkdefaulterrorbug

What it finds

assertThat(user.isActive()); with AssertJ or Truth only wraps the value: nothing is checked until a method such as isTrue() is called on the result. In the same way, Mockito's when(mock.find(id)); without thenReturn stubs nothing, and verify(mock); without a method call verifies nothing.

Reported is a statement that consists only of a call of assertThat with one argument, in a file that imports AssertJ or Truth, or of when, given or verify, in a file that imports Mockito.

From the rule's source, unfinished_test_check.rs.

Example from the rule's tests
import static org.assertj.core.api.Assertions.assertThat;import static org.mockito.Mockito.verify;import static org.mockito.Mockito.when; import java.util.List; class UserTest {  void check(List<String> users, boolean active) {    assertThat(active);tx0 reports: checks nothing until    when(users.get(0));tx0 reports: this stubbing does nothing    verify(users);tx0 reports: this verifies nothing    assertThat(active).isTrue();    when(users.get(0)).thenReturn("a");    verify(users).clear();  }}
Highlighted lines are the ones tx0 reports, with its message under each; the other lines are left alone.

Turn it on, off or suppress it

The rule runs in every tier. To turn it off for a project, set its level in tx0.toml:

tx0.toml
[rules]
"tx0/java:unfinished-test-check" = "off"

To keep one finding, suppress it with a reason. tx0 suppress ID --reason "..." writes the comment on the line before the code:

// tx0: ignore[tx0/java:unfinished-test-check] reason="..."

tx0 explain tx0/java:unfinished-test-check shows the same in the terminal. Found a false positive? Report it.