Skip to content

Commit

Permalink
Makes TextController support equals
Browse files Browse the repository at this point in the history
  • Loading branch information
jkwiz committed Oct 21, 2024
1 parent c562558 commit 59d76c0
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -87,4 +87,17 @@ private class TextControllerImpl(initialValue: String) : TextController {
set(value) {
_textValue.value = value
}

override fun equals(other: Any?): Boolean {
if (this === other) return true
if (javaClass != other?.javaClass) return false

other as TextController

return textValue == other.textValue
}

override fun hashCode(): Int {
return textValue.hashCode()
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package com.squareup.workflow1.ui

import org.junit.Test
import kotlin.test.assertEquals
import kotlin.test.assertNotEquals

@OptIn(WorkflowUiExperimentalApi::class)
internal class TextControllerTest {

@Test fun `equals works with the same value`() {
val controller1 = TextController(initialValue = "apple")
val controller2 = TextController(initialValue = "apple")
assertEquals(controller1, controller2)
}

@Test fun `equals works with different values`() {
val controller1 = TextController(initialValue = "apple")
val controller2 = TextController(initialValue = "orange")
assertNotEquals(controller1, controller2)
}
}

0 comments on commit 59d76c0

Please sign in to comment.