-
Notifications
You must be signed in to change notification settings - Fork 100
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixes deprecation warnings related to Named.
- Loading branch information
Showing
3 changed files
with
91 additions
and
2 deletions.
There are no files selected for viewing
84 changes: 84 additions & 0 deletions
84
workflow-ui/core-common/src/test/java/com/squareup/workflow1/ui/NamedScreenTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,84 @@ | ||
package com.squareup.workflow1.ui | ||
|
||
import com.google.common.truth.Truth.assertThat | ||
import org.junit.Test | ||
|
||
// If you try to replace isTrue() with isTrue compilation fails. | ||
@OptIn(WorkflowUiExperimentalApi::class) | ||
@Suppress("UsePropertyAccessSyntax") | ||
internal class NamedScreenTest { | ||
object Whut : Screen | ||
object Hey : Screen | ||
|
||
@Test fun `same type same name matches`() { | ||
assertThat(compatible(NamedScreen(Hey, "eh"), NamedScreen(Hey, "eh"))).isTrue() | ||
} | ||
|
||
@Test fun `same type diff name matches`() { | ||
assertThat(compatible(NamedScreen(Hey, "blam"), NamedScreen(Hey, "bloom"))).isFalse() | ||
} | ||
|
||
@Test fun `diff type same name no match`() { | ||
assertThat(compatible(NamedScreen(Hey, "a"), NamedScreen(Whut, "a"))).isFalse() | ||
} | ||
|
||
@Test fun recursion() { | ||
assertThat( | ||
compatible( | ||
NamedScreen(NamedScreen(Hey, "one"), "ho"), | ||
NamedScreen(NamedScreen(Hey, "one"), "ho") | ||
) | ||
).isTrue() | ||
|
||
assertThat( | ||
compatible( | ||
NamedScreen(NamedScreen(Hey, "one"), "ho"), | ||
NamedScreen(NamedScreen(Hey, "two"), "ho") | ||
) | ||
).isFalse() | ||
|
||
assertThat( | ||
compatible( | ||
NamedScreen(NamedScreen(Hey, "a"), "ho"), | ||
NamedScreen(NamedScreen(Whut, "a"), "ho") | ||
) | ||
).isFalse() | ||
} | ||
|
||
@Test fun `key recursion`() { | ||
assertThat(NamedScreen(NamedScreen(Hey, "one"), "ho").compatibilityKey) | ||
.isEqualTo(NamedScreen(NamedScreen(Hey, "one"), "ho").compatibilityKey) | ||
|
||
assertThat(NamedScreen(NamedScreen(Hey, "one"), "ho").compatibilityKey) | ||
.isNotEqualTo(NamedScreen(NamedScreen(Hey, "two"), "ho").compatibilityKey) | ||
|
||
assertThat(NamedScreen(NamedScreen(Hey, "a"), "ho").compatibilityKey) | ||
.isNotEqualTo(NamedScreen(NamedScreen(Whut, "a"), "ho").compatibilityKey) | ||
} | ||
|
||
@Test fun `recursive keys are legible`() { | ||
assertThat(NamedScreen(NamedScreen(Hey, "one"), "ho").compatibilityKey) | ||
.isEqualTo("com.squareup.workflow1.ui.NamedScreenTest\$Hey+one+ho") | ||
} | ||
|
||
private class Foo(override val compatibilityKey: String) : Compatible, Screen | ||
|
||
@Test fun `the test Compatible class actually works`() { | ||
assertThat(compatible(Foo("bar"), Foo("bar"))).isTrue() | ||
assertThat(compatible(Foo("bar"), Foo("baz"))).isFalse() | ||
} | ||
|
||
@Test fun `wrapping custom Compatible compatibility works`() { | ||
assertThat(compatible(NamedScreen(Foo("bar"), "name"), NamedScreen(Foo("bar"), "name"))) | ||
.isTrue() | ||
assertThat(compatible(NamedScreen(Foo("bar"), "name"), NamedScreen(Foo("baz"), "name"))) | ||
.isFalse() | ||
} | ||
|
||
@Test fun `wrapping custom Compatible keys work`() { | ||
assertThat(NamedScreen(Foo("bar"), "name").compatibilityKey) | ||
.isEqualTo(NamedScreen(Foo("bar"), "name").compatibilityKey) | ||
assertThat(NamedScreen(Foo("bar"), "name").compatibilityKey) | ||
.isNotEqualTo(NamedScreen(Foo("baz"), "name").compatibilityKey) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters