Skip to content

Commit 3f3b688

Browse files
authored
dataconnect: DataConnectBackendUnitTest.kt modernized (#6353)
1 parent 57e64e7 commit 3f3b688

File tree

2 files changed

+47
-41
lines changed

2 files changed

+47
-41
lines changed

firebase-dataconnect/androidTestutil/androidTestutil.gradle.kts

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -58,6 +58,7 @@ dependencies {
5858
implementation(libs.androidx.test.core)
5959
implementation(libs.androidx.test.junit)
6060
implementation(libs.auth0.jwt)
61+
implementation(libs.kotest.assertions)
6162
implementation(libs.kotest.property)
6263
implementation(libs.kotlinx.coroutines.core)
6364
implementation(libs.kotlinx.serialization.core)

firebase-dataconnect/androidTestutil/src/test/kotlin/com/google/firebase/dataconnect/testutil/DataConnectBackendUnitTest.kt

Lines changed: 46 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -16,118 +16,123 @@
1616

1717
package com.google.firebase.dataconnect.testutil
1818

19-
import com.google.common.truth.Truth.assertThat
2019
import com.google.firebase.dataconnect.testutil.DataConnectBackend.Companion.fromInstrumentationArgument
20+
import io.kotest.assertions.assertSoftly
21+
import io.kotest.assertions.throwables.shouldThrow
22+
import io.kotest.matchers.nulls.shouldBeNull
23+
import io.kotest.matchers.shouldBe
24+
import io.kotest.matchers.types.shouldBeSameInstanceAs
2125
import java.net.URI
2226
import java.net.URL
2327
import org.junit.Test
2428

2529
class DataConnectBackendUnitTest {
2630

2731
@Test
28-
fun `fromInstrumentationArgument(null) should return Production`() {
29-
assertThat(fromInstrumentationArgument(null)).isNull()
32+
fun `fromInstrumentationArgument(null) should return null`() {
33+
fromInstrumentationArgument(null).shouldBeNull()
3034
}
3135

3236
@Test
3337
fun `fromInstrumentationArgument('prod') should return Production`() {
34-
assertThat(fromInstrumentationArgument("prod")).isSameInstanceAs(DataConnectBackend.Production)
38+
fromInstrumentationArgument("prod") shouldBeSameInstanceAs DataConnectBackend.Production
3539
}
3640

3741
@Test
3842
fun `fromInstrumentationArgument('staging') should return Staging`() {
39-
assertThat(fromInstrumentationArgument("staging")).isSameInstanceAs(DataConnectBackend.Staging)
43+
fromInstrumentationArgument("staging") shouldBeSameInstanceAs DataConnectBackend.Staging
4044
}
4145

4246
@Test
4347
fun `fromInstrumentationArgument('autopush') should return Autopush`() {
44-
assertThat(fromInstrumentationArgument("autopush"))
45-
.isSameInstanceAs(DataConnectBackend.Autopush)
48+
fromInstrumentationArgument("autopush") shouldBeSameInstanceAs DataConnectBackend.Autopush
4649
}
4750

4851
@Test
4952
fun `fromInstrumentationArgument('emulator') should return Emulator()`() {
50-
assertThat(fromInstrumentationArgument("emulator")).isEqualTo(DataConnectBackend.Emulator())
53+
fromInstrumentationArgument("emulator") shouldBe DataConnectBackend.Emulator()
5154
}
5255

5356
@Test
5457
fun `fromInstrumentationArgument(emulator with host) should return Emulator() with the host`() {
55-
assertThat(fromInstrumentationArgument("emulator:a.b.c"))
56-
.isEqualTo(DataConnectBackend.Emulator(host = "a.b.c"))
58+
fromInstrumentationArgument("emulator:a.b.c") shouldBe
59+
DataConnectBackend.Emulator(host = "a.b.c")
5760
}
5861

5962
@Test
6063
fun `fromInstrumentationArgument(emulator with port) should return Emulator() with the port`() {
61-
assertThat(fromInstrumentationArgument("emulator::9987"))
62-
.isEqualTo(DataConnectBackend.Emulator(port = 9987))
64+
fromInstrumentationArgument("emulator::9987") shouldBe DataConnectBackend.Emulator(port = 9987)
6365
}
6466

6567
@Test
6668
fun `fromInstrumentationArgument(emulator with host and port) should return Emulator() with the host and port`() {
67-
assertThat(fromInstrumentationArgument("emulator:a.b.c:9987"))
68-
.isEqualTo(DataConnectBackend.Emulator(host = "a.b.c", port = 9987))
69+
fromInstrumentationArgument("emulator:a.b.c:9987") shouldBe
70+
DataConnectBackend.Emulator(host = "a.b.c", port = 9987)
6971
}
7072

7173
@Test
7274
fun `fromInstrumentationArgument(http url with host) should return Custom()`() {
73-
assertThat(fromInstrumentationArgument("http://a.b.c"))
74-
.isEqualTo(DataConnectBackend.Custom("a.b.c", false))
75+
fromInstrumentationArgument("http://a.b.c") shouldBe DataConnectBackend.Custom("a.b.c", false)
7576
}
7677

7778
@Test
7879
fun `fromInstrumentationArgument(http url with host and port) should return Custom()`() {
79-
assertThat(fromInstrumentationArgument("http://a.b.c:9987"))
80-
.isEqualTo(DataConnectBackend.Custom("a.b.c:9987", false))
80+
fromInstrumentationArgument("http://a.b.c:9987") shouldBe
81+
DataConnectBackend.Custom("a.b.c:9987", false)
8182
}
8283

8384
@Test
8485
fun `fromInstrumentationArgument(https url with host) should return Custom()`() {
85-
assertThat(fromInstrumentationArgument("https://a.b.c"))
86-
.isEqualTo(DataConnectBackend.Custom("a.b.c", true))
86+
fromInstrumentationArgument("https://a.b.c") shouldBe DataConnectBackend.Custom("a.b.c", true)
8787
}
8888

8989
@Test
9090
fun `fromInstrumentationArgument(https url with host and port) should return Custom()`() {
91-
assertThat(fromInstrumentationArgument("https://a.b.c:9987"))
92-
.isEqualTo(DataConnectBackend.Custom("a.b.c:9987", true))
91+
fromInstrumentationArgument("https://a.b.c:9987") shouldBe
92+
DataConnectBackend.Custom("a.b.c:9987", true)
9393
}
9494

9595
@Test
9696
fun `fromInstrumentationArgument('foo') should throw an exception`() {
9797
val exception =
98-
assertThrows(InvalidInstrumentationArgumentException::class) {
99-
fromInstrumentationArgument("foo")
100-
}
98+
shouldThrow<InvalidInstrumentationArgumentException> { fromInstrumentationArgument("foo") }
99+
101100
val urlParseErrorMessage = runCatching { URL("foo") }.exceptionOrNull()!!.message!!
102-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("foo")
103-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("invalid", ignoreCase = true)
104-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("DATA_CONNECT_BACKEND")
105-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText(urlParseErrorMessage)
101+
assertSoftly {
102+
exception.message shouldContainWithNonAbuttingText "foo"
103+
exception.message shouldContainWithNonAbuttingTextIgnoringCase "invalid"
104+
exception.message shouldContainWithNonAbuttingText "DATA_CONNECT_BACKEND"
105+
exception.message shouldContainWithNonAbuttingText urlParseErrorMessage
106+
}
106107
}
107108

108109
@Test
109110
fun `fromInstrumentationArgument(invalid URI) should throw an exception`() {
110111
val exception =
111-
assertThrows(InvalidInstrumentationArgumentException::class) {
112-
fromInstrumentationArgument("..:")
113-
}
112+
shouldThrow<InvalidInstrumentationArgumentException> { fromInstrumentationArgument("..:") }
113+
114114
val uriParseErrorMessage = runCatching { URI("..:") }.exceptionOrNull()!!.message!!
115-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("..:")
116-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("invalid", ignoreCase = true)
117-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("DATA_CONNECT_BACKEND")
118-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText(uriParseErrorMessage)
115+
assertSoftly {
116+
exception.message shouldContainWithNonAbuttingText "..:"
117+
exception.message shouldContainWithNonAbuttingTextIgnoringCase "invalid"
118+
exception.message shouldContainWithNonAbuttingText "DATA_CONNECT_BACKEND"
119+
exception.message shouldContainWithNonAbuttingText uriParseErrorMessage
120+
}
119121
}
120122

121123
@Test
122124
fun `fromInstrumentationArgument(invalid emulator URI) should throw an exception`() {
123125
val exception =
124-
assertThrows(InvalidInstrumentationArgumentException::class) {
126+
shouldThrow<InvalidInstrumentationArgumentException> {
125127
fromInstrumentationArgument("emulator:::::")
126128
}
129+
127130
val urlParseErrorMessage = runCatching { URL("https://::::") }.exceptionOrNull()!!.message!!
128-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("emulator:::::")
129-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("invalid", ignoreCase = true)
130-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText("DATA_CONNECT_BACKEND")
131-
assertThat(exception).hasMessageThat().containsWithNonAdjacentText(urlParseErrorMessage)
131+
assertSoftly {
132+
exception.message shouldContainWithNonAbuttingText "emulator:::::"
133+
exception.message shouldContainWithNonAbuttingTextIgnoringCase "invalid"
134+
exception.message shouldContainWithNonAbuttingText "DATA_CONNECT_BACKEND"
135+
exception.message shouldContainWithNonAbuttingText urlParseErrorMessage
136+
}
132137
}
133138
}

0 commit comments

Comments
 (0)