From 9c0675262ed0bb3de102059d39e31bef0df86f4b Mon Sep 17 00:00:00 2001 From: vrajdesai78 Date: Wed, 5 Oct 2022 08:59:45 +0530 Subject: [PATCH] Nit changes --- .../app/activity/route/ActivityRouter.kt | 4 +- .../route/ActivityRouterModuleTest.kt | 43 +++++++------------ .../app/activity/route/ActivityRouterTest.kt | 6 +-- 3 files changed, 21 insertions(+), 32 deletions(-) diff --git a/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt b/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt index 804867998b7..495d455f574 100644 --- a/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt +++ b/app/src/main/java/org/oppia/android/app/activity/route/ActivityRouter.kt @@ -17,11 +17,11 @@ class ActivityRouter @Inject constructor( ) { /** Opens the activity corresponding to the specified [destinationScreen]. */ fun routeToScreen(destinationScreen: DestinationScreen) { - destinationRoutes[destinationScreen.destinationScreenCase].let { route -> + destinationRoutes[destinationScreen.destinationScreenCase]?.let { route -> when (destinationScreen.destinationScreenCase) { DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS -> { activity.startActivity( - route?.createIntent( + route.createIntent( activity, destinationScreen ) diff --git a/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterModuleTest.kt b/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterModuleTest.kt index b3fb42b5c99..a51cdb2ea04 100644 --- a/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterModuleTest.kt +++ b/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterModuleTest.kt @@ -1,11 +1,13 @@ package org.oppia.android.app.activity.route import android.app.Application +import android.content.Context import androidx.appcompat.app.AppCompatActivity import androidx.test.core.app.ApplicationProvider import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import androidx.test.ext.truth.content.IntentSubject.assertThat +import com.google.common.truth.Truth.assertThat import dagger.BindsInstance import dagger.Component import org.junit.Before @@ -25,6 +27,7 @@ import org.oppia.android.app.devoptions.DeveloperOptionsModule import org.oppia.android.app.devoptions.DeveloperOptionsStarterModule import org.oppia.android.app.home.recentlyplayed.RecentlyPlayedActivity import org.oppia.android.app.model.DestinationScreen +import org.oppia.android.app.model.DestinationScreen.DestinationScreenCase import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionModule import org.oppia.android.app.shim.ViewBindingShimModule import org.oppia.android.app.testing.activity.TestActivity @@ -97,6 +100,9 @@ class ActivityRouterModuleTest { lateinit var destinationRoutes: Map + @Inject + lateinit var context: Context + @get:Rule var activityRule = ActivityScenarioRule( @@ -109,36 +115,19 @@ class ActivityRouterModuleTest { } @Test - fun testInjectActivityRouterModule_routeToRecentlyPlayedActivity() { - activityRule.scenario.onActivity { activity -> - assert( - destinationRoutes.containsKey( - DestinationScreen.DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS - ) - ) - destinationRoutes[DestinationScreen.DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS] - .let { route -> - val intent = route?.createIntent( - activity, - DestinationScreen.getDefaultInstance() - ) - assertThat(intent).hasComponentClass(RecentlyPlayedActivity::class.java) - } - } + fun testInjectDestinationRoutes_hasRouteForRecentlyPlayedActivity() { + assertThat( + destinationRoutes.containsKey(DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS) + ).isTrue() + val route = destinationRoutes[DestinationScreenCase.RECENTLY_PLAYED_ACTIVITY_PARAMS] + val intent = route?.createIntent(context, DestinationScreen.getDefaultInstance()) + assertThat(intent).hasComponentClass(RecentlyPlayedActivity::class.java) } @Test - fun testInjectActivityRouterModule_routeToDestinationScreenNotSet_showsError() { - activityRule.scenario.onActivity { activity -> - destinationRoutes[DestinationScreen.DestinationScreenCase.DESTINATIONSCREEN_NOT_SET] - .let { route -> - val intent = route?.createIntent( - activity, - DestinationScreen.getDefaultInstance() - ) - assertThat(intent).isNull() - } - } + fun testInjectDestinationRoutes_doesNotHaveRouteForDestinationScreenNotSet() { + assertThat(destinationRoutes) + .doesNotContainKey(DestinationScreenCase.DESTINATIONSCREEN_NOT_SET) } private fun setUpTestApplicationComponent() { diff --git a/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterTest.kt b/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterTest.kt index f900d05df35..c965118576b 100644 --- a/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterTest.kt +++ b/app/src/test/java/org/oppia/android/app/activity/route/ActivityRouterTest.kt @@ -6,7 +6,7 @@ import androidx.appcompat.app.AppCompatActivity import androidx.test.core.app.ApplicationProvider import androidx.test.espresso.intent.Intents import androidx.test.espresso.intent.Intents.intended -import androidx.test.espresso.intent.matcher.IntentMatchers +import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent import androidx.test.ext.junit.rules.ActivityScenarioRule import androidx.test.ext.junit.runners.AndroidJUnit4 import com.google.common.truth.Truth.assertThat @@ -127,7 +127,7 @@ class ActivityRouterTest { } @Test - fun testActivityRouter_routeToRecentlyPlayedActivity() { + fun testActivityRouter_canRouteToRecentlyPlayedActivity() { activityRule.scenario.onActivity { activity -> val activityRouter = activity.activityRouter val recentlyPlayedActivityParams = @@ -147,7 +147,7 @@ class ActivityRouterTest { RecentlyPlayedActivity.RECENTLY_PLAYED_ACTIVITY_INTENT_EXTRAS_KEY, recentlyPlayedActivityParams ), - IntentMatchers.hasComponent(RecentlyPlayedActivity::class.java.name) + hasComponent(RecentlyPlayedActivity::class.java.name) ) ) }