Incorrect Implicit isNotNull() assertion is covered by #14

Open
opened 2024-07-11 16:03:27 +02:00 by DieterDP · 1 comment

Steps to reproduce

Given following code:

import org.awaitility.Awaitility;
import org.junit.jupiter.api.Test;

import java.util.Map;

import static org.assertj.core.api.Assertions.assertThat;

public class Example {
    record MyObject(String a, String b) {}

    static class Loader {
        int i = 0;

        public Map<String, MyObject> load() {
            if (i == 0) {
                i++;
                return Map.of();
            } else {
                i++;
                return Map.of("x", new MyObject("a", "b"));
            }
        }
    }

    @Test
    public void runTest() {
        Loader loader = new Loader();

        Awaitility.await().untilAsserted(() ->
                assertThat(loader.load().get("x"))
                        .isNotNull() // Intellij hints "Implicit isNotNull() assertion is covered by containsExactly()"
                        .extracting(MyObject::a, MyObject::b)
                        .containsExactly("a", "b"));
    }
}

The above test runs correct, but IntelliJ hints that the "isNotNull" is not needed. Removing this line causes the test to fail.

Expected result (correct result): IntelliJ should not hint the "isNotNull" is not needed

Actual result (faulty result): IntelliJ hints that it is needed.

Environment:
IU-241.18034.62, JRE 17.0.11+1-b1207.24x64 JetBrains s.r.o., OS Linux(amd64) v5.15.0-113-generic, screens 1920.0x1080.0, 1920.0x1080.0

Steps to reproduce Given following code: ```java import org.awaitility.Awaitility; import org.junit.jupiter.api.Test; import java.util.Map; import static org.assertj.core.api.Assertions.assertThat; public class Example { record MyObject(String a, String b) {} static class Loader { int i = 0; public Map<String, MyObject> load() { if (i == 0) { i++; return Map.of(); } else { i++; return Map.of("x", new MyObject("a", "b")); } } } @Test public void runTest() { Loader loader = new Loader(); Awaitility.await().untilAsserted(() -> assertThat(loader.load().get("x")) .isNotNull() // Intellij hints "Implicit isNotNull() assertion is covered by containsExactly()" .extracting(MyObject::a, MyObject::b) .containsExactly("a", "b")); } } ``` The above test runs correct, but IntelliJ hints that the "isNotNull" is not needed. Removing this line causes the test to fail. Expected result (correct result): IntelliJ should not hint the "isNotNull" is not needed Actual result (faulty result): IntelliJ hints that it is needed. Environment: IU-241.18034.62, JRE 17.0.11+1-b1207.24x64 JetBrains s.r.o., OS Linux(amd64) v5.15.0-113-generic, screens 1920.0x1080.0, 1920.0x1080.0
chrisly42 added the
bug
label 2024-07-13 16:05:02 +02:00
Owner

Thanks for the thorough report. I will fix it as soon as I have the time.

Thanks for the thorough report. I will fix it as soon as I have the time.
Sign in to join this conversation.
No Milestone
No project
No Assignees
2 Participants
Notifications
Due Date
The due date is invalid or out of range. Please use the format 'yyyy-mm-dd'.

No due date set.

Dependencies

No dependencies set.

Reference: chrisly42/cajon-plugin#14
No description provided.