Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Update test for commit CoperFragment only before onStateSaved #45

Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
15 changes: 14 additions & 1 deletion library/src/test/java/com/vinted/coper/CoperImplTest.kt
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package com.vinted.coper

import android.content.pm.PackageManager
import android.os.Bundle
import android.os.Looper.getMainLooper
import androidx.core.content.PermissionChecker
import androidx.fragment.app.FragmentActivity
Expand Down Expand Up @@ -398,7 +399,7 @@ class CoperImplTest {
@Test
fun getFragment_lifecycleAlreadyAfterCreated_fragmentTransactionMade() = runTest {
val activityController = Robolectric.buildActivity(FragmentActivity::class.java)
val activity = activityController.setup().pause().get()
val activity = activityController.setup().resume().get()
val fixture = getCoperInstance(
lifecycle = activity.lifecycle,
fragmentManager = activity.supportFragmentManager
Expand All @@ -411,6 +412,18 @@ class CoperImplTest {
assertEquals(fragment, activity.supportFragmentManager.findFragmentByTag(FRAGMENT_TAG))
}

@Test(expected = CancellationException::class)
fun getFragment_lifecycleAlreadyStateSaved_throwCancellationException() = runTest {
val activityController = Robolectric.buildActivity(FragmentActivity::class.java)
val activity = activityController.setup().saveInstanceState(Bundle()).get()
val fixture = getCoperInstance(
lifecycle = activity.lifecycle,
fragmentManager = activity.supportFragmentManager
)

runIdlingMainThread { fixture.getFragmentSafely() }
}

@Test
fun request_onIoThread_shouldNotCrash() = runTest {
val fixture = getCoperInstance()
Expand Down
Loading