From 1cba0fd80363b6b2fc5a3a2cb3332486f0a458c4 Mon Sep 17 00:00:00 2001 From: Pablo Date: Thu, 8 Feb 2024 09:22:31 +0100 Subject: [PATCH] fix unit tests Signed-off-by: Pablo --- .../eventDetails/EventInitialTest.kt | 2 +- .../org/dhis2/data/filter/FilterRepositoryTest.kt | 4 ++-- .../eventDetails/EventDetailsIntegrationTest.kt | 2 +- .../ui/mapper/TEICardMapperTest.kt | 6 ++++-- .../teiDashboard/ui/mapper/InfoBarMapperTest.kt | 15 +++++++++++++-- .../dhis2/commons/resources/ResourceManager.kt | 2 +- 6 files changed, 22 insertions(+), 9 deletions(-) diff --git a/app/src/androidTest/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventInitialTest.kt b/app/src/androidTest/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventInitialTest.kt index de6ebdd6855..daa58140d4f 100644 --- a/app/src/androidTest/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventInitialTest.kt +++ b/app/src/androidTest/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventInitialTest.kt @@ -154,7 +154,7 @@ class EventInitialTest { enrollmentStatus = enrollmentStatus, ) - private fun provideEventResourcesProvider() = EventDetailResourcesProvider(resourceManager) + private fun provideEventResourcesProvider() = EventDetailResourcesProvider(PROGRAM_UID, resourceManager) private fun createOrUpdateEventDetails() = CreateOrUpdateEventDetails( repository = eventDetailsRepository, diff --git a/app/src/test/java/org/dhis2/data/filter/FilterRepositoryTest.kt b/app/src/test/java/org/dhis2/data/filter/FilterRepositoryTest.kt index 40a8021db2e..ca9cdbb8744 100644 --- a/app/src/test/java/org/dhis2/data/filter/FilterRepositoryTest.kt +++ b/app/src/test/java/org/dhis2/data/filter/FilterRepositoryTest.kt @@ -74,11 +74,11 @@ class FilterRepositoryTest { private fun mockFilterLabels() { whenever(filterResources.filterOrgUnitLabel()) doReturn ORG_UNIT whenever(filterResources.filterSyncLabel()) doReturn SYNC_STATUS - whenever(filterResources.filterEnrollmentStatusLabel()) doReturn + whenever(filterResources.filterEnrollmentStatusLabel(any())) doReturn ENROLLMENT_STATUS whenever(filterResources.filterDateLabel()) doReturn EVENT_DATE whenever(filterResources.filterEventStatusLabel()) doReturn EVENT_STATUS - whenever(filterResources.filterEnrollmentDateLabel()) doReturn + whenever(filterResources.filterEnrollmentDateLabel(any())) doReturn ENROLLMENT_DATE whenever(filterResources.filterAssignedToMeLabel()) doReturn ASSIGN_TO_ME whenever(filterResources.filterEventDateLabel()) doReturn EVENT_DATE diff --git a/app/src/test/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventDetailsIntegrationTest.kt b/app/src/test/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventDetailsIntegrationTest.kt index 4456be2091e..0f88359cccd 100644 --- a/app/src/test/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventDetailsIntegrationTest.kt +++ b/app/src/test/java/org/dhis2/usescases/eventsWithoutRegistration/eventDetails/EventDetailsIntegrationTest.kt @@ -179,7 +179,7 @@ class EventDetailsIntegrationTest { enrollmentStatus = enrollmentStatus, ) - private fun provideEventResourcesProvider() = EventDetailResourcesProvider(resourceManager) + private fun provideEventResourcesProvider() = EventDetailResourcesProvider(PROGRAM_UID, resourceManager) private fun createOrUpdateEventDetails() = CreateOrUpdateEventDetails( repository = eventDetailsRepository, diff --git a/app/src/test/java/org/dhis2/usescases/searchTrackEntity/ui/mapper/TEICardMapperTest.kt b/app/src/test/java/org/dhis2/usescases/searchTrackEntity/ui/mapper/TEICardMapperTest.kt index 2e4dcb6df90..c4b913728e4 100644 --- a/app/src/test/java/org/dhis2/usescases/searchTrackEntity/ui/mapper/TEICardMapperTest.kt +++ b/app/src/test/java/org/dhis2/usescases/searchTrackEntity/ui/mapper/TEICardMapperTest.kt @@ -15,6 +15,7 @@ import org.hisp.dhis.android.core.trackedentity.TrackedEntityInstance import org.junit.Assert.assertEquals import org.junit.Before import org.junit.Test +import org.mockito.kotlin.any import org.mockito.kotlin.doReturn import org.mockito.kotlin.mock import org.mockito.kotlin.whenever @@ -36,7 +37,7 @@ class TEICardMapperTest { whenever(resourceManager.getString(R.string.show_less)) doReturn "Show less" whenever(resourceManager.getString(R.string.completed)) doReturn "Completed" whenever( - resourceManager.getString(R.string.enrollment_completed), + resourceManager.formatWithEnrollmentLabel(any(), any(), any(), any()), ) doReturn "Enrollment Completed" whenever( resourceManager.getString(R.string.overdue_today), @@ -67,7 +68,7 @@ class TEICardMapperTest { ) assertEquals( result.additionalInfo[3].value, - resourceManager.getString(R.string.enrollment_completed), + "Enrollment Completed", ) assertEquals( @@ -99,6 +100,7 @@ class TEICardMapperTest { setCurrentEnrollment( Enrollment.builder() .uid("EnrollmentUid") + .program("programUid") .status(EnrollmentStatus.COMPLETED) .build(), ) diff --git a/app/src/test/java/org/dhis2/usescases/teiDashboard/ui/mapper/InfoBarMapperTest.kt b/app/src/test/java/org/dhis2/usescases/teiDashboard/ui/mapper/InfoBarMapperTest.kt index bb036738277..8d782544aee 100644 --- a/app/src/test/java/org/dhis2/usescases/teiDashboard/ui/mapper/InfoBarMapperTest.kt +++ b/app/src/test/java/org/dhis2/usescases/teiDashboard/ui/mapper/InfoBarMapperTest.kt @@ -33,8 +33,19 @@ class InfoBarMapperTest { whenever(resourceManager.getString(R.string.sync_warning)) doReturn "Sync warning" whenever(resourceManager.getString(R.string.sync_error)) doReturn "Sync Error" whenever(resourceManager.getString(R.string.marked_follow_up)) doReturn "Marked for follow up" - whenever(resourceManager.getString(R.string.enrollment_completed)) doReturn "Enrollment completed" - whenever(resourceManager.getString(R.string.enrollment_cancelled)) doReturn "Enrollment cancelled" + setPrograms().forEach { + whenever( + resourceManager.formatWithEnrollmentLabel( + it.uid(), R.string.enrollment_completed_V2, 1, + ), + ) doReturn "Enrollment completed" + whenever( + resourceManager.formatWithEnrollmentLabel( + it.uid(), R.string.enrollment_cancelled_V2, 1, + ), + ) doReturn "Enrollment cancelled" + } + whenever(resourceManager.getString(R.string.sync)) doReturn "Sync" whenever(resourceManager.getString(R.string.sync_retry)) doReturn "Retry sync" whenever(resourceManager.getString(R.string.remove)) doReturn "remove" diff --git a/commons/src/main/java/org/dhis2/commons/resources/ResourceManager.kt b/commons/src/main/java/org/dhis2/commons/resources/ResourceManager.kt index 4635aa513e2..4b9bba7bcd4 100644 --- a/commons/src/main/java/org/dhis2/commons/resources/ResourceManager.kt +++ b/commons/src/main/java/org/dhis2/commons/resources/ResourceManager.kt @@ -29,7 +29,7 @@ class ResourceManager( programUid: String, @StringRes stringResource: Int, quantity: Int, - formatWithQuantity: Boolean = false + formatWithQuantity: Boolean = false, ): String { val enrollmentLabel = try { D2Manager.getD2().programModule().programs().uid(programUid).blockingGet()