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 dependency leaking #3623

Merged
merged 4 commits into from
Nov 19, 2024
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
Original file line number Diff line number Diff line change
Expand Up @@ -114,14 +114,9 @@ constructor(
open val fhirPathDataExtractor: FhirPathDataExtractor,
open val parser: IParser,
@ApplicationContext open val context: Context,
open val contentCache: ContentCache,
) {

@Inject lateinit var contentCache: ContentCache

init {
DaggerDefaultRepositoryComponent.create().inject(this)
}

suspend inline fun <reified T : Resource> loadResource(resourceId: String): T? =
fhirEngine.loadResource(resourceId)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.configuration.profile.ProfileConfiguration
import org.smartregister.fhircore.engine.configuration.register.RegisterConfiguration
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
Expand All @@ -52,6 +53,7 @@ constructor(
override val fhirPathDataExtractor: FhirPathDataExtractor,
override val parser: IParser,
@ApplicationContext override val context: Context,
override val contentCache: ContentCache,
) :
Repository,
DefaultRepository(
Expand All @@ -64,6 +66,7 @@ constructor(
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = context,
contentCache = contentCache,
) {

override suspend fun loadRegisterData(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -123,6 +123,8 @@ class DefaultRepositoryTest : RobolectricTest() {

@Inject lateinit var parser: IParser

@Inject lateinit var contentCache: ContentCache

@BindValue
val configService: ConfigService =
spyk(AppConfigService(ApplicationProvider.getApplicationContext()))
Expand All @@ -149,6 +151,7 @@ class DefaultRepositoryTest : RobolectricTest() {
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = context,
contentCache = contentCache,
)
}

Expand Down Expand Up @@ -562,6 +565,7 @@ class DefaultRepositoryTest : RobolectricTest() {
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = context,
contentCache = contentCache,
),
)
coEvery { fhirEngine.search<RelatedPerson>(any()) } returns
Expand Down Expand Up @@ -640,6 +644,7 @@ class DefaultRepositoryTest : RobolectricTest() {
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = context,
contentCache = contentCache,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import org.smartregister.fhircore.engine.configuration.ConfigType
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.profile.ProfileConfiguration
import org.smartregister.fhircore.engine.configuration.register.RegisterConfiguration
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.datastore.syncLocationIdsProtoStore
import org.smartregister.fhircore.engine.domain.model.ActionParameter
import org.smartregister.fhircore.engine.domain.model.ActionParameterType
Expand Down Expand Up @@ -104,6 +105,9 @@ class RegisterRepositoryTest : RobolectricTest() {
@Inject lateinit var fhirEngine: FhirEngine

@Inject lateinit var parser: IParser

@Inject lateinit var contentCache: ContentCache

private val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
private val patient = Faker.buildPatient(PATIENT_ID)
private lateinit var registerRepository: RegisterRepository
Expand All @@ -123,6 +127,7 @@ class RegisterRepositoryTest : RobolectricTest() {
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = ApplicationProvider.getApplicationContext(),
contentCache = contentCache,
),
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -108,6 +108,7 @@ import org.smartregister.fhircore.engine.configuration.QuestionnaireConfig
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.configuration.event.EventTriggerCondition
import org.smartregister.fhircore.engine.configuration.event.EventWorkflow
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.domain.model.ResourceConfig
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
Expand Down Expand Up @@ -159,6 +160,8 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {

@Inject lateinit var configurationRegistry: ConfigurationRegistry

@Inject lateinit var contentCache: ContentCache

private val context: Context = ApplicationProvider.getApplicationContext()
private val knowledgeManager = KnowledgeManager.create(context)
private val fhirContext: FhirContext = FhirContext.forCached(FhirVersionEnum.R4)
Expand Down Expand Up @@ -192,6 +195,7 @@ class FhirCarePlanGeneratorTest : RobolectricTest() {
fhirPathDataExtractor = fhirPathDataExtractor,
parser = iParser,
context = context,
contentCache = contentCache,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -56,6 +56,7 @@ import org.junit.Rule
import org.junit.Test
import org.smartregister.fhircore.engine.app.fakes.Faker
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.robolectric.RobolectricTest
import org.smartregister.fhircore.engine.rule.CoroutineTestRule
Expand All @@ -78,6 +79,9 @@ class FhirResourceExpireWorkerTest : RobolectricTest() {
@Inject lateinit var dispatcherProvider: DispatcherProvider

@Inject lateinit var parser: IParser

@Inject lateinit var contentCache: ContentCache

private val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
private lateinit var defaultRepository: DefaultRepository

Expand Down Expand Up @@ -120,6 +124,7 @@ class FhirResourceExpireWorkerTest : RobolectricTest() {
fhirPathDataExtractor = mockk(),
parser = parser,
context = ApplicationProvider.getApplicationContext(),
contentCache = contentCache,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,7 @@ import org.junit.runner.RunWith
import org.robolectric.Robolectric
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.smartregister.fhircore.engine.util.test.HiltActivityForTest
import org.smartregister.fhircore.geowidget.shadows.ShadowConnectivityReceiver
import org.smartregister.fhircore.geowidget.shadows.ShadowKujakuMapView
import org.smartregister.fhircore.geowidget.shadows.ShadowMapbox
Expand All @@ -58,7 +59,7 @@ class GeoWidgetFragmentTest {
fun setup() {
hiltRule.inject()

Robolectric.buildActivity(GeoWidgetTestActivity::class.java).create().resume().get()
Robolectric.buildActivity(HiltActivityForTest::class.java).create().resume().get()

geowidgetFragment = GeoWidgetFragment()

Expand Down

This file was deleted.

Original file line number Diff line number Diff line change
Expand Up @@ -18,31 +18,23 @@ package org.smartregister.fhircore.geowidget.screens

import android.os.Build
import androidx.arch.core.executor.testing.InstantTaskExecutorRule
import androidx.test.core.app.ApplicationProvider
import ca.uhn.fhir.parser.IParser
import com.google.android.fhir.FhirEngine
import dagger.hilt.android.testing.HiltAndroidRule
import dagger.hilt.android.testing.HiltAndroidTest
import dagger.hilt.android.testing.HiltTestApplication
import io.mockk.coEvery
import io.mockk.mockk
import io.mockk.spyk
import java.util.UUID
import javax.inject.Inject
import org.junit.Assert
import org.junit.Before
import org.junit.Rule
import org.junit.Test
import org.junit.runner.RunWith
import org.mockito.Mock
import org.mockito.MockitoAnnotations
import org.robolectric.RobolectricTestRunner
import org.robolectric.annotation.Config
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.rulesengine.ConfigRulesExecutor
import org.smartregister.fhircore.engine.util.DispatcherProvider
import org.smartregister.fhircore.engine.util.SharedPreferencesHelper
import org.smartregister.fhircore.engine.util.fhirpath.FhirPathDataExtractor
import org.smartregister.fhircore.geowidget.model.GeoJsonFeature
Expand All @@ -65,52 +57,23 @@ class GeoWidgetViewModelTest {
@Inject lateinit var parser: IParser

private lateinit var configurationRegistry: ConfigurationRegistry

private lateinit var sharedPreferencesHelper: SharedPreferencesHelper

private lateinit var geoWidgetViewModel: GeoWidgetViewModel

private lateinit var defaultRepository: DefaultRepository

private val fhirEngine = mockk<FhirEngine>()

private val configRulesExecutor: ConfigRulesExecutor = mockk()

private lateinit var viewModel: GeoWidgetViewModel

@Mock private lateinit var dispatcherProvider: DispatcherProvider

@Before
fun setUp() {
MockitoAnnotations.initMocks(this)
viewModel = GeoWidgetViewModel()
geoWidgetViewModel = GeoWidgetViewModel()
hiltRule.inject()
sharedPreferencesHelper = mockk()
configurationRegistry = mockk()
defaultRepository =
spyk(
DefaultRepository(
fhirEngine = fhirEngine,
dispatcherProvider = dispatcherProvider,
sharedPreferencesHelper = sharedPreferencesHelper,
configurationRegistry = configurationRegistry,
configService = configService,
configRulesExecutor = configRulesExecutor,
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = ApplicationProvider.getApplicationContext(),
),
)
geoWidgetViewModel = spyk(GeoWidgetViewModel())

coEvery { defaultRepository.create(any()) } returns emptyList()
}

fun testMappingServicePointKeysToTypes() {
val expectedMap = mutableMapOf<String, ServicePointType>()
ServicePointType.entries.forEach { expectedMap[it.name.lowercase()] = it }

val result = viewModel.getServicePointKeyToType()
val result = geoWidgetViewModel.getServicePointKeyToType()

Assert.assertEquals(expectedMap.size, result.size)
expectedMap.forEach { (key, expectedValue) ->
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -24,7 +24,6 @@
import com.google.android.fhir.search.search
import com.google.android.fhir.workflow.FhirOperator
import dagger.hilt.android.qualifiers.ApplicationContext
import java.util.NoSuchElementException
import javax.inject.Inject
import kotlinx.coroutines.withContext
import org.hl7.fhir.exceptions.FHIRException
Expand All @@ -35,6 +34,7 @@
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.app.ConfigService
import org.smartregister.fhircore.engine.configuration.report.measure.ReportConfiguration
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.rulesengine.ConfigRulesExecutor
import org.smartregister.fhircore.engine.util.DispatcherProvider
Expand All @@ -58,6 +58,7 @@
override val parser: IParser,
@ApplicationContext override val context: Context,
override val dispatcherProvider: DispatcherProvider,
override val contentCache: ContentCache,

Check warning on line 61 in android/quest/src/main/java/org/smartregister/fhircore/quest/data/report/measure/MeasureReportRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/data/report/measure/MeasureReportRepository.kt#L61

Added line #L61 was not covered by tests
) :
DefaultRepository(
fhirEngine = fhirEngine,
Expand All @@ -69,6 +70,7 @@
parser = parser,
context = context,
dispatcherProvider = dispatcherProvider,
contentCache = contentCache,

Check warning on line 73 in android/quest/src/main/java/org/smartregister/fhircore/quest/data/report/measure/MeasureReportRepository.kt

View check run for this annotation

Codecov / codecov/patch

android/quest/src/main/java/org/smartregister/fhircore/quest/data/report/measure/MeasureReportRepository.kt#L73

Added line #L73 was not covered by tests
) {

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,7 @@ import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.register.RegisterConfiguration
import org.smartregister.fhircore.engine.configuration.report.measure.MeasureReportConfiguration
import org.smartregister.fhircore.engine.configuration.report.measure.ReportConfiguration
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.data.local.register.RegisterRepository
import org.smartregister.fhircore.engine.domain.model.FhirResourceConfig
Expand All @@ -66,6 +67,10 @@ class MeasureReportPagingSourceTest : RobolectricTest() {

@Inject lateinit var locationService: LocationService

@Inject lateinit var contentCache: ContentCache

@Inject lateinit var fhirContext: FhirContext

private val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
private val fhirEngine: FhirEngine = mockk()
private val registerId = "register id"
Expand All @@ -74,8 +79,6 @@ class MeasureReportPagingSourceTest : RobolectricTest() {
private lateinit var measureReportConfiguration: MeasureReportConfiguration
private lateinit var measureReportPagingSource: MeasureReportPagingSource
private lateinit var registerRepository: RegisterRepository

@Inject lateinit var fhirContext: FhirContext
private lateinit var defaultRepository: DefaultRepository

@Before
Expand Down Expand Up @@ -115,6 +118,7 @@ class MeasureReportPagingSourceTest : RobolectricTest() {
fhirPathDataExtractor = fhirPathDataExtractor,
parser = parser,
context = ApplicationProvider.getApplicationContext(),
contentCache = contentCache,
),
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ import org.junit.Test
import org.smartregister.fhircore.engine.configuration.ConfigurationRegistry
import org.smartregister.fhircore.engine.configuration.report.measure.MeasureReportConfiguration
import org.smartregister.fhircore.engine.configuration.report.measure.ReportConfiguration
import org.smartregister.fhircore.engine.data.local.ContentCache
import org.smartregister.fhircore.engine.data.local.DefaultRepository
import org.smartregister.fhircore.engine.data.local.register.RegisterRepository
import org.smartregister.fhircore.engine.rulesengine.ResourceDataRulesExecutor
Expand Down Expand Up @@ -73,6 +74,10 @@ class MeasureReportRepositoryTest : RobolectricTest() {

@Inject lateinit var locationService: LocationService

@Inject lateinit var fhirContext: FhirContext

@Inject lateinit var contentCache: ContentCache

private val configurationRegistry: ConfigurationRegistry = Faker.buildTestConfigurationRegistry()
private val fhirEngine: FhirEngine = mockk()
private lateinit var measureReportConfiguration: MeasureReportConfiguration
Expand All @@ -82,8 +87,6 @@ class MeasureReportRepositoryTest : RobolectricTest() {
private lateinit var resourceDataRulesExecutor: ResourceDataRulesExecutor
private lateinit var registerRepository: RegisterRepository
private val parser = FhirContext.forR4Cached().newJsonParser()

@Inject lateinit var fhirContext: FhirContext
private lateinit var defaultRepository: DefaultRepository

@Before
Expand Down Expand Up @@ -121,6 +124,7 @@ class MeasureReportRepositoryTest : RobolectricTest() {
fhirPathDataExtractor = mockk(),
parser = parser,
context = ApplicationProvider.getApplicationContext(),
contentCache = contentCache,
),
)

Expand All @@ -137,6 +141,7 @@ class MeasureReportRepositoryTest : RobolectricTest() {
parser = parser,
context = ApplicationProvider.getApplicationContext(),
dispatcherProvider = dispatcherProvider,
contentCache = contentCache,
)
}

Expand Down
Loading
Loading