From bf42220422f747f00c570221e0897bad7a15dcec Mon Sep 17 00:00:00 2001 From: Maxime NATUREL Date: Mon, 26 Sep 2022 10:08:59 +0200 Subject: [PATCH] Unit tests for view navigator --- .../overview/SessionOverviewViewNavigator.kt | 1 - .../SessionOverviewViewNavigatorTest.kt | 18 ++++++++++++++++++ 2 files changed, 18 insertions(+), 1 deletion(-) diff --git a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigator.kt b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigator.kt index ba5c3181d2..0cb95bae7d 100644 --- a/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigator.kt +++ b/vector/src/main/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigator.kt @@ -32,7 +32,6 @@ class SessionOverviewViewNavigator @Inject constructor() { context.startActivity(RenameSessionActivity.newIntent(context, deviceId)) } - // TODO add unit test fun goBack(fragmentActivity: FragmentActivity) { fragmentActivity.finish() } diff --git a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt index 3d38f3b3bf..e309c05042 100644 --- a/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt @@ -17,12 +17,15 @@ package im.vector.app.features.settings.devices.v2.overview import android.content.Intent +import androidx.fragment.app.FragmentActivity import im.vector.app.features.settings.devices.v2.details.SessionDetailsActivity import im.vector.app.features.settings.devices.v2.rename.RenameSessionActivity import im.vector.app.test.fakes.FakeContext import io.mockk.every +import io.mockk.just import io.mockk.mockk import io.mockk.mockkObject +import io.mockk.runs import io.mockk.unmockkAll import io.mockk.verify import org.junit.After @@ -77,6 +80,21 @@ class SessionOverviewViewNavigatorTest { } } + @Test + fun `given an activity when going back then the activity is finished`() { + // Given + val fragmentActivity = mockk() + every { fragmentActivity.finish() } just runs + + // When + sessionOverviewViewNavigator.goBack(fragmentActivity) + + // Then + verify { + fragmentActivity.finish() + } + } + private fun givenIntentForSessionDetails(sessionId: String): Intent { val intent = mockk() every { SessionDetailsActivity.newIntent(context.instance, sessionId) } returns intent