Skip to content

Commit 98a190b

Browse files
committed
Added reproducer for jqno/equalsverifier#1083.
1 parent de4b5c9 commit 98a190b

File tree

2 files changed

+54
-0
lines changed
  • subprojects/equalsverifier-with-kotlin/src

2 files changed

+54
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
package org.sdkotlin.equalsverifier.delegation
2+
3+
interface Foo {
4+
val foo: Int
5+
}
6+
7+
interface Bar {
8+
val bar: Int
9+
}
10+
11+
data class BarImpl(override val bar: Int) : Bar
12+
13+
class FooBarImpl(barValue: Int) : Foo, Bar by BarImpl(barValue) {
14+
15+
override val foo = -bar
16+
17+
override fun equals(other: Any?): Boolean {
18+
if (this === other) return true
19+
if (other !is FooBarImpl) return false
20+
return bar == other.bar
21+
}
22+
23+
override fun hashCode(): Int = bar
24+
override fun toString(): String = "FooBarImpl(foo=$bar)"
25+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,29 @@
1+
package org.sdkotlin.equalsverifier.delegation
2+
3+
import nl.jqno.equalsverifier.EqualsVerifier
4+
import org.assertj.core.api.Assertions.assertThat
5+
import org.junit.jupiter.api.Disabled
6+
import org.junit.jupiter.api.Test
7+
8+
class FooBarImplTest {
9+
10+
@Test
11+
@Disabled("https://github.com/jqno/equalsverifier/issues/1083")
12+
fun `test equals, hashCode, and toString`() {
13+
EqualsVerifier.forClass(FooBarImpl::class.java).verify()
14+
}
15+
16+
@Test
17+
fun `test equals for equal`() {
18+
val actual = FooBarImpl(1)
19+
val expected = FooBarImpl(1)
20+
assertThat(actual).isEqualTo(expected)
21+
}
22+
23+
@Test
24+
fun `test equals for not equal`() {
25+
val actual = FooBarImpl(1)
26+
val expected = FooBarImpl(2)
27+
assertThat(actual).isNotEqualTo(expected)
28+
}
29+
}

0 commit comments

Comments
 (0)