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

Fix Part of #4236 : Add tests for AsyncResultSubject #5670

Open
wants to merge 26 commits into
base: develop
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 8 commits
Commits
Show all changes
26 commits
Select commit Hold shift + click to select a range
c009a17
Added Test For AsyncResultSubject
TanishMoral11 Jan 26, 2025
9dfebea
Reformatting
TanishMoral11 Jan 26, 2025
8b98691
Update
TanishMoral11 Jan 26, 2025
000ca24
Added New Tests
TanishMoral11 Jan 27, 2025
6ab4e6d
Reformatting
TanishMoral11 Jan 27, 2025
ae62e88
Resolved Klint Issue
TanishMoral11 Jan 27, 2025
bad8e9a
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Jan 27, 2025
d297385
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Jan 28, 2025
aa623bc
Added More Tests
TanishMoral11 Jan 30, 2025
200f7e0
Format
TanishMoral11 Jan 30, 2025
36195e7
All Test
TanishMoral11 Jan 30, 2025
e387066
Rerun CI Checks
TanishMoral11 Jan 30, 2025
a4ae9d8
Klint
TanishMoral11 Jan 30, 2025
c1f1521
All Tests
TanishMoral11 Jan 30, 2025
10223c5
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Jan 31, 2025
0edd250
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Feb 7, 2025
66784ad
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Feb 10, 2025
c167c20
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Feb 11, 2025
86f3ae2
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Feb 13, 2025
a2e50a8
RoboElectric to AndroidJUnit4
TanishMoral11 Feb 13, 2025
bda5446
Rm Unused Variables
TanishMoral11 Feb 13, 2025
64f4174
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Feb 14, 2025
680d45e
Added More Test
TanishMoral11 Feb 14, 2025
57c4664
Fix Klint
TanishMoral11 Feb 14, 2025
30e2c42
rm Test
TanishMoral11 Feb 14, 2025
e3297e9
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 Feb 19, 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
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,6 @@ import com.google.common.truth.extensions.proto.LiteProtoTruth.assertThat
import com.google.protobuf.MessageLite
import org.oppia.android.util.data.AsyncResult

// TODO(#4236): Add tests for this class.

/**
* Truth subject for verifying properties of [AsyncResult]s.
*
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,79 @@
package org.oppia.android.testing.data

import com.google.common.truth.Truth.assertThat
import org.junit.Test
import org.junit.runner.RunWith
import org.oppia.android.util.data.AsyncResult
import org.robolectric.RobolectricTestRunner

@RunWith(RobolectricTestRunner::class)
class AsyncResultSubjectTest {

@Test
fun testAsyncResultPending_isPending() {
val pendingResult: AsyncResult<String> = AsyncResult.Pending()

AsyncResultSubject.assertThat(pendingResult).isPending()
}

@Test
fun testAsyncResultPending_isNotSuccess() {
val pendingResult: AsyncResult<String> = AsyncResult.Pending()

AsyncResultSubject.assertThat(pendingResult).isNotSuccess()
}

@Test
fun testAsyncResultSuccess_isSuccess() {
val successResult: AsyncResult<String> = AsyncResult.Success("Success value")

AsyncResultSubject.assertThat(successResult).isSuccess()
}

@Test
fun testAsyncResultSuccess_hasSuccessValueWhere_matchesExpected() {
val successResult: AsyncResult<String> = AsyncResult.Success("Success value")

AsyncResultSubject.assertThat(successResult).hasSuccessValueWhere {
// Here we are verifying that the value is "Success value"
assertThat(this).isEqualTo("Success value")
}
}

@Test
fun testAsyncResultSuccess_isStringSuccessThat() {
val successResult: AsyncResult<String> = AsyncResult.Success("Success value")

AsyncResultSubject.assertThat(successResult).isStringSuccessThat().isEqualTo("Success value")
}

@Test
fun testAsyncResultFailure_isFailure() {
val failureResult: AsyncResult<String> = AsyncResult.Failure(Throwable("Error"))

AsyncResultSubject.assertThat(failureResult).isFailure()
}

@Test
fun testAsyncResultFailure_isFailureThat_matchesExpectedError() {
val failureResult: AsyncResult<String> = AsyncResult.Failure(Throwable("Error"))

AsyncResultSubject.assertThat(failureResult).isFailureThat().hasMessageThat().contains("Error")
}

@Test
fun testAsyncResultSuccess_isNewerOrSameAgeAs() {
val successResult1: AsyncResult<String> = AsyncResult.Success("First")
val successResult2: AsyncResult<String> = AsyncResult.Success("Second")

AsyncResultSubject.assertThat(successResult1).isNewerOrSameAgeAs(successResult2)
}

@Test
fun testAsyncResultFailure_hasSameEffectiveValueAs_differentError() {
val failureResult1: AsyncResult<String> = AsyncResult.Failure(Throwable("Error"))
val failureResult2: AsyncResult<String> = AsyncResult.Failure(Throwable("Different Error"))

AsyncResultSubject.assertThat(failureResult1).hasSameEffectiveValueAs(failureResult2).isFalse()
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -33,3 +33,21 @@ oppia_android_test(
"//utility/src/main/java/org/oppia/android/util/networking:debug_module",
],
)

# Adding test for AsyncResultSubject
oppia_android_test(
name = "AsyncResultSubjectTest",
srcs = ["AsyncResultSubjectTest.kt"],
custom_package = "org.oppia.android.testing.data",
test_class = "org.oppia.android.testing.data.AsyncResultSubjectTest",
test_manifest = "//testing:test_manifest",
deps = [
"//testing/src/main/java/org/oppia/android/testing/data:async_result_subject",
"//testing/src/main/java/org/oppia/android/testing/robolectric:test_module",
"//third_party:androidx_test_ext_junit",
"//third_party:com_google_truth_truth",
"//third_party:junit_junit",
"//third_party:org_robolectric_robolectric",
"//third_party:robolectric_android-all",
],
)
Loading