Skip to content

Commit

Permalink
Update test for commit CoperFragment only before onStateSaved (#45)
Browse files Browse the repository at this point in the history
  • Loading branch information
swnishan authored May 27, 2024
1 parent 52f32c5 commit 8210a6c
Showing 1 changed file with 14 additions and 1 deletion.
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

0 comments on commit 8210a6c

Please sign in to comment.