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

Improve test coverage #86

Merged
merged 22 commits into from
Sep 23, 2024
Merged
Show file tree
Hide file tree
Changes from 21 commits
Commits
Show all changes
22 commits
Select commit Hold shift + click to select a range
3942c8e
Add tests for BundleResources
lincmba Aug 28, 2024
2f62589
Test getSupervisorPractitionerDetailsByKeycloakId
lincmba Sep 18, 2024
844af23
Create Test Helper Methods
lincmba Sep 18, 2024
e49a46e
Test PractitionerDetailsEndpointHelper.getAttributedPractitionerDetai…
lincmba Sep 18, 2024
b2cfcd1
Test PractitionerDetailsEndpointHelper.getOrganizationIdsByLocationIds
lincmba Sep 19, 2024
74874ae
Test PractitionerDetailsEndpointHelper.getCareTeamsByOrganizationIds
lincmba Sep 19, 2024
1dca67a
Test PractitionerDetailsEndpointHelper.getOrganizationsById
lincmba Sep 19, 2024
e3a4bb6
Test PractitionerDetailsEndpointHelper.getLocationsById
lincmba Sep 19, 2024
9176bd6
Test PractitionerDetailsEndpointHelper.getOrganizationAffiliationsByO…
lincmba Sep 19, 2024
39dd7fe
Test PractitionerDetailsEndpointHelper.getOrganizationAffiliationsByO…
lincmba Sep 19, 2024
6bc1871
Test PractitionerDetailsEndpointHelper.getLocationIdsByOrganizationAf…
lincmba Sep 19, 2024
a63493c
Cleanup
lincmba Sep 19, 2024
9ed3c94
Fix failing tests
lincmba Sep 19, 2024
4676e52
Close static mocks to avoid interfering with other test functions
lincmba Sep 20, 2024
2a2e563
Add tests for RestUtils
lincmba Sep 20, 2024
fbf9db5
Add tests for Utils.findSyncStrategy
lincmba Sep 20, 2024
79c840f
Add tests for Utils.createEmptyBundle
lincmba Sep 20, 2024
74b4c87
Add tests for ResourceFinderImp.findResourcesInBundle
lincmba Sep 20, 2024
2549b57
Add tests for ResourceFinderImp.createResourceFromRequest
lincmba Sep 20, 2024
58151ca
Add tests for RestUtil
lincmba Sep 20, 2024
e04fcff
Remove README.md from files to be tested
lincmba Sep 20, 2024
138a2d4
Reduce visibility of some methods
lincmba Sep 20, 2024
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 .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ jobs:
java-version: 11

- name: Run Unit tests and generate report
run: mvn -B clean test jacoco:report --file pom.xml
run: mvn -B clean test jacoco:report --file pom.xml --file README.md --file LICENSE

- name: Upload coverage reports to Codecov
uses: codecov/[email protected]
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -88,7 +88,7 @@ public Bundle getSupervisorPractitionerDetailsByKeycloakId(String keycloakUuid)
return bundle;
}

private Bundle getAttributedPractitionerDetailsByPractitioner(Practitioner practitioner) {
lincmba marked this conversation as resolved.
Show resolved Hide resolved
public Bundle getAttributedPractitionerDetailsByPractitioner(Practitioner practitioner) {
Bundle responseBundle = new Bundle();
List<Practitioner> attributedPractitioners = new ArrayList<>();
PractitionerDetails practitionerDetails =
Expand Down Expand Up @@ -189,7 +189,7 @@ public static Set<String> getAttributedLocations(List<LocationHierarchy> locatio
.collect(Collectors.toSet());
}

private List<String> getOrganizationIdsByLocationIds(Set<String> attributedLocationsList) {
lincmba marked this conversation as resolved.
Show resolved Hide resolved
public List<String> getOrganizationIdsByLocationIds(Set<String> attributedLocationsList) {
if (attributedLocationsList == null || attributedLocationsList.isEmpty()) {
return new ArrayList<>();
}
Expand Down Expand Up @@ -376,7 +376,7 @@ private Set<String> getOrganizationIdsByPractitionerRoles(
.collect(Collectors.toSet());
}

private Practitioner getPractitionerByIdentifier(String identifier) {
lincmba marked this conversation as resolved.
Show resolved Hide resolved
public Practitioner getPractitionerByIdentifier(String identifier) {
Bundle resultBundle =
getFhirClientForR4()
.search()
Expand All @@ -391,7 +391,7 @@ private Practitioner getPractitionerByIdentifier(String identifier) {
: null;
}

private List<CareTeam> getCareTeamsByOrganizationIds(List<String> organizationIds) {
lincmba marked this conversation as resolved.
Show resolved Hide resolved
public List<CareTeam> getCareTeamsByOrganizationIds(List<String> organizationIds) {
if (organizationIds.isEmpty()) return new ArrayList<>();

Bundle bundle =
Expand Down Expand Up @@ -450,7 +450,7 @@ private static String getReferenceIDPart(String reference) {
reference.lastIndexOf(org.smartregister.utils.Constants.FORWARD_SLASH) + 1);
}

private Bundle getOrganizationsById(Set<String> organizationIds) {
public Bundle getOrganizationsById(Set<String> organizationIds) {
return organizationIds.isEmpty()
? EMPTY_BUNDLE
: getFhirClientForR4()
Expand All @@ -464,7 +464,7 @@ private Bundle getOrganizationsById(Set<String> organizationIds) {
.execute();
}

private @Nullable List<Location> getLocationsByIds(List<String> locationIds) {
public @Nullable List<Location> getLocationsByIds(List<String> locationIds) {
if (locationIds == null || locationIds.isEmpty()) {
return new ArrayList<>();
}
Expand All @@ -485,7 +485,7 @@ private Bundle getOrganizationsById(Set<String> organizationIds) {
.collect(Collectors.toList());
}

private List<OrganizationAffiliation> getOrganizationAffiliationsByOrganizationIds(
public List<OrganizationAffiliation> getOrganizationAffiliationsByOrganizationIds(
Set<String> organizationIds) {
if (organizationIds == null || organizationIds.isEmpty()) {
return new ArrayList<>();
Expand All @@ -495,7 +495,7 @@ private List<OrganizationAffiliation> getOrganizationAffiliationsByOrganizationI
return mapBundleToOrganizationAffiliation(organizationAffiliationsBundle);
}

private Bundle getOrganizationAffiliationsByOrganizationIdsBundle(Set<String> organizationIds) {
public Bundle getOrganizationAffiliationsByOrganizationIdsBundle(Set<String> organizationIds) {
return organizationIds.isEmpty()
? EMPTY_BUNDLE
: getFhirClientForR4()
Expand All @@ -509,7 +509,7 @@ private Bundle getOrganizationAffiliationsByOrganizationIdsBundle(Set<String> or
.execute();
}

private List<String> getLocationIdsByOrganizationAffiliations(
public List<String> getLocationIdsByOrganizationAffiliations(
List<OrganizationAffiliation> organizationAffiliations) {

return organizationAffiliations.stream()
Expand All @@ -523,7 +523,7 @@ private List<String> getLocationIdsByOrganizationAffiliations(
.collect(Collectors.toList());
}

private Set<String> getManagingOrganizationsOfCareTeamIds(List<CareTeam> careTeamsList) {
public Set<String> getManagingOrganizationsOfCareTeamIds(List<CareTeam> careTeamsList) {
return careTeamsList.stream()
.filter(CareTeam::hasManagingOrganization)
.flatMap(it -> it.getManagingOrganization().stream())
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ private ResourceFinderImp(FhirContext fhirContext) {
this.fhirContext = fhirContext;
}

private IBaseResource createResourceFromRequest(RequestDetailsReader request) {
public IBaseResource createResourceFromRequest(RequestDetailsReader request) {
byte[] requestContentBytes = request.loadRequestContents();
Charset charset = request.getCharset();
if (charset == null) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -95,7 +95,7 @@ public void testGetPaginatedLocationsPaginatesLocations() {

LocationHierarchyEndpointHelper mockLocationHierarchyEndpointHelper =
mock(LocationHierarchyEndpointHelper.class);
List<Location> locations = createLocationList(5, false);
List<Location> locations = createTestLocationList(5, false);
List<String> adminLevels = new ArrayList<>();

List<String> locationIds = Collections.singletonList("12345");
Expand Down Expand Up @@ -162,7 +162,7 @@ public void testHandleNonIdentifierRequestListModePaginatesLocations() {
MockedStatic<JwtUtils> mockJwtUtils = Mockito.mockStatic(JwtUtils.class);
List<String> adminLevels = new ArrayList<>();

List<Location> locations = createLocationList(4, false);
List<Location> locations = createTestLocationList(4, false);
List<String> locationIds = List.of("1", "2", "3", "4");
List<String> userRoles = Collections.singletonList(Constants.ROLE_ALL_LOCATIONS);

Expand Down Expand Up @@ -204,6 +204,7 @@ public void testHandleNonIdentifierRequestListModePaginatesLocations() {
Assert.assertTrue(resultBundle.hasLink());
Assert.assertTrue(resultBundle.hasTotal());
Assert.assertEquals(16, resultBundle.getEntry().size());
mockJwtUtils.close();
}

@Test
Expand Down Expand Up @@ -295,7 +296,7 @@ public void testGetDescendantsWithAdminLevelFiltersReturnsLocationsWithinAdminLe

@Test
public void testFilterLocationsByAdminLevelsBasic() {
List<Location> locations = createLocationList(5, true);
List<Location> locations = createTestLocationList(5, true);
List<String> adminLevels = List.of("1", "3");

List<Location> filteredLocations =
Expand All @@ -309,7 +310,7 @@ public void testFilterLocationsByAdminLevelsBasic() {

@Test
public void testFilterLocationsByAdminLevelsWithNullAdminLevelsDoesNotFilter() {
List<Location> locations = createLocationList(5, true);
List<Location> locations = createTestLocationList(5, true);

List<Location> filteredLocations =
locationHierarchyEndpointHelper.filterLocationsByAdminLevels(locations, null);
Expand Down Expand Up @@ -342,7 +343,7 @@ public void testFilterLocationsByInventoryWithInventory() {
Mockito.doReturn(queryMock).when(queryMock).returnBundle(Bundle.class);
Mockito.doReturn(bundleWithInventory).when(queryMock).execute();

List<Location> locations = createLocationList(5, true);
List<Location> locations = createTestLocationList(5, true);
List<Location> filteredLocations =
locationHierarchyEndpointHelper.filterLocationsByInventory(locations);

Expand All @@ -364,7 +365,7 @@ public void testFilterLocationsByInventoryNoInventory() {
Mockito.doReturn(queryMock).when(queryMock).returnBundle(Bundle.class);
Mockito.doReturn(bundleWithInventory).when(queryMock).execute();

List<Location> locations = createLocationList(5, true);
List<Location> locations = createTestLocationList(5, true);
List<Location> filteredLocations =
locationHierarchyEndpointHelper.filterLocationsByInventory(locations);

Expand All @@ -388,7 +389,7 @@ private Bundle getLocationBundle() {
return bundleLocation;
}

private List<Location> createLocationList(int numLocations, boolean setAdminLevel) {
public static List<Location> createTestLocationList(int numLocations, boolean setAdminLevel) {
List<Location> locations = new ArrayList<>();
for (int i = 0; i < numLocations; i++) {
Location location = new Location();
Expand Down
Loading
Loading