Skip to content

Commit 0d462a7

Browse files
committed
test(fdl-ktx): add tests for the destructuring declarations
1 parent 4a4ee1c commit 0d462a7

File tree

1 file changed

+45
-0
lines changed

1 file changed

+45
-0
lines changed

firebase-dynamic-links/ktx/src/test/kotlin/com/google/firebase/dynamiclinks/ktx/DynamicLinksTests.kt

Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,17 @@ import com.google.common.truth.Truth.assertThat
1919
import com.google.firebase.FirebaseApp
2020
import com.google.firebase.FirebaseOptions
2121
import com.google.firebase.dynamiclinks.FirebaseDynamicLinks
22+
import com.google.firebase.dynamiclinks.PendingDynamicLinkData
23+
import com.google.firebase.dynamiclinks.ShortDynamicLink
2224
import com.google.firebase.ktx.Firebase
2325
import com.google.firebase.ktx.app
2426
import com.google.firebase.ktx.initialize
2527
import org.junit.After
2628
import org.junit.Before
2729
import org.junit.Test
2830
import org.junit.runner.RunWith
31+
import org.mockito.Mockito.`when`
32+
import org.mockito.Mockito.mock
2933
import org.robolectric.RobolectricTestRunner
3034
import org.robolectric.RuntimeEnvironment
3135

@@ -223,4 +227,45 @@ class DynamicLinksTests : BaseTestCase() {
223227
val efr = Integer.parseInt(dynamicLink.uri.getQueryParameter("efr")!!) == 1
224228
assertThat(efr).isEqualTo(forcedRedirect)
225229
}
230+
231+
@Test
232+
fun `ShortDynamicLink destructure declaration works`() {
233+
val fakeWarning = object : ShortDynamicLink.Warning {
234+
override fun getMessage() = "Warning"
235+
override fun getCode() = "warning"
236+
}
237+
238+
val expectedShortLink = Uri.parse("https://example.com")
239+
val expectedPreviewLink = Uri.parse("https://example.com/preview")
240+
val expectedWarnings = mutableListOf<ShortDynamicLink.Warning>(fakeWarning)
241+
242+
val mockShortDynamicLink = mock(ShortDynamicLink::class.java)
243+
`when`(mockShortDynamicLink.shortLink).thenReturn(expectedShortLink)
244+
`when`(mockShortDynamicLink.previewLink).thenReturn(expectedPreviewLink)
245+
`when`(mockShortDynamicLink.warnings).thenReturn(expectedWarnings)
246+
247+
val (shortLink, previewLink, warnings) = mockShortDynamicLink
248+
249+
assertThat(shortLink).isEqualTo(expectedShortLink)
250+
assertThat(previewLink).isEqualTo(expectedPreviewLink)
251+
assertThat(warnings).isEqualTo(expectedWarnings)
252+
}
253+
254+
@Test
255+
fun `PendingDynamicLinkData destructure declaration works`() {
256+
val expectedLink = Uri.parse("https://example.com")
257+
val expectedMinAppVersion = 30
258+
val expectedTimestamp = 172947600L
259+
260+
val mockPendingData = mock(PendingDynamicLinkData::class.java)
261+
`when`(mockPendingData.link).thenReturn(expectedLink)
262+
`when`(mockPendingData.minimumAppVersion).thenReturn(expectedMinAppVersion)
263+
`when`(mockPendingData.clickTimestamp).thenReturn(expectedTimestamp)
264+
265+
val (link, minAppVersion, timestamp) = mockPendingData
266+
267+
assertThat(link).isEqualTo(expectedLink)
268+
assertThat(minAppVersion).isEqualTo(expectedMinAppVersion)
269+
assertThat(timestamp).isEqualTo(expectedTimestamp)
270+
}
226271
}

0 commit comments

Comments
 (0)