Skip to content

Commit

Permalink
feat: Add test file for the console logger file
Browse files Browse the repository at this point in the history
  • Loading branch information
kkmurerwa committed Jan 23, 2024
1 parent b03b19f commit 466f2ce
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 5 deletions.
1 change: 0 additions & 1 deletion scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down
31 changes: 31 additions & 0 deletions utility/src/test/java/org/oppia/android/util/logging/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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
Expand All @@ -42,18 +44,37 @@ 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()
setUpApplicationForContext()
}

@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() {
Expand Down Expand Up @@ -109,6 +130,7 @@ class ConsoleLoggerTest {
FakeOppiaClockModule::class,
]
)

interface TestApplicationComponent : DataProvidersInjector {
@Component.Builder
interface Builder {
Expand Down

0 comments on commit 466f2ce

Please sign in to comment.