Skip to content

Commit 59d76c0

Browse files
committed
Makes TextController support equals
1 parent c562558 commit 59d76c0

File tree

2 files changed

+34
-0
lines changed

2 files changed

+34
-0
lines changed

workflow-ui/core-common/src/main/java/com/squareup/workflow1/ui/TextController.kt

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,4 +87,17 @@ private class TextControllerImpl(initialValue: String) : TextController {
8787
set(value) {
8888
_textValue.value = value
8989
}
90+
91+
override fun equals(other: Any?): Boolean {
92+
if (this === other) return true
93+
if (javaClass != other?.javaClass) return false
94+
95+
other as TextController
96+
97+
return textValue == other.textValue
98+
}
99+
100+
override fun hashCode(): Int {
101+
return textValue.hashCode()
102+
}
90103
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.squareup.workflow1.ui
2+
3+
import org.junit.Test
4+
import kotlin.test.assertEquals
5+
import kotlin.test.assertNotEquals
6+
7+
@OptIn(WorkflowUiExperimentalApi::class)
8+
internal class TextControllerTest {
9+
10+
@Test fun `equals works with the same value`() {
11+
val controller1 = TextController(initialValue = "apple")
12+
val controller2 = TextController(initialValue = "apple")
13+
assertEquals(controller1, controller2)
14+
}
15+
16+
@Test fun `equals works with different values`() {
17+
val controller1 = TextController(initialValue = "apple")
18+
val controller2 = TextController(initialValue = "orange")
19+
assertNotEquals(controller1, controller2)
20+
}
21+
}

0 commit comments

Comments
 (0)