-
Notifications
You must be signed in to change notification settings - Fork 544
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
TanishMoral11
wants to merge
26
commits into
oppia:develop
Choose a base branch
from
TanishMoral11:add-tests-for-asyncresultsubject
base: develop
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
26 commits
Select commit
Hold shift + click to select a range
c009a17
Added Test For AsyncResultSubject
TanishMoral11 9dfebea
Reformatting
TanishMoral11 8b98691
Update
TanishMoral11 000ca24
Added New Tests
TanishMoral11 6ab4e6d
Reformatting
TanishMoral11 ae62e88
Resolved Klint Issue
TanishMoral11 bad8e9a
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 d297385
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 aa623bc
Added More Tests
TanishMoral11 200f7e0
Format
TanishMoral11 36195e7
All Test
TanishMoral11 e387066
Rerun CI Checks
TanishMoral11 a4ae9d8
Klint
TanishMoral11 c1f1521
All Tests
TanishMoral11 10223c5
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 0edd250
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 66784ad
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 c167c20
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 86f3ae2
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 a2e50a8
RoboElectric to AndroidJUnit4
TanishMoral11 bda5446
Rm Unused Variables
TanishMoral11 64f4174
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 680d45e
Added More Test
TanishMoral11 57c4664
Fix Klint
TanishMoral11 30e2c42
rm Test
TanishMoral11 e3297e9
Merge branch 'develop' into add-tests-for-asyncresultsubject
TanishMoral11 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
240 changes: 240 additions & 0 deletions
240
testing/src/test/java/org/oppia/android/testing/data/AsyncResultSubjectTest.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,240 @@ | ||
package org.oppia.android.testing.data | ||
|
||
import androidx.test.ext.junit.runners.AndroidJUnit4 | ||
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.annotation.Config | ||
import java.io.FileNotFoundException | ||
|
||
/** Tests for [AsyncResultSubject]. */ | ||
@RunWith(AndroidJUnit4::class) | ||
@Config(manifest = Config.NONE) | ||
class AsyncResultSubjectTest { | ||
private val pendingResult: AsyncResult<String> = AsyncResult.Pending() | ||
private val successResult: AsyncResult<String> = AsyncResult.Success("Some string") | ||
private val failureResult: AsyncResult<String> = | ||
AsyncResult.Failure(RuntimeException("Error message")) | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkIsPending() { | ||
AsyncResultSubject.assertThat(pendingResult).isPending() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkIsNotSuccess() { | ||
AsyncResultSubject.assertThat(pendingResult).isNotSuccess() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkIsNotFailure() { | ||
AsyncResultSubject.assertThat(pendingResult).isNotFailure() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkIsNotPending() { | ||
AsyncResultSubject.assertThat(successResult).isNotPending() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkIsSuccess() { | ||
AsyncResultSubject.assertThat(successResult).isSuccess() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkIsNotFailure() { | ||
AsyncResultSubject.assertThat(successResult).isNotFailure() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkSuccessValueMatches() { | ||
AsyncResultSubject.assertThat(successResult).hasSuccessValueWhere { | ||
assertThat(this).isEqualTo("Some string") | ||
} | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkIsStringSuccessThat() { | ||
AsyncResultSubject.assertThat(successResult) | ||
.isStringSuccessThat() | ||
.isEqualTo("Some string") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkIsFailure() { | ||
AsyncResultSubject.assertThat(failureResult).isFailure() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkIsNotSuccess() { | ||
AsyncResultSubject.assertThat(failureResult).isNotSuccess() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkIsNotPending() { | ||
AsyncResultSubject.assertThat(failureResult).isNotPending() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkErrorMessageMatches() { | ||
AsyncResultSubject.assertThat(failureResult) | ||
.isFailureThat() | ||
.hasMessageThat() | ||
.contains("Error message") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_newerResult_checkIsNewerOrSameAge() { | ||
val olderResult: AsyncResult<String> = AsyncResult.Success("Older") | ||
Thread.sleep(50) | ||
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 is not a typical Oppia pattern, please use |
||
val newerResult: AsyncResult<String> = AsyncResult.Success("Newer") | ||
AsyncResultSubject.assertThat(newerResult).isNewerOrSameAgeAs(olderResult) | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_throwableSuccess_checkIsThrowableSuccessThat() { | ||
val throwableResult: AsyncResult<Throwable> = | ||
AsyncResult.Success(RuntimeException("Error")) | ||
AsyncResultSubject.assertThat(throwableResult) | ||
.asThrowableSuccessThat() | ||
.hasMessageThat() | ||
.contains("Error") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkCause() { | ||
val failureResult: AsyncResult<String> = | ||
AsyncResult.Failure(RuntimeException("Root error", FileNotFoundException("Cause"))) | ||
AsyncResultSubject.assertThat(failureResult) | ||
.isFailureThat() | ||
.hasCauseThat() | ||
.hasMessageThat() | ||
.contains("Cause") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_nullSuccessValue_checkIsNull() { | ||
val nullSuccessResult: AsyncResult<String?> = AsyncResult.Success(null) | ||
AsyncResultSubject.assertThat(nullSuccessResult) | ||
.isSuccessThat() | ||
.isNull() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingAndSuccess_checkHasDifferentEffectiveValue() { | ||
val pendingResult: AsyncResult<String> = AsyncResult.Pending() | ||
val successResult: AsyncResult<String> = AsyncResult.Success("Value") | ||
AsyncResultSubject.assertThat(pendingResult) | ||
.hasSameEffectiveValueAs(successResult) | ||
.isFalse() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_sameSuccessValue_checkHasSameEffectiveValue() { | ||
val successResult1: AsyncResult<String> = AsyncResult.Success("Same value") | ||
val successResult2: AsyncResult<String> = AsyncResult.Success("Same value") | ||
AsyncResultSubject.assertThat(successResult1) | ||
.hasSameEffectiveValueAs(successResult2) | ||
.isTrue() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_differentSuccessValues_checkHasDifferentEffectiveValue() { | ||
val successResult1: AsyncResult<String> = AsyncResult.Success("First value") | ||
val successResult2: AsyncResult<String> = AsyncResult.Success("Second value") | ||
AsyncResultSubject.assertThat(successResult1) | ||
.hasSameEffectiveValueAs(successResult2) | ||
.isFalse() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_intSuccess_checkIsIntSuccessThat() { | ||
val intResult: AsyncResult<Int> = AsyncResult.Success(42) | ||
AsyncResultSubject.assertThat(intResult) | ||
.isIntSuccessThat() | ||
.isEqualTo(42) | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_booleanSuccess_checkIsBooleanSuccessThat() { | ||
val boolResult: AsyncResult<Boolean> = AsyncResult.Success(true) | ||
AsyncResultSubject.assertThat(boolResult) | ||
.isBooleanSuccessThat() | ||
.isTrue() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_differentFailureMessages_checkHasDifferentEffectiveValue() { | ||
val failureResult1: AsyncResult<String> = AsyncResult.Failure(RuntimeException("Error 1")) | ||
val failureResult2: AsyncResult<String> = AsyncResult.Failure(RuntimeException("Error 2")) | ||
AsyncResultSubject.assertThat(failureResult1) | ||
.hasSameEffectiveValueAs(failureResult2) | ||
.isFalse() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkIsNotSuccessOrFailure() { | ||
AsyncResultSubject.assertThat(pendingResult).isNotSuccess() | ||
AsyncResultSubject.assertThat(pendingResult).isNotFailure() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkIsSuccessThat() { | ||
AsyncResultSubject.assertThat(successResult).isSuccessThat().isEqualTo("Some string") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkIsFailureThatError() { | ||
AsyncResultSubject.assertThat(failureResult) | ||
.isFailureThat() | ||
.hasMessageThat() | ||
.contains("Error message") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkHasSameEffectiveValueAs() { | ||
val anotherPending: AsyncResult<String> = AsyncResult.Pending() | ||
AsyncResultSubject.assertThat(pendingResult).hasSameEffectiveValueAs(anotherPending) | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkHasDifferentEffectiveValue() { | ||
val successResult: AsyncResult<String> = AsyncResult.Success("Some string") | ||
AsyncResultSubject.assertThat(pendingResult) | ||
.hasSameEffectiveValueAs(successResult) | ||
.isFalse() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_successResult_checkStringSuccessValue() { | ||
AsyncResultSubject.assertThat(successResult) | ||
.isSuccessThat() | ||
.isEqualTo("Some string") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_failureResult_checkErrorMessageMatchesExact() { | ||
AsyncResultSubject.assertThat(failureResult) | ||
.isFailureThat() | ||
.hasMessageThat() | ||
.isEqualTo("Error message") | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkHasNullEffectiveValue() { | ||
val nullPending: AsyncResult<String> = AsyncResult.Pending() | ||
AsyncResultSubject.assertThat(pendingResult) | ||
.hasSameEffectiveValueAs(nullPending) | ||
.isTrue() | ||
} | ||
|
||
@Test | ||
fun testAsyncResultSubject_pendingResult_checkIsNotSameEffectiveValue() { | ||
val pending1: AsyncResult<String> = AsyncResult.Pending() | ||
val pending2: AsyncResult<String> = AsyncResult.Pending() | ||
AsyncResultSubject.assertThat(pending1) | ||
.hasSameEffectiveValueAs(pending2) | ||
.isTrue() | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
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.
Is there an error running with JUnit4?