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

Catch uncaught RxJava errors in unit tests #438

Merged
merged 3 commits into from
Jan 8, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
2 changes: 1 addition & 1 deletion app/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ android {
dependencies {
implementation project(path: ':router')

testImplementation "junit:junit:$versions.junit"
implementation "junit:junit:$versions.junit"
saket marked this conversation as resolved.
Show resolved Hide resolved
testImplementation "org.mockito:mockito-core:$versions.mockito"
testImplementation "com.nhaarman:mockito-kotlin:$versions.mockitoKotlin"
testImplementation "pl.pragmatists:JUnitParams:$versions.junitParams"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -39,12 +39,10 @@ import java.util.UUID
@RunWith(AndroidJUnit4::class)
class MigrationAndroidTest {

@Rule
@JvmField
@get:Rule
val helper = MigrationTestHelperWithForeignConstraints()

@Rule
@JvmField
@get:Rule
val expectedException = ExpectedException.none()

@Test
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,13 @@ import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.util.RxErrorsRule
import org.simple.clinic.util.TestClock
import org.threeten.bp.Clock
import org.threeten.bp.Duration
Expand All @@ -34,8 +36,14 @@ class BloodPressureRepositoryAndroidTest {
@Inject
lateinit var testData: TestData

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

val testClock: TestClock
get() = clock as TestClock
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import android.support.test.runner.AndroidJUnit4
import com.f2prateek.rx.preferences2.Preference
import org.junit.Before
import org.junit.Rule
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.TestClinicApp
Expand All @@ -13,6 +14,7 @@ import org.simple.clinic.bp.BloodPressureRepository
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.sync.BaseSyncCoordinatorAndroidTest
import org.simple.clinic.util.Optional
import org.simple.clinic.util.RxErrorsRule
import javax.inject.Inject
import javax.inject.Named

Expand All @@ -35,8 +37,14 @@ class BloodPressureSyncAndroidTest : BaseSyncCoordinatorAndroidTest<BloodPressur
@Inject
lateinit var testData: TestData

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,20 +6,15 @@ import io.bloco.faker.Faker
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AppDatabase
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.patient.Gender
import org.simple.clinic.patient.Patient
import org.simple.clinic.patient.PatientAddress
import org.simple.clinic.patient.PatientStatus
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.protocol.ProtocolDrug
import org.simple.clinic.user.UserSession
import org.threeten.bp.Instant
import org.threeten.bp.LocalDate
import org.simple.clinic.util.RxErrorsRule
import java.util.UUID
import javax.inject.Inject

Expand All @@ -41,8 +36,14 @@ class PrescriptionRepositoryAndroidTest {
@Inject
lateinit var testData: TestData

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,17 +7,18 @@ import org.junit.Rule
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.sync.RegisterPatientRule
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.drugs.PrescribedDrug
import org.simple.clinic.drugs.PrescriptionRepository
import org.simple.clinic.facility.FacilityRepository
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.sync.BaseSyncCoordinatorAndroidTest
import org.simple.clinic.sync.RegisterPatientRule
import org.simple.clinic.user.User
import org.simple.clinic.user.UserSession
import org.simple.clinic.util.Optional
import org.simple.clinic.util.RxErrorsRule
import java.util.UUID
import javax.inject.Inject
import javax.inject.Named
Expand Down Expand Up @@ -47,20 +48,23 @@ class PrescriptionSyncAndroidTest : BaseSyncCoordinatorAndroidTest<PrescribedDru
@Inject
lateinit var facilityRepository: FacilityRepository

val user: User
private val user: User
get() = userSession.loggedInUserImmediate()!!

val currentFacilityUuid: UUID
private val currentFacilityUuid: UUID
get() = facilityRepository.currentFacilityUuid(user)!!

val authenticationRule = AuthenticationRule()
private val authenticationRule = AuthenticationRule()

private val registerPatientRule = RegisterPatientRule(UUID.randomUUID())

val registerPatientRule = RegisterPatientRule(UUID.randomUUID())
private val rxErrorsRule = RxErrorsRule()

@get:Rule
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(registerPatientRule)!!
.around(registerPatientRule)
.around(rxErrorsRule)!!

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package org.simple.clinic.facility
import android.support.test.runner.AndroidJUnit4
import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.simple.clinic.AppDatabase
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.user.LoggedInUserFacilityMapping
import org.simple.clinic.user.User
import org.simple.clinic.util.RxErrorsRule
import java.util.UUID
import javax.inject.Inject

Expand All @@ -31,6 +33,9 @@ class FacilityRepositoryAndroidTest {
@Inject
lateinit var mappingDao: LoggedInUserFacilityMapping.RoomDao

@get:Rule
val rxErrorsRule = RxErrorsRule()

private lateinit var user: User

@Before
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AppDatabase
import org.simple.clinic.AuthenticationRule
Expand All @@ -15,6 +16,7 @@ import org.simple.clinic.sync.BaseSyncCoordinatorAndroidTest
import org.simple.clinic.user.UserSession
import org.simple.clinic.util.None
import org.simple.clinic.util.Optional
import org.simple.clinic.util.RxErrorsRule
import javax.inject.Inject
import javax.inject.Named

Expand Down Expand Up @@ -49,8 +51,14 @@ class FacilitySyncAndroidTest {
@Inject
lateinit var testData: TestData

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,13 +3,15 @@ package org.simple.clinic.medicalhistory
import com.google.common.truth.Truth.assertThat
import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.medicalhistory.MedicalHistory.Answer.NO
import org.simple.clinic.medicalhistory.MedicalHistory.Answer.UNKNOWN
import org.simple.clinic.medicalhistory.MedicalHistory.Answer.YES
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.util.RxErrorsRule
import org.threeten.bp.Clock
import org.threeten.bp.Instant
import org.threeten.bp.temporal.ChronoUnit.DAYS
Expand All @@ -30,6 +32,9 @@ class MedicalHistoryRepositoryAndroidTest {
@Inject
lateinit var clock: Clock

@get:Rule
val rxErrorsRule = RxErrorsRule()

@Before
fun setup() {
TestClinicApp.appComponent().inject(this)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@ import org.junit.Rule
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.sync.RegisterPatientRule
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.medicalhistory.sync.MedicalHistoryPayload
Expand All @@ -18,7 +17,9 @@ import org.simple.clinic.medicalhistory.sync.MedicalHistorySyncApiV2
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.sync.BaseSyncCoordinatorAndroidTest
import org.simple.clinic.sync.DataPushResponse
import org.simple.clinic.sync.RegisterPatientRule
import org.simple.clinic.util.Optional
import org.simple.clinic.util.RxErrorsRule
import java.util.UUID
import javax.inject.Inject
import javax.inject.Named
Expand All @@ -42,14 +43,17 @@ class MedicalHistorySyncAndroidTest : BaseSyncCoordinatorAndroidTest<MedicalHist
@Inject
lateinit var testData: TestData

val authenticationRule = AuthenticationRule()
private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

val registerPatientRule = RegisterPatientRule(patientUuid = UUID.randomUUID())
private val registerPatientRule = RegisterPatientRule(patientUuid = UUID.randomUUID())

@get:Rule
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(registerPatientRule)
.around(rxErrorsRule)!!

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import org.junit.After
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AppDatabase
import org.simple.clinic.AuthenticationRule
Expand Down Expand Up @@ -37,6 +38,7 @@ import org.simple.clinic.patient.PatientRepository
import org.simple.clinic.patient.PatientStatus
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.user.UserSession
import org.simple.clinic.util.RxErrorsRule
import org.simple.clinic.util.TestClock
import org.threeten.bp.Clock
import org.threeten.bp.Duration
Expand Down Expand Up @@ -79,8 +81,14 @@ class AppointmentRepositoryAndroidTest {
private val testClock: TestClock
get() = clock as TestClock

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

@Before
fun setup() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@ import com.f2prateek.rx.preferences2.Preference
import io.reactivex.Single
import org.junit.Before
import org.junit.Rule
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.TestClinicApp
Expand All @@ -13,6 +14,7 @@ import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.sync.BaseSyncCoordinatorAndroidTest
import org.simple.clinic.sync.DataPushResponse
import org.simple.clinic.util.Optional
import org.simple.clinic.util.RxErrorsRule
import javax.inject.Inject
import javax.inject.Named

Expand Down Expand Up @@ -44,8 +46,14 @@ class AppointmentSyncAndroidTest : BaseSyncCoordinatorAndroidTest<Appointment, A
val config: AppointmentConfig
get() = appointmentConfigProvider.blockingGet()

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

@Before
fun setUp() {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,12 +5,14 @@ import com.google.common.truth.Truth.assertThat
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.rules.RuleChain
import org.junit.runner.RunWith
import org.simple.clinic.AuthenticationRule
import org.simple.clinic.TestClinicApp
import org.simple.clinic.TestData
import org.simple.clinic.patient.SyncStatus
import org.simple.clinic.user.UserSession
import org.simple.clinic.util.RxErrorsRule
import java.util.UUID
import javax.inject.Inject

Expand All @@ -26,8 +28,14 @@ class CommunicationRepositoryAndroidTest {
@Inject
lateinit var testData: TestData

private val authenticationRule = AuthenticationRule()

private val rxErrorsRule = RxErrorsRule()

@get:Rule
val authenticationRule = AuthenticationRule()
val ruleChain = RuleChain
.outerRule(authenticationRule)
.around(rxErrorsRule)!!

@Before
fun setup() {
Expand Down
Loading