diff --git a/scripts/assets/test_file_exemptions.textproto b/scripts/assets/test_file_exemptions.textproto index dac453e5d9b..cf5563bb8c9 100644 --- a/scripts/assets/test_file_exemptions.textproto +++ b/scripts/assets/test_file_exemptions.textproto @@ -834,7 +834,6 @@ exempted_file_path: "utility/src/main/java/org/oppia/android/util/gcsresource/Gc exempted_file_path: "utility/src/main/java/org/oppia/android/util/locale/OppiaBidiFormatter.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/locale/OppiaLocale.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/logging/AnalyticsEventLogger.kt" -exempted_file_path: "utility/src/main/java/org/oppia/android/util/logging/ConsoleLogger.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/logging/ConsoleLoggerInjector.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/logging/ConsoleLoggerInjectorProvider.kt" exempted_file_path: "utility/src/main/java/org/oppia/android/util/logging/EventTypeToHumanReadableNameConverter.kt" diff --git a/utility/src/test/java/org/oppia/android/util/logging/BUILD.bazel b/utility/src/test/java/org/oppia/android/util/logging/BUILD.bazel index 46094493ecf..2f852a40af5 100644 --- a/utility/src/test/java/org/oppia/android/util/logging/BUILD.bazel +++ b/utility/src/test/java/org/oppia/android/util/logging/BUILD.bazel @@ -140,4 +140,35 @@ oppia_android_test( ], ) +oppia_android_test( + name = "ConsoleLoggerTest", + srcs = ["ConsoleLoggerTest.kt"], + custom_package = "org.oppia.android.util.logging", + test_class = "org.oppia.android.util.logging.ConsoleLoggerTest", + test_manifest = "//utility:test_manifest", + deps = [ + ":dagger", + ":sync_status_manager_test_base", + "//testing", + "//testing/src/main/java/org/oppia/android/testing/junit:oppia_parameterized_test_runner", + "//testing/src/main/java/org/oppia/android/testing/junit:parameterized_robolectric_test_runner", + "//testing/src/main/java/org/oppia/android/testing/data:data_provider_test_monitor", + "//testing/src/main/java/org/oppia/android/testing/robolectric:test_module", + "//testing/src/main/java/org/oppia/android/testing/threading:test_module", + "//testing/src/main/java/org/oppia/android/testing/time:test_module", + "//third_party:androidx_test_ext_junit", + "//third_party:androidx_test_ext_truth", + "//third_party:com_google_truth_truth", + "//third_party:junit_junit", + "//third_party:org_robolectric_robolectric", + "//third_party:robolectric_android-all", + "//utility/src/main/java/org/oppia/android/util/locale:prod_module", + "//utility/src/main/java/org/oppia/android/util/locale/testing:test_module", + "//utility/src/main/java/org/oppia/android/util/logging:event_bundle_creator", + "//utility/src/main/java/org/oppia/android/util/logging:standard_event_logging_configuration_module", + "//utility/src/main/java/org/oppia/android/util/logging:prod_module", + "//utility/src/main/java/org/oppia/android/util/networking:debug_module", + ], +) + dagger_rules() diff --git a/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt b/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt index b934c17a142..62745c9ce49 100644 --- a/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt +++ b/utility/src/test/java/org/oppia/android/util/logging/ConsoleLoggerTest.kt @@ -5,12 +5,14 @@ import android.content.Context import androidx.test.core.app.ApplicationProvider import androidx.test.core.content.pm.ApplicationInfoBuilder import androidx.test.core.content.pm.PackageInfoBuilder -import androidx.test.ext.truth.os.BundleSubject.assertThat import com.google.common.truth.Truth.assertThat import dagger.BindsInstance import dagger.Component import dagger.Module import dagger.Provides +import kotlinx.coroutines.flow.collect +import kotlinx.coroutines.launch +import kotlinx.coroutines.test.runBlockingTest import org.junit.Before import org.junit.Test import org.junit.runner.RunWith @@ -19,12 +21,12 @@ import org.oppia.android.testing.junit.OppiaParameterizedTestRunner import org.oppia.android.testing.junit.OppiaParameterizedTestRunner.SelectRunnerPlatform import org.oppia.android.testing.junit.ParameterizedRobolectricTestRunner import org.oppia.android.testing.robolectric.RobolectricModule +import org.oppia.android.testing.threading.TestCoroutineDispatchers import org.oppia.android.testing.threading.TestDispatcherModule import org.oppia.android.testing.time.FakeOppiaClockModule import org.oppia.android.util.data.DataProvidersInjector import org.oppia.android.util.data.DataProvidersInjectorProvider import org.oppia.android.util.locale.testing.LocaleTestModule -import org.oppia.android.util.platformparameter.LOGGING_LEARNER_STUDY_IDS_DEFAULT_VALUE import org.robolectric.Shadows import org.robolectric.annotation.Config import org.robolectric.annotation.LooperMode @@ -42,9 +44,16 @@ class ConsoleLoggerTest { @Inject lateinit var context: Context @Inject lateinit var consoleLogger: ConsoleLogger + @Inject + lateinit var testCoroutineDispatchers: TestCoroutineDispatchers + private val testVersionName = "1.0" private val testVersionCode = 1 + private val testTag = "tag" + private val testLogLevel: LogLevel = LogLevel.ERROR + private val testMessage = "test error message" + @Before fun setUp() { setUpTestApplicationComponent() @@ -52,8 +61,20 @@ class ConsoleLoggerTest { } @Test - fun dummyTest() { - assertThat(true).isTrue() + fun testConsoleLogger_logError_withMessage_logsMessage() = runBlockingTest { + val consoleJob = launch { + consoleLogger.logErrorMessagesFlow.collect { + assertThat(it.logTag).isEqualTo(testTag) + assertThat(it.logLevel).isEqualTo(testLogLevel.toString()) + assertThat(it.fullErrorLog).isEqualTo(testMessage) + } + } + + consoleLogger.e(testTag, testMessage) + + testCoroutineDispatchers.advanceUntilIdle() + + consoleJob.cancel() } private fun setUpTestApplicationComponent() { @@ -109,6 +130,7 @@ class ConsoleLoggerTest { FakeOppiaClockModule::class, ] ) + interface TestApplicationComponent : DataProvidersInjector { @Component.Builder interface Builder {