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
Changes from 3 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 @@ -5,9 +5,12 @@ 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)
Copy link
Collaborator

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?

Suggested change
@RunWith(AndroidJUnit4::class)
@RunWith(JUnit4::class)

@Config(manifest = Config.NONE)
class AsyncResultSubjectTest {
private val pendingResult: AsyncResult<String> = AsyncResult.Pending()
private val successResult: AsyncResult<String> = AsyncResult.Success("Some string")
Expand Down Expand Up @@ -82,10 +85,49 @@ class AsyncResultSubjectTest {
}

@Test
fun testAsyncResultSubject_twoSuccessResults_checkNewerOrSameAge() {
val successResult1: AsyncResult<String> = AsyncResult.Success("First")
val successResult2: AsyncResult<String> = AsyncResult.Success("Second")
AsyncResultSubject.assertThat(successResult1).isNewerOrSameAgeAs(successResult2)
fun testAsyncResultSubject_newerResult_checkIsNewerOrSameAge() {
val olderResult: AsyncResult<String> = AsyncResult.Success("Older")
Thread.sleep(50)
Copy link
Collaborator

Choose a reason for hiding this comment

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

This is not a typical Oppia pattern, please use testCoroutineDispatchers.advanceTimeBy(TimeUnit.SECONDS.toMillis(50)) instead.

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
Expand Down Expand Up @@ -164,14 +206,6 @@ class AsyncResultSubjectTest {
.isFalse()
}

@Test
fun testAsyncResultSubject_isComparableSuccessThat_checkIntValue() {
val intResult: AsyncResult<Int> = AsyncResult.Success(100)
AsyncResultSubject.assertThat(intResult)
.isComparableSuccessThat<Int>()
.isEqualTo(100)
}

@Test
fun testAsyncResultSubject_successResult_checkStringSuccessValue() {
AsyncResultSubject.assertThat(successResult)
Expand Down
Loading