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

[RunAllTests] Fix #5303, #5304, #5305, #5306, #5309, part of #5307, part of #5308: Fix a variety of dev platform-specific issues #5138

Merged
merged 30 commits into from
Feb 14, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
30 commits
Select commit Hold shift + click to select a range
667bf89
Fix a variety of dev platform-specific issues.
BenHenning Aug 22, 2023
fb59232
Tidy some things up, and revert fragment test.
BenHenning Aug 28, 2023
2551d4b
Fix test behavior inconsistency in test.
BenHenning Sep 11, 2023
714f3ea
Merge branch 'develop' into fix-platform-specific-issues
BenHenning Sep 11, 2023
7488b9f
Fix broken ProfileAndDeviceIdFragmentTest test.
BenHenning Sep 13, 2023
e3d4091
Merge branch 'develop' into fix-platform-specific-issues
BenHenning Oct 26, 2023
5671673
Post-merge fix.
BenHenning Oct 26, 2023
bd1466d
Merge branch 'develop' into fix-platform-specific-issues
BenHenning Jan 16, 2024
79878cd
Some more robustness fixes.
BenHenning Jan 19, 2024
bd97611
Fix BUILD file lint issue.
BenHenning Jan 20, 2024
211487c
Merge branch 'develop' into fix-platform-specific-issues
BenHenning Feb 6, 2024
1a666a9
Post-merge fixes.
BenHenning Feb 6, 2024
a2ee5d3
Add smoke tests for instr. binaries & tests.
BenHenning Feb 7, 2024
d5b9012
Some minor refactoring for readability.
BenHenning Feb 7, 2024
e6ec869
Fixed broken instrumentation builds.
BenHenning Feb 7, 2024
9f50469
Merge branch 'develop' into fix-instrumentation-build-failure
BenHenning Feb 7, 2024
8dbf4dc
Add missing CODEOWNERS line.
BenHenning Feb 7, 2024
9c38057
Remove old files from CODEOWNERS.
BenHenning Feb 7, 2024
f2ff4e3
Merge branch 'fix-instrumentation-build-failure' into fix-platform-sp…
BenHenning Feb 7, 2024
fad48ed
Add missing tests for TestBlazeWorkspace changes.
BenHenning Feb 8, 2024
e1802c8
Add missing Firebase auth tests.
BenHenning Feb 8, 2024
00c32f6
Merge branch 'fix-instrumentation-build-failure' into fix-platform-sp…
BenHenning Feb 8, 2024
d3cbd93
Post-merge fixes for previously missed tests.
BenHenning Feb 8, 2024
50f41d2
Merge branch 'develop' into fix-instrumentation-build-failure
BenHenning Feb 8, 2024
c8df70e
Merge branch 'fix-instrumentation-build-failure' into fix-platform-sp…
BenHenning Feb 8, 2024
c85d421
Merge branch 'develop' into fix-instrumentation-build-failure
BenHenning Feb 9, 2024
dcf27b6
Merge branch 'fix-instrumentation-build-failure' into fix-platform-sp…
BenHenning Feb 9, 2024
2369514
Merge branch 'develop' into fix-platform-specific-issues
BenHenning Feb 9, 2024
2916770
Update scripts/src/javatests/org/oppia/android/scripts/common/GitClie…
BenHenning Feb 14, 2024
f2d810a
Merge branch 'develop' into fix-platform-specific-issues
BenHenning Feb 14, 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
Original file line number Diff line number Diff line change
Expand Up @@ -51,6 +51,7 @@ app_test(
"//app/src/main/java/org/oppia/android/app/translation/testing:test_module",
"//testing",
"//testing/src/main/java/org/oppia/android/testing/junit:initialize_default_locale_rule",
"//testing/src/main/java/org/oppia/android/testing/logging:event_log_subject",
"//testing/src/main/java/org/oppia/android/testing/logging:sync_status_test_module",
"//testing/src/main/java/org/oppia/android/testing/platformparameter:test_module",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
Expand Down

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
Expand Up @@ -418,7 +418,7 @@ class DeveloperOptionsFragmentTest {
createDeveloperOptionsTestActivityIntent(internalProfileId)
).use {
testCoroutineDispatchers.runCurrent()
val exception = assertThrows(RuntimeException::class) {
val exception = assertThrows<RuntimeException>() {
scrollToPosition(position = 2)
onView(withId(R.id.force_crash_text_view)).perform(click())
}
Expand All @@ -433,7 +433,7 @@ class DeveloperOptionsFragmentTest {
).use {
testCoroutineDispatchers.runCurrent()
onView(isRoot()).perform(orientationLandscape())
val exception = assertThrows(RuntimeException::class) {
val exception = assertThrows<RuntimeException>() {
scrollToPosition(position = 2)
onView(withId(R.id.force_crash_text_view)).perform(click())
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -232,7 +232,7 @@ class StringToRatioParserTest {

@Test
fun testParser_parseRatioOrThrow_ratioWithInvalidRatio_throwsException() {
val exception = assertThrows(IllegalArgumentException::class) {
val exception = assertThrows<IllegalArgumentException>() {
stringToRatioParser.parseRatioOrThrow("a:b:c")
}
assertThat(exception)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ class AppLanguageLocaleHandlerTest {

@Test
fun testGetDisplayLocale_initialState_throwsException() {
val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
appLanguageLocaleHandler.getDisplayLocale()
}

Expand Down Expand Up @@ -103,7 +103,7 @@ class AppLanguageLocaleHandlerTest {
fun testInitializeLocale_twice_throwsException() {
appLanguageLocaleHandler.initializeLocale(computeNewAppLanguageLocale(ENGLISH))

val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
appLanguageLocaleHandler.initializeLocale(retrieveAppLanguageLocale())
}

Expand All @@ -117,7 +117,7 @@ class AppLanguageLocaleHandlerTest {
fun testUpdateLocale_uninitialized_throwsException() {
setAppLanguage(ENGLISH)

val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
appLanguageLocaleHandler.updateLocale(retrieveAppLanguageLocale())
}

Expand Down Expand Up @@ -186,7 +186,7 @@ class AppLanguageLocaleHandlerTest {
fun testInitializeLocaleForActivity_uninitialized_throwsException() {
val configuration = Configuration()

val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
appLanguageLocaleHandler.initializeLocaleForActivity(configuration)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -242,7 +242,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) { handler.getStringInLocale(-1) }
assertThrows<Resources.NotFoundException>() { handler.getStringInLocale(-1) }
}

@Test
Expand Down Expand Up @@ -279,7 +279,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) { handler.getStringInLocaleWithWrapping(-1) }
assertThrows<Resources.NotFoundException>() { handler.getStringInLocaleWithWrapping(-1) }
}

@Test
Expand Down Expand Up @@ -316,7 +316,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) {
assertThrows<Resources.NotFoundException>() {
handler.getStringInLocaleWithoutWrapping(-1)
}
}
Expand All @@ -336,7 +336,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) { handler.getStringArrayInLocale(-1) }
assertThrows<Resources.NotFoundException>() { handler.getStringArrayInLocale(-1) }
}

@Test
Expand Down Expand Up @@ -366,7 +366,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) { handler.getQuantityStringInLocale(-1, 0) }
assertThrows<Resources.NotFoundException>() { handler.getQuantityStringInLocale(-1, 0) }
}

@Test
Expand Down Expand Up @@ -397,7 +397,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) {
assertThrows<Resources.NotFoundException>() {
handler.getQuantityStringInLocaleWithWrapping(-1, 0)
}
}
Expand Down Expand Up @@ -432,7 +432,7 @@ class AppLanguageResourceHandlerTest {
updateAppLanguageTo(OppiaLanguage.ENGLISH)
val handler = retrieveAppLanguageResourceHandler()

assertThrows(Resources.NotFoundException::class) {
assertThrows<Resources.NotFoundException>() {
handler.getQuantityStringInLocaleWithoutWrapping(-1, 0)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,7 +28,15 @@ class LoggingIdentifierController @Inject constructor(
private val persistentCacheStoreFactory: PersistentCacheStore.Factory,
private val oppiaLogger: OppiaLogger
) {
private val learnerIdRandom by lazy { Random(applicationIdSeed) }
// Use a base random to compute the per-ID random IDs in order so that test behaviors are
// consistent and deterministic when fixing the application ID seed.
private val baseRandom = Random(applicationIdSeed)
private val installationRandomSeed = baseRandom.nextLong()
private val sessionRandomSeed = baseRandom.nextLong()
private val learnerRandomSeed = baseRandom.nextLong()
private val installationIdRandom by lazy { Random(installationRandomSeed) }
private val sessionIdRandom by lazy { Random(sessionRandomSeed) }
private val learnerIdRandom by lazy { Random(learnerRandomSeed) }

private val sessionId by lazy { MutableStateFlow(computeSessionId()) }
private val sessionIdDataProvider by lazy {
Expand Down Expand Up @@ -113,12 +121,12 @@ class LoggingIdentifierController @Inject constructor(
sessionId.value = computeSessionId()
}

private fun computeSessionId(): String = learnerIdRandom.randomUuid().toString()
private fun computeSessionId(): String = sessionIdRandom.randomUuid().toString()

private fun computeInstallationId(): String {
return machineLocale.run {
MessageDigest.getInstance("SHA-1")
.digest(learnerIdRandom.randomUuid().toString().toByteArray())
.digest(installationIdRandom.randomUuid().toString().toByteArray())
.joinToString("") { "%02x".formatForMachines(it) }
.substring(startIndex = 0, endIndex = 12)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -435,7 +435,7 @@ class AudioPlayerControllerTest {
@Test
fun testController_notInitialized_releasePlayer_fails() {
setUpMediaReadyApplication()
val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
audioPlayerController.releaseMediaPlayer()
}

Expand All @@ -446,7 +446,7 @@ class AudioPlayerControllerTest {
@Test
fun testError_notPrepared_invokePlay_fails() {
setUpMediaReadyApplication()
val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
audioPlayerController.play(isPlayingFromAutoPlay = false, reloadingMainContent = false)
}

Expand All @@ -456,7 +456,7 @@ class AudioPlayerControllerTest {
@Test
fun testError_notPrepared_invokePause_fails() {
setUpMediaReadyApplication()
val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
audioPlayerController.pause(isFromExplicitUserAction = true)
}

Expand All @@ -466,7 +466,7 @@ class AudioPlayerControllerTest {
@Test
fun testError_notPrepared_invokeSeekTo_fails() {
setUpMediaReadyApplication()
val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
audioPlayerController.seekTo(500)
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,13 +11,21 @@ import dagger.Module
import dagger.Provides
import kotlinx.coroutines.CoroutineDispatcher
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.ArgumentCaptor
import org.mockito.Captor
import org.mockito.Mock
import org.mockito.Mockito.verify
import org.mockito.Mockito.verifyNoInteractions
import org.mockito.junit.MockitoJUnit
import org.mockito.junit.MockitoRule
import org.oppia.android.domain.oppialogger.analytics.ApplicationLifecycleModule
import org.oppia.android.testing.TestLogReportingModule
import org.oppia.android.testing.assertThrows
import org.oppia.android.testing.firebase.FakeFirebaseAuthWrapperImpl
import org.oppia.android.testing.firebase.TestAuthenticationModule
import org.oppia.android.testing.mockito.capture
import org.oppia.android.testing.robolectric.RobolectricModule
import org.oppia.android.testing.time.FakeOppiaClockModule
import org.oppia.android.util.data.DataProvidersInjector
Expand All @@ -36,66 +44,66 @@ import javax.inject.Singleton
@LooperMode(LooperMode.Mode.PAUSED)
@Config(application = AuthenticationControllerTest.TestApplication::class)
class AuthenticationControllerTest {
@Inject
lateinit var firebaseAuthWrapper: FirebaseAuthWrapper
@field:[Rule JvmField] val mockitoRule: MockitoRule = MockitoJUnit.rule()

@Inject
lateinit var fakeFirebaseAuthWrapperImpl: FakeFirebaseAuthWrapperImpl
@Inject lateinit var firebaseAuthWrapper: FirebaseAuthWrapper
@Inject lateinit var fakeFirebaseAuthWrapperImpl: FakeFirebaseAuthWrapperImpl
@Inject lateinit var authenticationController: AuthenticationController
@field:[Inject BackgroundDispatcher] lateinit var backgroundDispatcher: CoroutineDispatcher

@Inject
lateinit var authenticationController: AuthenticationController

@field:[Inject BackgroundDispatcher]
lateinit var backgroundDispatcher: CoroutineDispatcher
@Mock lateinit var mockFakeSuccessCallback: FakeSuccessCallback
@Mock lateinit var mockFakeFailureCallback: FakeFailureCallback
@Captor lateinit var throwableCaptor: ArgumentCaptor<Throwable>

@Before
fun setUp() {
setUpTestApplicationComponent()
}

@Test
fun testAuthentication_getCurrentUser_userSignedIn_returnsInstanceOfFirebaseUserWrapper() {
fun testAuthentication_signInAnonymously_onlyOnSuccessCalled() {
fakeFirebaseAuthWrapperImpl.simulateSignInSuccess()

firebaseAuthWrapper.signInAnonymously(
onSuccess = {},
onFailure = {}
onSuccess = mockFakeSuccessCallback::onSuccess,
onFailure = mockFakeFailureCallback::onFailure
)

val user = authenticationController.currentFirebaseUser

assertThat(user).isInstanceOf(FirebaseUserWrapper::class.java)
// onSuccess should be called.
verify(mockFakeSuccessCallback).onSuccess()
verifyNoInteractions(mockFakeFailureCallback)
}

@Test
fun testAuthentication_signInAnonymously_succeeds() {
fakeFirebaseAuthWrapperImpl.simulateSignInSuccess()
fun testAuthentication_signInAnonymously_onlyOnFailureCalled() {
fakeFirebaseAuthWrapperImpl.simulateSignInFailure()

firebaseAuthWrapper.signInAnonymously(
onSuccess = {},
onFailure = {}
onSuccess = mockFakeSuccessCallback::onSuccess,
onFailure = mockFakeFailureCallback::onFailure
)

val user = authenticationController.currentFirebaseUser

assertThat(user).isInstanceOf(FirebaseUserWrapper::class.java)
// onFailure should be called with the failure details.
verify(mockFakeFailureCallback).onFailure(capture(throwableCaptor))
verifyNoInteractions(mockFakeSuccessCallback)
assertThat(throwableCaptor.value).hasMessageThat().contains("Sign-in failure")
}

@Test
fun testAuthentication_signInAnonymously_failure_returnsException() {
fakeFirebaseAuthWrapperImpl.simulateSignInFailure()
fun testAuthentication_getCurrentUser_userSignedIn_returnsInstanceOfFirebaseUserWrapper() {
fakeFirebaseAuthWrapperImpl.simulateSignInSuccess()
firebaseAuthWrapper.signInAnonymously(
onSuccess = mockFakeSuccessCallback::onSuccess,
onFailure = mockFakeFailureCallback::onFailure
)

assertThrows(Throwable::class) {
firebaseAuthWrapper.signInAnonymously(
onSuccess = {},
onFailure = {}
)
}
val user = authenticationController.currentFirebaseUser

assertThat(user).isInstanceOf(FirebaseUserWrapper::class.java)
}

private fun setUpTestApplicationComponent() {
ApplicationProvider.getApplicationContext<TestApplication>()
.inject(this)
ApplicationProvider.getApplicationContext<TestApplication>().inject(this)
}

@Module
Expand Down Expand Up @@ -141,4 +149,8 @@ class AuthenticationControllerTest {

override fun getDataProvidersInjector(): DataProvidersInjector = component
}

interface FakeSuccessCallback { fun onSuccess() }

interface FakeFailureCallback { fun onFailure(failure: Throwable) }
}
Original file line number Diff line number Diff line change
Expand Up @@ -152,7 +152,7 @@ class AnswerClassificationControllerTest {
fun testClassify_forUnknownInteraction_throwsException() {
val interaction = Interaction.getDefaultInstance()

val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
answerClassificationController.classify(
interaction,
TEST_STRING_0,
Expand All @@ -170,7 +170,7 @@ class AnswerClassificationControllerTest {
.addAnswerGroups(AnswerGroup.newBuilder().addRuleSpecs(RuleSpec.getDefaultInstance()))
.build()

val exception = assertThrows(IllegalStateException::class) {
val exception = assertThrows<IllegalStateException>() {
answerClassificationController.classify(
interaction,
TEST_STRING_0,
Expand Down
Loading
Loading