Skip to content

Commit

Permalink
For mozilla-mobile#15310: Add test for ActivityNotFoundException when…
Browse files Browse the repository at this point in the history
… sharing to app.
  • Loading branch information
mcarare committed Sep 28, 2020
1 parent 6289da8 commit daced89
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions app/src/test/java/org/mozilla/fenix/share/ShareControllerTest.kt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package org.mozilla.fenix.share

import android.app.Activity
import android.content.ActivityNotFoundException
import android.content.Context
import android.content.Intent
import androidx.navigation.NavController
Expand Down Expand Up @@ -141,6 +142,31 @@ class ShareControllerTest {
}
}

@Test
fun `handleShareToApp should dismiss with an error start when a ActivityNotFoundException occurs`() {
val appPackageName = "package"
val appClassName = "activity"
val appShareOption = AppShareOption("app", mockk(), appPackageName, appClassName)
val shareIntent = slot<Intent>()
// Our share Intent uses `FLAG_ACTIVITY_NEW_TASK` but when resolving the startActivity call
// needed for capturing the actual Intent used the `slot` one doesn't have this flag so we
// need to use an Activity Context.
val activityContext: Context = mockk<Activity>()
val testController = DefaultShareController(activityContext, shareSubject, shareData, mockk(),
snackbar, mockk(), mockk(), testCoroutineScope, dismiss)
every { activityContext.startActivity(capture(shareIntent)) } throws ActivityNotFoundException()
every { activityContext.getString(R.string.share_error_snackbar) } returns "Cannot share to this app"

testController.handleShareToApp(appShareOption)

verifyOrder {
activityContext.startActivity(shareIntent.captured)
snackbar.setText("Cannot share to this app")
snackbar.show()
dismiss(ShareController.Result.SHARE_ERROR)
}
}

@Test
@Suppress("DeferredResultUnused")
fun `handleShareToDevice should share to account device, inform callbacks and dismiss`() {
Expand Down

0 comments on commit daced89

Please sign in to comment.