[jvm] fix edge case for 'assert equals between inconvertible types' with instances of Kotlin value classes

#IDEA-362694 Fixed


(cherry picked from commit 0abfc10798a836bf77c0131871cb5daca2bf6303)

IJ-MR-150993

GitOrigin-RevId: 2509b8d2aa97d157b05eee08e9bbbddc321184f5
This commit is contained in:
Bartek Pacia
2024-12-06 13:27:09 +00:00
committed by intellij-monorepo-bot
parent 7c14f053cf
commit 02cb3576cf
@@ -19,7 +19,7 @@ abstract class KotlinAssertEqualsBetweenInconvertibleTypesInspectionTest : Asser
}
@Test
fun `test JUnit 4 assertEquals`() {
fun `JUnit 4 assertEquals`() {
@Language("kotlin") val code = """
import org.junit.Test
import kotlin.test.assertEquals
@@ -118,7 +118,8 @@ abstract class KotlinAssertEqualsBetweenInconvertibleTypesInspectionTest : Asser
myFixture.testHighlighting(JvmLanguage.KOTLIN, code)
}
fun `test JUnit 5 assertNotEquals`() {
@Test
fun `JUnit 5 assertNotEquals`() {
@Language("kotlin") val code = """
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.Assertions.assertNotEquals
@@ -135,7 +136,8 @@ abstract class KotlinAssertEqualsBetweenInconvertibleTypesInspectionTest : Asser
myFixture.testHighlighting(JvmLanguage.KOTLIN, code)
}
fun `test AssertJ assertNotEquals`() {
@Test
fun `AssertJ assertNotEquals`() {
@Language("kotlin") val code = """
import org.junit.jupiter.api.Test
import org.assertj.core.api.Assertions
@@ -152,7 +154,8 @@ abstract class KotlinAssertEqualsBetweenInconvertibleTypesInspectionTest : Asser
myFixture.testHighlighting(JvmLanguage.KOTLIN, code)
}
fun `test JUnit 4 assertNotSame`() {
@Test
fun `JUnit 4 assertNotSame`() {
@Language("kotlin") val code = """
import org.junit.Test
import org.junit.Assert.assertNotSame
@@ -1021,4 +1024,48 @@ abstract class KotlinAssertEqualsBetweenInconvertibleTypesInspectionTest : Asser
myFixture.testHighlighting(JvmLanguage.KOTLIN, code)
}
@Test
fun `Kotlin typealias`() {
@Language("kotlin") val code = """
import org.junit.Test
import org.junit.Assert
typealias TypeAlias = Int
class MySampleTest {
@Test
fun myTest() {
val expected: TypeAlias = 3
Assert.assertEquals(expected, 3)
Assert.<warning descr="'assertEquals()' between objects of inconvertible types 'int' and 'String'">assertEquals</warning>(expected, "foo")
}
}
""".trimIndent()
myFixture.testHighlighting(JvmLanguage.KOTLIN, code)
}
@Ignore("We are aware of this edge case, but it seems not possible to fix with the current UAST API. See IDEA-362694")
@Test
fun `Kotlin inline value class`() {
@Language("kotlin") val code = """
import org.junit.Test
import org.junit.Assert
@JvmInline
value class ValueClass(val prop: String)
class MySampleTest {
@Test
fun myTest() {
Assert.<warning descr="'assertEquals()' between objects of inconvertible types 'ValueClass' and 'int'">assertEquals</warning>(ValueClass("foo"), 1)
Assert.<warning descr="'assertEquals()' between objects of inconvertible types 'ValueClass' and 'String'">assertEquals</warning>(ValueClass("foo"), "foo")
Assert.assertEquals(ValueClass("foo"), ValueClass("foo"))
}
}
""".trimIndent()
myFixture.testHighlighting(JvmLanguage.KOTLIN, code)
}
}