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 22 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 6 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
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 @@ -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 Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,3 +57,21 @@ 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 = [
"//:dagger",
"//testing",
Copy link
Collaborator

Choose a reason for hiding this comment

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

Are these two deps really required here?

"//testing/src/main/java/org/oppia/android/testing/logging:event_log_subject",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:org_robolectric_robolectric",
"//third_party:robolectric_android-all",
],
)
Original file line number Diff line number Diff line change
@@ -0,0 +1,298 @@
package org.oppia.android.testing.logging

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

@RunWith(JUnit4::class)
class EventLogSubjectTest {
@Test
fun testHasTimeStamp_withTimeStamp_matchesTimeStamp() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

All the tests in this class needs to be renamed to follow our preferred format: https://github.com/oppia/oppia-android/wiki/Oppia-Android-Testing#guidelines-for-testing, e.g. testEventLogSubject_matchesCorrectTimestamp
testEventLogSubject_failsOnUnmatchingTimestamp

val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()

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

@Test(expected = AssertionError::class)
fun testHasTimeStamp_withDifferentTimeStamp_fails() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()

EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
Copy link
Collaborator

Choose a reason for hiding this comment

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

We don't use this pattern when testing. Prefer something likee:

Suggested change
@Test(expected = AssertionError::class)
fun testHasTimeStamp_withDifferentTimeStamp_fails() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()
EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
@Test
fun testEventLogSubject_failsOnUnmatchingTimestamp() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()
assertThrows<AssertionError>() {
EventLogSubject.assertThat(eventLog)
.hasTimestampThat()
.isEqualTo(987654321)
}
}


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

EventLogSubject.assertThat(eventLog)
.isEssentialPriority()
}

@Test(expected = AssertionError::class)
fun testIsEssentialPriority_withDifferentPriority_fails() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fun testIsEssentialPriority_withDifferentPriority_fails() {
fun testEventLogSubject_matchEssentialPriorityWithDifferentPriority_fails() {

val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.OPTIONAL)
.build()

EventLogSubject.assertThat(eventLog)
.isEssentialPriority()
}

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

EventLogSubject.assertThat(eventLog)
.isOptionalPriority()
}

@Test(expected = AssertionError::class)
fun testIsOptionalPriority_withDifferentPriority_fails() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.ESSENTIAL)
.build()

EventLogSubject.assertThat(eventLog)
.isOptionalPriority()
}

@Test
fun testHasNoProfileId_withNoProfileId() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

Suggested change
fun testHasNoProfileId_withNoProfileId() {
fun testEventLogSubject_eventWithNoProfileId_returnsNoProfileId() {

Ditto test below

val eventLog = EventLog.newBuilder()
.build()

EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
}

@Test(expected = AssertionError::class)
fun testHasNoProfileId_withProfileId_fails() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
val eventLog = EventLog.newBuilder()
.setProfileId(profileId)
.build()

EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
}

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

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

@Test(expected = AssertionError::class)
fun testHasProfileId_withDifferentProfileId_fails() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
val eventLog = EventLog.newBuilder()
.setProfileId(profileId)
.build()
val differentProfileId = ProfileId.newBuilder()
.setInternalId(2)
.build()

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

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

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

@Test(expected = AssertionError::class)
fun testHasAppLanguageSelectionThat_withDifferentAppLanguageSelection_fails() {
val appLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setAppLanguageSelection(appLanguageSelection)
.build()
val differentAppLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()

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

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

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

@Test(expected = AssertionError::class)
fun testHasWrittenTranslationLanguageSelectionThat_withDifferentLanguageSelection_fails() {
val writtenLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setWrittenTranslationLanguageSelection(writtenLanguageSelection)
.build()
val differentLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()

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

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

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

@Test(expected = AssertionError::class)
fun testHasAudioTranslationLanguageSelectionThat_withDifferentSelection_fails() {
val audioTranslationLanguageSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
val eventLog = EventLog.newBuilder()
.setAudioTranslationLanguageSelection(audioTranslationLanguageSelection)
.build()
val differentSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()

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

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

EventLogSubject.assertThat(eventLog)
.hasOpenExplorationActivityContext()
}

@Test(expected = AssertionError::class)
fun testHasOpenExplorationActivityContext_withDifferentContext_fails() {
val eventLog = EventLog.newBuilder()
.build()

EventLogSubject.assertThat(eventLog)
.hasOpenExplorationActivityContext()
}

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

EventLogSubject.assertThat(eventLog)
.hasOpenInfoTabContext()
}

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

EventLogSubject.assertThat(eventLog)
.hasOpenLessonsTabContext()
}

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

EventLogSubject.assertThat(eventLog)
.hasOpenPracticeTabContext()
}

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

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