File tree Expand file tree Collapse file tree 2 files changed +35
-0
lines changed
workflow-ui/core-common/src
main/java/com/squareup/workflow1/ui
test/java/com/squareup/workflow1/ui Expand file tree Collapse file tree 2 files changed +35
-0
lines changed Original file line number Diff line number Diff 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}
Original file line number Diff line number Diff line change 1+ package com.squareup.workflow1.ui
2+
3+ import org.junit.Test
4+ import kotlin.test.assertEquals
5+ import kotlin.test.assertNotEquals
6+
7+ // If you try to replace isTrue() with isTrue compilation fails.
8+ @OptIn(WorkflowUiExperimentalApi ::class )
9+ internal class TextControllerTest {
10+
11+ @Test fun `equals works with the same value` () {
12+ val controller1 = TextController (initialValue = " apple" )
13+ val controller2 = TextController (initialValue = " apple" )
14+ assertEquals(controller1, controller2)
15+ }
16+
17+ @Test fun `equals works with different values` () {
18+ val controller1 = TextController (initialValue = " apple" )
19+ val controller2 = TextController (initialValue = " orange" )
20+ assertNotEquals(controller1, controller2)
21+ }
22+ }
You can’t perform that action at this time.
0 commit comments