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

Fixes #4272: Added Tests for EventLogSubject. #5678

Open
wants to merge 9 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
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
4 changes: 0 additions & 4 deletions scripts/assets/test_file_exemptions.textproto
Original file line number Diff line number Diff line change
Expand Up @@ -4090,10 +4090,6 @@ test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/lightweightcheckpointing/ExplorationCheckpointTestHelper.kt"
source_file_is_incompatible_with_code_coverage: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/logging/EventLogSubject.kt"
test_file_not_required: true
}
test_file_exemption {
exempted_file_path: "testing/src/main/java/org/oppia/android/testing/logging/SyncStatusTestModule.kt"
override_min_coverage_percent_required: 0
Expand Down
adhiamboperes marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -70,8 +70,6 @@ import org.oppia.android.app.model.UserTypeAnswer
import org.oppia.android.app.model.WrittenTranslationLanguageSelection
import org.oppia.android.testing.logging.EventLogSubject.Companion.assertThat

// TODO(#4272): Add tests for this class.
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do a global search and remove any other occurrances of this TODO(#4272).


/**
* Truth subject for verifying properties of [EventLog]s.
*
Expand All @@ -80,7 +78,6 @@ import org.oppia.android.testing.logging.EventLogSubject.Companion.assertThat
*
* Call [assertThat] to create the subject.
*/
@Suppress("unused", "MemberVisibilityCanBePrivate") // TODO(#4272): Remove suppression when tested.
class EventLogSubject private constructor(
metadata: FailureMetadata,
private val actual: EventLog
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,17 @@ oppia_android_test(
"//utility/src/main/java/org/oppia/android/util/networking:debug_module",
],
)

oppia_android_test(
name = "EventLogSubjectTest",
srcs = ["EventLogSubjectTest.kt"],
custom_package = "org.oppia.android.testing.logging",
test_class = "org.oppia.android.testing.logging.EventLogSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//testing/src/main/java/org/oppia/android/testing/logging:event_log_subject",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:robolectric_android-all",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,310 @@
package org.oppia.android.testing.logging

import org.junit.Assert.assertThrows
import org.junit.Test
import org.junit.runner.RunWith
import org.junit.runners.JUnit4
import org.oppia.android.app.model.AppLanguageSelection
import org.oppia.android.app.model.AudioTranslationLanguageSelection
import org.oppia.android.app.model.EventLog
import org.oppia.android.app.model.EventLog.ExplorationContext
import org.oppia.android.app.model.EventLog.TopicContext
import org.oppia.android.app.model.OppiaLanguage
import org.oppia.android.app.model.ProfileId
import org.oppia.android.app.model.WrittenTranslationLanguageSelection

/** Tests for [EventLogSubject]. */
@RunWith(JUnit4::class)
class EventLogSubjectTest {
@Test
fun testEventLogSubject_matchesCorrectTimeStamp() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()

EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(123456789)
}

@Test
fun testEventLogSubject_failsOnUnmatchingTimestamp() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()

assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
}

@Test
fun testEventLogSubject_matchesPriorityEssential() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.ESSENTIAL)
.build()

EventLogSubject.assertThat(eventLog)
.isEssentialPriority()
}

@Test
fun testEventLogSubject_matchEssentialPriorityWithDifferentPriority_fails() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.OPTIONAL)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.isEssentialPriority()
}
}

@Test
fun testEventLogSubject_matchesPriorityOptional() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.OPTIONAL)
.build()

EventLogSubject.assertThat(eventLog)
.isOptionalPriority()
}

@Test
fun testEventLogSubject_failsOnUnmatchingOptionalPriority() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.ESSENTIAL)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.isOptionalPriority()
}
}

@Test
fun testEventLogSubject_eventWithNoProfileId_returnsNoProfileId() {
val eventLog = EventLog.newBuilder()
.build()

EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
}

@Test
fun testEventLogSubject_eventWithProfileId_failsNoProfileExpected() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
val eventLog = EventLog.newBuilder()
.setProfileId(profileId)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
}
}

@Test
fun testEventLogSubject_matchesProfileIdPresent() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
val eventLog = EventLog.newBuilder()
.setProfileId(profileId)
.build()

EventLogSubject.assertThat(eventLog)
.hasProfileIdThat()
.isEqualTo(profileId)
}

@Test
fun testEventLogSubject_failsOnDifferentProfileId() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
val eventLog = EventLog.newBuilder()
.setProfileId(profileId)
.build()
val differentProfileId = ProfileId.newBuilder()
.setInternalId(2)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasProfileIdThat()
.isEqualTo(differentProfileId)
}
}

@Test
fun testEventLogSubject_matchesAppLanguageSelection() {
val appLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setAppLanguageSelection(appLanguageSelection)
.build()

EventLogSubject.assertThat(eventLog)
.hasAppLanguageSelectionThat()
.isEqualTo(appLanguageSelection)
}

@Test
fun testEventLogSubject_failsOnDifferentAppLanguageSelectionPresent() {
val appLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setAppLanguageSelection(appLanguageSelection)
.build()
val differentAppLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasAppLanguageSelectionThat()
.isEqualTo(differentAppLanguageSelection)
}
}

@Test
fun testEventLogSubject_matchesWrittenTranslationLanguageSelection() {
val writtenTranslationLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setWrittenTranslationLanguageSelection(writtenTranslationLanguageSelection)
.build()

EventLogSubject.assertThat(eventLog)
.hasWrittenTranslationLanguageSelectionThat()
.isEqualTo(writtenTranslationLanguageSelection)
}

@Test
fun testEventLogSubject_failsOnDifferentWrittenTranslationLanguageSelection() {
val writtenLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setWrittenTranslationLanguageSelection(writtenLanguageSelection)
.build()
val differentLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasWrittenTranslationLanguageSelectionThat()
.isEqualTo(differentLanguageSelection)
}
}

@Test
fun testEventLogSubject_matchesAudioTranslationLanguageSelection() {
val audioTranslationLanguageSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setAudioTranslationLanguageSelection(audioTranslationLanguageSelection)
.build()

EventLogSubject.assertThat(eventLog)
.hasAudioTranslationLanguageSelectionThat()
.isEqualTo(audioTranslationLanguageSelection)
}

@Test
fun testEventLogSubject_failsOnDifferentAudioTranslationLanguageSelection() {
val audioTranslationLanguageSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setAudioTranslationLanguageSelection(audioTranslationLanguageSelection)
.build()
val differentSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasAudioTranslationLanguageSelectionThat()
.isEqualTo(differentSelection)
}
}

@Test
fun testEventLogSubject_hasOpenExplorationActivityContext() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
.setOpenExplorationActivity(ExplorationContext.newBuilder())
)
.build()

EventLogSubject.assertThat(eventLog)
.hasOpenExplorationActivityContext()
}

@Test
fun testEventLogSubject_missingExplorationActivityContext_fails() {
val eventLog = EventLog.newBuilder()
.build()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasOpenExplorationActivityContext()
}
}

@Test
fun testEventLogSubject_hasOpenInfoTabContext() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
.setOpenInfoTab(TopicContext.newBuilder())
)
.build()

EventLogSubject.assertThat(eventLog)
.hasOpenInfoTabContext()
}

@Test
fun testEventLogSubject_hasOpenLessonsTabContext() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
.setOpenLessonsTab(TopicContext.newBuilder())
)
.build()

EventLogSubject.assertThat(eventLog)
.hasOpenLessonsTabContext()
}

@Test
fun testEventLogSubject_hasOpenPracticeTabContextPresent() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
.setOpenPracticeTab(TopicContext.newBuilder())
)
.build()

EventLogSubject.assertThat(eventLog)
.hasOpenPracticeTabContext()
}

@Test
fun testEventLogSubject_hasOpenRevisionTabContext() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
.setOpenRevisionTab(TopicContext.newBuilder())
)
.build()

EventLogSubject.assertThat(eventLog)
.hasOpenRevisionTabContext()
}
}
Loading