Skip to content

Commit 917dd52

Browse files
committed
Added reproducer for jqno/equalsverifier#1081.
1 parent 49470b4 commit 917dd52

File tree

4 files changed

+76
-0
lines changed

4 files changed

+76
-0
lines changed

settings.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ include("subprojects:constant-dependencies:constant-consumer")
4343
include("subprojects:constant-dependencies:constant-producer")
4444
include("subprojects:di-with-koin")
4545
include("subprojects:effective-kotlin")
46+
include("subprojects:equalsverifier-with-kotlin")
4647
include("subprojects:kotlin-dl")
4748
include("subprojects:kotlin-for-java-devs")
4849
include("subprojects:kotlin-for-java-devs-client")
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
plugins {
2+
id("org.sdkotlin.buildlogic.kotlin-project")
3+
id("org.sdkotlin.buildlogic.test.unit-test-suite")
4+
}
5+
6+
dependencies {
7+
8+
testImplementation(platform("org.sdkotlin.platforms:test-platform"))
9+
10+
testImplementation(libs.equalsverifier)
11+
12+
testRuntimeOnly(libs.mockito) {
13+
because("Used by EqualsVerifier for prefab value generation.")
14+
}
15+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
package org.sdkotlin.equalsverifier.recusive
2+
3+
data class DataClassWithSealedTypeProperty(
4+
val foo: Foo,
5+
)
6+
7+
sealed interface Foo {
8+
9+
val value: Int
10+
11+
companion object {
12+
fun get(value: Int): Foo =
13+
FooEnum.INSTANCES[value] ?: UnknownFooImpl(value)
14+
}
15+
}
16+
17+
enum class FooEnum(
18+
private val delegate: Foo,
19+
) : Foo by delegate {
20+
21+
FOO_1(1),
22+
FOO_2(2),
23+
;
24+
25+
constructor(
26+
value: Int,
27+
) : this(FooImpl(value))
28+
29+
companion object {
30+
val INSTANCES: Map<Int, FooEnum> =
31+
entries.associateBy { enum -> enum.value }
32+
}
33+
}
34+
35+
internal data class FooImpl(
36+
override val value: Int,
37+
) : Foo
38+
39+
internal data class UnknownFooImpl(
40+
override val value: Int,
41+
) : Foo
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,19 @@
1+
package org.sdkotlin.equalsverifier.recusive
2+
3+
import nl.jqno.equalsverifier.EqualsVerifier
4+
import org.junit.jupiter.api.Test
5+
6+
internal class DataClassWithSealedTypePropertyTest {
7+
8+
@Test
9+
fun `test equals, hashCode, and toString`() {
10+
EqualsVerifier.forClass(DataClassWithSealedTypeProperty::class.java)
11+
// Required per https://github.com/jqno/equalsverifier/issues/1081.
12+
.withPrefabValues(
13+
Foo::class.java,
14+
FooImpl(1),
15+
FooImpl(2),
16+
)
17+
.verify()
18+
}
19+
}

0 commit comments

Comments
 (0)