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 d6e94238ed..ef61856255 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 @@ -20,7 +20,6 @@ import android.content.Context import im.vector.app.features.settings.devices.v2.details.SessionDetailsActivity import javax.inject.Inject -// TODO add unit tests class SessionOverviewViewNavigator @Inject constructor() { fun navigateToSessionDetails(context: Context, deviceId: String) { 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 new file mode 100644 index 0000000000..56f1e5920d --- /dev/null +++ b/vector/src/test/java/im/vector/app/features/settings/devices/v2/overview/SessionOverviewViewNavigatorTest.kt @@ -0,0 +1,68 @@ +/* + * Copyright (c) 2022 New Vector Ltd + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ + +package im.vector.app.features.settings.devices.v2.overview + +import android.content.Intent +import im.vector.app.features.settings.devices.v2.details.SessionDetailsActivity +import im.vector.app.test.fakes.FakeContext +import io.mockk.every +import io.mockk.mockk +import io.mockk.mockkObject +import io.mockk.unmockkAll +import io.mockk.verify +import org.junit.After +import org.junit.Before +import org.junit.Test + +private const val A_SESSION_ID = "session_id" + +class SessionOverviewViewNavigatorTest { + + private val context = FakeContext() + private val sessionOverviewViewNavigator = SessionOverviewViewNavigator() + + @Before + fun setUp() { + mockkObject(SessionDetailsActivity) + } + + @After + fun tearDown() { + unmockkAll() + } + + @Test + fun `given a session id when navigating to details then it starts the correct activity`() { + // Given + val intent = givenIntentForSessionDetails(A_SESSION_ID) + context.givenStartActivity(intent) + + // When + sessionOverviewViewNavigator.navigateToSessionDetails(context.instance, A_SESSION_ID) + + // Then + verify { + context.instance.startActivity(intent) + } + } + + private fun givenIntentForSessionDetails(sessionId: String): Intent { + val intent = mockk() + every { SessionDetailsActivity.newIntent(context.instance, sessionId) } returns intent + return intent + } +}