Skip to content

Commit

Permalink
OLMIS-7952: Added another test coverage.
Browse files Browse the repository at this point in the history
  • Loading branch information
tsznaj committed Jul 9, 2024
1 parent d62eb5b commit 7ed6367
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,8 @@ public Page<StockCardDto> 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();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -50,6 +53,8 @@
@PowerMockIgnore("javax.security.auth.*")
public class HomeFacilityPermissionServiceTest {

private static final String OTHER_TYPE_CODE = "otherTypeCode";

@InjectMocks
private HomeFacilityPermissionService homeFacilityPermissionService;

Expand Down Expand Up @@ -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);
Expand Down

0 comments on commit 7ed6367

Please sign in to comment.