Skip to content

Commit

Permalink
Nit changes
Browse files Browse the repository at this point in the history
  • Loading branch information
vrajdesai78 committed Oct 5, 2022
1 parent 451500f commit 9c06752
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 32 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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
)
Expand Down
Original file line number Diff line number Diff line change
@@ -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
Expand All @@ -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
Expand Down Expand Up @@ -97,6 +100,9 @@ class ActivityRouterModuleTest {
lateinit var destinationRoutes:
Map<DestinationScreen.DestinationScreenCase, @JvmSuppressWildcards Route>

@Inject
lateinit var context: Context

@get:Rule
var activityRule =
ActivityScenarioRule<TestActivity>(
Expand All @@ -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() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -127,7 +127,7 @@ class ActivityRouterTest {
}

@Test
fun testActivityRouter_routeToRecentlyPlayedActivity() {
fun testActivityRouter_canRouteToRecentlyPlayedActivity() {
activityRule.scenario.onActivity { activity ->
val activityRouter = activity.activityRouter
val recentlyPlayedActivityParams =
Expand All @@ -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)
)
)
}
Expand Down

0 comments on commit 9c06752

Please sign in to comment.