Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #5393: Make hasProtoExtra centralized. #5446

Merged
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
21 commits
Select commit Hold shift + click to select a range
df189df
Centralized hasProtoExtra matcher
Vishwajith-Shettigar Jun 27, 2024
140c0ab
Klint
Vishwajith-Shettigar Jun 27, 2024
06bd74c
bazel build error fix
Vishwajith-Shettigar Jun 27, 2024
90f43d9
Merge branch 'develop' into centralize-hasprotoextra
Vishwajith-Shettigar Jun 27, 2024
24b6152
fix build test error
Vishwajith-Shettigar Jun 27, 2024
20ff8cc
fix bazel lint
Vishwajith-Shettigar Jun 27, 2024
fe4d4ef
fix build test error
Vishwajith-Shettigar Jun 27, 2024
d0ef035
fix
Vishwajith-Shettigar Jun 27, 2024
ad2bb79
fix checks failing
Vishwajith-Shettigar Jun 28, 2024
d9b9fbd
syntax error fix
Vishwajith-Shettigar Jun 28, 2024
7abef18
fix failing checks
Vishwajith-Shettigar Jun 28, 2024
0133021
reformat bazel.build
Vishwajith-Shettigar Jun 28, 2024
b08b5a4
Merge branch 'develop' into centralize-hasprotoextra
Vishwajith-Shettigar Jun 28, 2024
3fce23e
Merge branch 'develop' into centralize-hasprotoextra
Vishwajith-Shettigar Jun 29, 2024
9bc668d
Merge branch 'develop' into centralize-hasprotoextra
Vishwajith-Shettigar Jun 30, 2024
688695b
Merge branch 'develop' into centralize-hasprotoextra
Vishwajith-Shettigar Jul 1, 2024
2bef747
Merge branch 'develop' into centralize-hasprotoextra
Vishwajith-Shettigar Jul 2, 2024
6d8f714
Add kdoc and remove file from kdoc_validity_excemptions
Vishwajith-Shettigar Jul 2, 2024
6290c85
Remove file path from kdoc exemptions
Vishwajith-Shettigar Jul 2, 2024
e10baab
fake changes
Vishwajith-Shettigar Jul 2, 2024
015c070
trigger re-run checks
Vishwajith-Shettigar Jul 2, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions app/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -844,6 +844,7 @@ kt_android_library(
"src/sharedTest/java/org/oppia/android/app/utility/FontSizeMatcher.kt",
"src/sharedTest/java/org/oppia/android/app/utility/OrientationChangeAction.kt",
"src/sharedTest/java/org/oppia/android/app/utility/ProgressMatcher.kt",
"src/sharedTest/java/org/oppia/android/app/utility/ProtoExtraMatcher.kt",
"src/sharedTest/java/org/oppia/android/app/utility/TabMatcher.kt",
],
visibility = [
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,20 +14,15 @@ import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withContentDescription
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand All @@ -53,6 +48,7 @@ import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositi
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.TopicActivity
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -100,7 +96,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.extractCurrentAppScreenName
Expand Down Expand Up @@ -507,20 +502,6 @@ class CompletedStoryListActivityTest {
}
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

private fun createCompletedStoryListActivityIntent(internalProfileId: Int): Intent {
return CompletedStoryListActivity.createCompletedStoryListActivityIntent(
ApplicationProvider.getApplicationContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@ package org.oppia.android.app.faq

import android.app.Application
import android.content.Context
import android.content.Intent
import android.content.res.Resources
import androidx.appcompat.app.AppCompatActivity
import androidx.recyclerview.widget.RecyclerView
Expand All @@ -19,12 +18,8 @@ import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand All @@ -51,6 +46,7 @@ import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositi
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -93,7 +89,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.EventLoggingConfigurationModule
Expand Down Expand Up @@ -229,20 +224,6 @@ class FAQListFragmentTest {
}.build()
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

private fun setUpTestApplicationComponent() {
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,6 @@ import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.matcher.RootMatchers.isDialog
import androidx.test.espresso.matcher.ViewMatchers.Visibility
import androidx.test.espresso.matcher.ViewMatchers.isDisplayed
Expand All @@ -31,12 +30,10 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.CoreMatchers.allOf
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
import org.hamcrest.core.IsNot.not
import org.junit.After
Expand Down Expand Up @@ -84,6 +81,7 @@ import org.oppia.android.app.topic.TopicActivity
import org.oppia.android.app.translation.AppLanguageLocaleHandler
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.translation.testing.TestActivityRecreator
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.FontScaleConfigurationUtil
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
Expand Down Expand Up @@ -141,7 +139,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.extractCurrentAppScreenName
Expand Down Expand Up @@ -2034,20 +2031,6 @@ class HomeActivityTest {
dataProviderTestMonitor.waitForNextSuccessfulResult(profileTestHelper.logIntoUser())
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,15 +27,11 @@ import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.Matchers.containsString
import org.hamcrest.Matchers.instanceOf
import org.hamcrest.Matchers.not
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -69,6 +65,7 @@ import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.hasGridI
import org.oppia.android.app.resumelesson.ResumeLessonActivity
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.EspressoTestsMatchers.withDrawable
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
Expand Down Expand Up @@ -123,7 +120,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.extractCurrentAppScreenName
Expand Down Expand Up @@ -1458,20 +1454,6 @@ class RecentlyPlayedFragmentTest {
.commitNow()
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,19 +14,14 @@ import androidx.test.espresso.contrib.RecyclerViewActions.scrollToPosition
import androidx.test.espresso.intent.Intents
import androidx.test.espresso.intent.Intents.intended
import androidx.test.espresso.intent.matcher.IntentMatchers.hasComponent
import androidx.test.espresso.intent.matcher.IntentMatchers.hasExtra
import androidx.test.espresso.matcher.ViewMatchers.isRoot
import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.common.truth.Truth.assertThat
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.CoreMatchers.containsString
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand All @@ -52,6 +47,7 @@ import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositi
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.topic.TopicActivity
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -98,7 +94,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.CurrentAppScreenNameIntentDecorator.extractCurrentAppScreenName
Expand Down Expand Up @@ -452,20 +447,6 @@ class OngoingTopicListActivityTest {
}
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

private fun createOngoingTopicListActivityIntent(internalProfileId: Int): Intent {
return OngoingTopicListActivity.createOngoingTopicListActivityIntent(
ApplicationProvider.getApplicationContext(),
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,12 +22,8 @@ import androidx.test.espresso.matcher.ViewMatchers.withId
import androidx.test.espresso.matcher.ViewMatchers.withText
import androidx.test.ext.junit.runners.AndroidJUnit4
import androidx.test.rule.ActivityTestRule
import com.google.protobuf.MessageLite
import dagger.Component
import org.hamcrest.Description
import org.hamcrest.Matcher
import org.hamcrest.Matchers.allOf
import org.hamcrest.TypeSafeMatcher
import org.junit.After
import org.junit.Before
import org.junit.Rule
Expand Down Expand Up @@ -56,6 +52,7 @@ import org.oppia.android.app.player.state.itemviewmodel.SplitScreenInteractionMo
import org.oppia.android.app.recyclerview.RecyclerViewMatcher.Companion.atPositionOnView
import org.oppia.android.app.shim.ViewBindingShimModule
import org.oppia.android.app.translation.testing.ActivityRecreatorTestModule
import org.oppia.android.app.utility.EspressoTestsMatchers.hasProtoExtra
import org.oppia.android.app.utility.OrientationChangeAction.Companion.orientationLandscape
import org.oppia.android.data.backends.gae.NetworkConfigProdModule
import org.oppia.android.data.backends.gae.NetworkModule
Expand Down Expand Up @@ -103,7 +100,6 @@ import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.accessibility.AccessibilityTestModule
import org.oppia.android.util.caching.AssetModule
import org.oppia.android.util.caching.testing.CachingTestModule
import org.oppia.android.util.extensions.getProtoExtra
import org.oppia.android.util.gcsresource.GcsResourceModule
import org.oppia.android.util.locale.LocaleProdModule
import org.oppia.android.util.logging.EventLoggingConfigurationModule
Expand Down Expand Up @@ -604,20 +600,6 @@ class OptionsFragmentTest {
testCoroutineDispatchers.runCurrent()
}

private fun <T : MessageLite> hasProtoExtra(keyName: String, expectedProto: T): Matcher<Intent> {
val defaultProto = expectedProto.newBuilderForType().build()
return object : TypeSafeMatcher<Intent>() {
override fun describeTo(description: Description) {
description.appendText("Intent with extra: $keyName and proto value: $expectedProto")
}

override fun matchesSafely(intent: Intent): Boolean {
return intent.hasExtra(keyName) &&
intent.getProtoExtra(keyName, defaultProto) == expectedProto
}
}
}

// TODO(#59): Figure out a way to reuse modules instead of needing to re-declare them.
@Singleton
@Component(
Expand Down
Loading
Loading