-
Notifications
You must be signed in to change notification settings - Fork 541
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
base: develop
Are you sure you want to change the base?
Changes from 8 commits
c009a17
9dfebea
8b98691
000ca24
6ab4e6d
ae62e88
bad8e9a
d297385
aa623bc
200f7e0
36195e7
e387066
a4ae9d8
c1f1521
10223c5
0edd250
66784ad
c167c20
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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) | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I tried switching to JUnit4 as suggested, but I encountered an error: There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. That sounds good, thanks! There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. As per yesterday’s discussion, Ben mentioned that we don’t generally use the Robolectric runner, so one way to fix this error while using the JUnit runner is to inject FakeOppiaClock in this class, and then add an @before method to initialize the FakeOppiaClock object to uptimemillis or fake time mode as needed for these tests |
||||||||||||||||||||||||||||||||||||
class AsyncResultSubjectTest { | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
@Test | ||||||||||||||||||||||||||||||||||||
fun testAsyncResultPending_isPending() { | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||||||||||||||||||||||||||||||||||||
val pendingResult: AsyncResult<String> = AsyncResult.Pending() | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
AsyncResultSubject.assertThat(pendingResult).isPending() | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
@Test | ||||||||||||||||||||||||||||||||||||
fun testAsyncResultPending_isNotSuccess() { | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. You are also missing a corresponding "isNotFailure()" test. |
||||||||||||||||||||||||||||||||||||
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") | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
} | ||||||||||||||||||||||||||||||||||||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Suggestion to reduce ambiguity.
Suggested change
|
||||||||||||||||||||||||||||||||||||
|
||||||||||||||||||||||||||||||||||||
@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 |
---|---|---|
|
@@ -33,3 +33,21 @@ oppia_android_test( | |
"//utility/src/main/java/org/oppia/android/util/networking:debug_module", | ||
], | ||
) | ||
|
||
# Adding test for AsyncResultSubject | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This comment is not required. There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Done. |
||
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", | ||
], | ||
) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
remove this file from
test_file_exemptions
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Done .