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 23 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
Commits
Show all changes
23 commits
Select commit Hold shift + click to select a range
7fe3d03
Added some tests for EventLogSubject
Jan 29, 2025
8797c9b
Removed Todo
Jan 29, 2025
937f504
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Jan 29, 2025
024447c
reformatting
Jan 29, 2025
a09a802
Merge remote-tracking branch 'origin/eventlog-subject-Test' into even…
Jan 29, 2025
37bb7a3
removed buildifier
Jan 29, 2025
b975475
Resolved comments
Jan 30, 2025
50668e3
renamed functions
Jan 31, 2025
892908f
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 10, 2025
0ec3f35
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 13, 2025
fadd691
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 13, 2025
2d30acb
added more tests
Feb 13, 2025
459c1ed
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 14, 2025
201c0d2
added more tests
Feb 14, 2025
fe0a94a
added more tests
Feb 15, 2025
3c4cc36
Added all tests
Feb 15, 2025
5e772b1
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 17, 2025
a236ea0
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 17, 2025
5765c55
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 18, 2025
dd896bf
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 19, 2025
d20cfb9
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 20, 2025
a79c114
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 20, 2025
60bfb7a
Merge branch 'develop' into eventlog-subject-Test
theayushyadav11 Feb 21, 2025
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
Original file line number Diff line number Diff line change
Expand Up @@ -78,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 @@ -65,13 +65,9 @@ oppia_android_test(
test_class = "org.oppia.android.testing.logging.EventLogSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//:dagger",
"//testing",
"//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
@@ -1,5 +1,6 @@
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
Expand All @@ -12,10 +13,11 @@ 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 testHasTimeStamp_withTimeStamp_matchesTimeStamp() {
fun testEventLogSubject_matchesCorrectTimeStamp() {
val eventLog = EventLog.newBuilder()
.setTimestamp(123456789)
.build()
Expand All @@ -25,19 +27,21 @@ class EventLogSubjectTest {
.isEqualTo(123456789)
}

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

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

@Test
fun testIsEssentialPriority_withEssentialPriority_matchesEssentialPriority() {
fun testEventLogSubject_matchesPriorityEssential() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.ESSENTIAL)
.build()
Expand All @@ -46,18 +50,19 @@ class EventLogSubjectTest {
.isEssentialPriority()
}

@Test(expected = AssertionError::class)
fun testIsEssentialPriority_withDifferentPriority_fails() {
@Test
fun testEventLogSubject_matchEssentialPriorityWithDifferentPriority_fails() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.OPTIONAL)
.build()

EventLogSubject.assertThat(eventLog)
.isEssentialPriority()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.isEssentialPriority()
}
}

@Test
fun testIsOptionalPriority_withOptionalPriority_matchesOptionalPriority() {
fun testEventLogSubject_matchesPriorityOptional() {
val eventLog = EventLog.newBuilder()
.setPriority(EventLog.Priority.OPTIONAL)
.build()
Expand All @@ -66,40 +71,42 @@ class EventLogSubjectTest {
.isOptionalPriority()
}

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

EventLogSubject.assertThat(eventLog)
.isOptionalPriority()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.isOptionalPriority()
}
}

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

EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
}

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

EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasNoProfileId()
}
}

@Test
fun testHasProfileId_withProfileId_matchesProfileId() {
fun testEventLogSubject_matchesProfileIdPresent() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
Expand All @@ -112,8 +119,8 @@ class EventLogSubjectTest {
.isEqualTo(profileId)
}

@Test(expected = AssertionError::class)
fun testHasProfileId_withDifferentProfileId_fails() {
@Test
fun testEventLogSubject_failsOnDifferentProfileId() {
val profileId = ProfileId.newBuilder()
.setInternalId(1)
.build()
Expand All @@ -123,14 +130,15 @@ class EventLogSubjectTest {
val differentProfileId = ProfileId.newBuilder()
.setInternalId(2)
.build()

EventLogSubject.assertThat(eventLog)
.hasProfileIdThat()
.isEqualTo(differentProfileId)
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasProfileIdThat()
.isEqualTo(differentProfileId)
}
}

@Test
fun testHasAppLanguageSelectionThat_withAppLanguageSelection_matchesAppLanguageSelection() {
fun testEventLogSubject_hasSameAppLanguageSelection() {
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 testEventLogSubject_hasSameAppLanguageSelection() {
fun testEventLogSubject_matchesAppLanguageSelection() {

val appLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
Expand All @@ -143,8 +151,8 @@ class EventLogSubjectTest {
.isEqualTo(appLanguageSelection)
}

@Test(expected = AssertionError::class)
fun testHasAppLanguageSelectionThat_withDifferentAppLanguageSelection_fails() {
@Test
fun testEventLogSubject_failsOnDifferentAppLanguageSelectionPresent() {
val appLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
Expand All @@ -154,14 +162,15 @@ class EventLogSubjectTest {
val differentAppLanguageSelection = AppLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()

EventLogSubject.assertThat(eventLog)
.hasAppLanguageSelectionThat()
.isEqualTo(differentAppLanguageSelection)
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasAppLanguageSelectionThat()
.isEqualTo(differentAppLanguageSelection)
}
}

@Test
fun testHasWrittenTranslationLanguageSelectionThat_matchcesWrittenTranslationLanguageSelection() {
fun testEventLogSubject_matchesWrittenTranslationLanguageSelection() {
val writtenTranslationLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
Expand All @@ -174,8 +183,8 @@ class EventLogSubjectTest {
.isEqualTo(writtenTranslationLanguageSelection)
}

@Test(expected = AssertionError::class)
fun testHasWrittenTranslationLanguageSelectionThat_withDifferentLanguageSelection_fails() {
@Test
fun testEventLogSubject_failsOnDifferentWrittenTranslationLanguageSelection() {
val writtenLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
Expand All @@ -185,14 +194,15 @@ class EventLogSubjectTest {
val differentLanguageSelection = WrittenTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()

EventLogSubject.assertThat(eventLog)
.hasWrittenTranslationLanguageSelectionThat()
.isEqualTo(differentLanguageSelection)
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasWrittenTranslationLanguageSelectionThat()
.isEqualTo(differentLanguageSelection)
}
}

@Test
fun testHasAudioTranslationLanguageSelectionThat_withMatchingSelection_passes() {
fun testEventLogSubject_matchesAudioTranslationLanguageSelection() {
val audioTranslationLanguageSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
Expand All @@ -205,8 +215,8 @@ class EventLogSubjectTest {
.isEqualTo(audioTranslationLanguageSelection)
}

@Test(expected = AssertionError::class)
fun testHasAudioTranslationLanguageSelectionThat_withDifferentSelection_fails() {
@Test
fun testEventLogSubject_failsOnDifferentAudioTranslationLanguageSelection() {
val audioTranslationLanguageSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ENGLISH)
.build()
Expand All @@ -216,14 +226,15 @@ class EventLogSubjectTest {
val differentSelection = AudioTranslationLanguageSelection.newBuilder()
.setSelectedLanguage(OppiaLanguage.ARABIC)
.build()

EventLogSubject.assertThat(eventLog)
.hasAudioTranslationLanguageSelectionThat()
.isEqualTo(differentSelection)
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasAudioTranslationLanguageSelectionThat()
.isEqualTo(differentSelection)
}
}

@Test
fun testHasOpenExplorationActivityContext_withMatchingContext_passes() {
fun testEventLogSubject_hasOpenExplorationActivityContextPresent() {
Copy link
Collaborator

Choose a reason for hiding this comment

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

For this and below, remove redundant verb.

Suggested change
fun testEventLogSubject_hasOpenExplorationActivityContextPresent() {
fun testEventLogSubject_hasOpenExplorationActivityContext() {

val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
Expand All @@ -235,17 +246,18 @@ class EventLogSubjectTest {
.hasOpenExplorationActivityContext()
}

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

Choose a reason for hiding this comment

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

For this and below, rename:

Suggested change
fun testEventLogSubject_openExplorationActivityContextAbsent_fails() {
fun testEventLogSubject_missingExplorationActivityContext_fails() {

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

EventLogSubject.assertThat(eventLog)
.hasOpenExplorationActivityContext()
assertThrows(AssertionError::class.java) {
EventLogSubject.assertThat(eventLog)
.hasOpenExplorationActivityContext()
}
}

@Test
fun testHasOpenInfoTabContext_withMatchingContext_passes() {
fun testEventLogSubject_hasOpenInfoTabContextPresent() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
Expand All @@ -258,7 +270,7 @@ class EventLogSubjectTest {
}

@Test
fun testHasOpenLessonsTabContext_withMatchingContext_passes() {
fun testEventLogSubject_hasOpenLessonsTabContextPresent() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
Expand All @@ -271,7 +283,7 @@ class EventLogSubjectTest {
}

@Test
fun testHasOpenPracticeTabContext_withMatchingContext_passes() {
fun testEventLogSubject_hasOpenPracticeTabContextPresent() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
Expand All @@ -284,7 +296,7 @@ class EventLogSubjectTest {
}

@Test
fun testHasOpenRevisionTabContext_withMatchingContext_passes() {
fun testEventLogSubject_hasOpenRevisionTabContextPresent() {
val eventLog = EventLog.newBuilder()
.setContext(
EventLog.Context.newBuilder()
Expand Down
Loading