From 7ed6367d17499656a4e8eca76806373a36fe3ad1 Mon Sep 17 00:00:00 2001 From: tsznaj Date: Tue, 9 Jul 2024 12:58:03 +0200 Subject: [PATCH] OLMIS-7952: Added another test coverage. --- .../web/StockCardsController.java | 3 +- .../HomeFacilityPermissionServiceTest.java | 41 +++++++++++++++++++ 2 files changed, 43 insertions(+), 1 deletion(-) diff --git a/src/main/java/org/openlmis/stockmanagement/web/StockCardsController.java b/src/main/java/org/openlmis/stockmanagement/web/StockCardsController.java index 3fe32dbb..1530a0f7 100644 --- a/src/main/java/org/openlmis/stockmanagement/web/StockCardsController.java +++ b/src/main/java/org/openlmis/stockmanagement/web/StockCardsController.java @@ -107,7 +107,8 @@ public Page getStockCardSummaries( profiler.start("FIND_STOCK_CARDS"); try { return stockCardSummariesService - .findStockCards(program, facility, pageable, profiler.startNested("FIND_STOCK_CARDS")); + .findStockCards(program, facility, pageable, + profiler.startNested("FIND_STOCK_CARDS")); } finally { profiler.stop().log(); } diff --git a/src/test/java/org/openlmis/stockmanagement/service/HomeFacilityPermissionServiceTest.java b/src/test/java/org/openlmis/stockmanagement/service/HomeFacilityPermissionServiceTest.java index 656453db..05ca0612 100644 --- a/src/test/java/org/openlmis/stockmanagement/service/HomeFacilityPermissionServiceTest.java +++ b/src/test/java/org/openlmis/stockmanagement/service/HomeFacilityPermissionServiceTest.java @@ -16,9 +16,12 @@ package org.openlmis.stockmanagement.service; import static java.util.UUID.randomUUID; +import static org.junit.Assert.assertFalse; import static org.junit.Assert.assertTrue; import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.times; import static org.mockito.Mockito.verify; +import static org.mockito.Mockito.verifyNoInteractions; import static org.mockito.Mockito.when; import static org.openlmis.stockmanagement.service.HomeFacilityPermissionService.WS_TYPE_CODE; @@ -50,6 +53,8 @@ @PowerMockIgnore("javax.security.auth.*") public class HomeFacilityPermissionServiceTest { + private static final String OTHER_TYPE_CODE = "otherTypeCode"; + @InjectMocks private HomeFacilityPermissionService homeFacilityPermissionService; @@ -119,6 +124,42 @@ public void shouldPassCheckIfFacilityIsWithinTheSameGeographicZoneAsHomeFacility verify(facilityService).findOne(homeFacilityId); } + @Test + public void shouldFailCheckIfFacilityHasOtherTypeCodeThanWs() { + //given + FacilityDto facilityDto = mock(FacilityDto.class); + FacilityTypeDto facilityTypeDto = new FacilityTypeDto(); + facilityTypeDto.setCode(OTHER_TYPE_CODE); + when(facilityDto.getType()).thenReturn(facilityTypeDto); + UUID geographicZoneId = randomUUID(); + + mockGeographicZoneId(facilityDto, geographicZoneId); + mockGeographicZoneId(homeFacilityDto, geographicZoneId); + UUID facilityId = UUID.randomUUID(); + when(facilityService.findOne(facilityId)).thenReturn(facilityDto); + + //when + boolean result = homeFacilityPermissionService.checkFacilityAndHomeFacilityLinkage(facilityId); + + //then + assertFalse(result); + verify(facilityService).findOne(facilityId); + verify(facilityService, times(0)).findOne(homeFacilityId); + } + + @Test + public void shouldFailCheckIfFacilityIdIsEqualToHomeFacilityId() { + //given + + //when + boolean result = + homeFacilityPermissionService.checkFacilityAndHomeFacilityLinkage(homeFacilityId); + + //then + assertFalse(result); + verifyNoInteractions(facilityService); + } + private void mockGeographicZoneId(FacilityDto facilityDto, UUID geographicZoneId) { GeographicZoneDto geographicZoneDto = new GeographicZoneDto(); geographicZoneDto.setId(geographicZoneId);