[java-inspections] IDEA-14669 fixed: suggest adding specific non-null assertions from test frameworks

(cherry picked from commit 0d22d640ea4ee77a6bdfb5b4af504332e7456b68)

IJ-MR-150371

GitOrigin-RevId: 04a5fe47cf874ae78c5ad73282b55123f55e84cb
This commit is contained in:
Bartek Pacia
2024-11-27 17:59:39 +01:00
committed by intellij-monorepo-bot
parent 47a2170f17
commit 5569a2965d
14 changed files with 376 additions and 6 deletions

View File

@@ -0,0 +1,20 @@
// "Assert with JUnit 3 'assertNotNull(s)'" "true-preview"
import junit.framework.TestCase;
import org.jetbrains.annotations.Nullable;
public class SomeJUnit3Test extends TestCase {
@Nullable
String getNullableString() {
double random = Math.random();
if (random > 0.75) return null;
if (random > 0.50) return "";
else return "bruh";
}
public void test() {
String s = getNullableString();
assertNotNull(s);
assertTrue(s.isEmpty());
}
}

View File

@@ -0,0 +1,19 @@
// "Assert with JUnit 4 'Assert.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public final class SomeJUnit4Test {
@Nullable
native String getNullableString();
@Test
public void test() {
String s = getNullableString();
Assert.assertNotNull(s);
assertTrue(s.isEmpty());
}
}

View File

@@ -0,0 +1,20 @@
// "Assert with JUnit 4 'Assert.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.junit.Assert;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public final class SomeJUnit4Test {
@Nullable
native String getNullableString();
@Test
public void test() {
String s = getNullableString();
Assert.assertNotNull(s);
//noinspection SimplifiableConditionalExpression
assertTrue(s.isEmpty() ? true : false);
}
}

View File

@@ -0,0 +1,24 @@
// "Assert with JUnit 5 'Assertions.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Assertions;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SomeJUnit5Test {
@Nullable
String getNullableString() {
double random = Math.random();
if (random > 0.75) return null;
if (random > 0.50) return "";
else return "bruh";
}
@Test
public void test() {
String s = getNullableString();
Assertions.assertNotNull(s);
assertTrue(s.isEmpty());
}
}

View File

@@ -0,0 +1,24 @@
// "Assert with TestNG 'Assert.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.testng.Assert;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
public class SomeTestNGTest {
@Nullable
String getNullableString() {
double random = Math.random();
if (random > 0.75) return null;
if (random > 0.50) return "";
else return "bruh";
}
@Test
public void test() {
String s = getNullableString();
Assert.assertNotNull(s);
assertTrue(s.isEmpty());
}
}

View File

@@ -0,0 +1,19 @@
// "Assert with JUnit 3 'assertNotNull(s)'" "true-preview"
import junit.framework.TestCase;
import org.jetbrains.annotations.Nullable;
public class SomeJUnit3Test extends TestCase {
@Nullable
String getNullableString() {
double random = Math.random();
if (random > 0.75) return null;
if (random > 0.50) return "";
else return "bruh";
}
public void test() {
String s = getNullableString();
assertTrue(s.isEm<caret>pty());
}
}

View File

@@ -0,0 +1,17 @@
// "Assert with JUnit 4 'Assert.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public final class SomeJUnit4Test {
@Nullable
native String getNullableString();
@Test
public void test() {
String s = getNullableString();
assertTrue(s.isEm<caret>pty());
}
}

View File

@@ -0,0 +1,18 @@
// "Assert with JUnit 4 'Assert.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.junit.Test;
import static org.junit.Assert.assertTrue;
public final class SomeJUnit4Test {
@Nullable
native String getNullableString();
@Test
public void test() {
String s = getNullableString();
//noinspection SimplifiableConditionalExpression
assertTrue(s.isEm<caret>pty() ? true : false);
}
}

View File

@@ -0,0 +1,22 @@
// "Assert with JUnit 5 'Assertions.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class SomeJUnit5Test {
@Nullable
String getNullableString() {
double random = Math.random();
if (random > 0.75) return null;
if (random > 0.50) return "";
else return "bruh";
}
@Test
public void test() {
String s = getNullableString();
assertTrue(s.isEm<caret>pty());
}
}

View File

@@ -0,0 +1,22 @@
// "Assert with TestNG 'Assert.assertNotNull(s)'" "true-preview"
import org.jetbrains.annotations.Nullable;
import org.testng.annotations.Test;
import static org.testng.Assert.assertTrue;
public class SomeTestNGTest {
@Nullable
String getNullableString() {
double random = Math.random();
if (random > 0.75) return null;
if (random > 0.50) return "";
else return "bruh";
}
@Test
public void test() {
String s = getNullableString();
assertTrue(s.isEm<caret>pty());
}
}