@@ -0,0 +1,3433 @@
+/*%0A * This program is part of the OpenLMIS logistics management information system platform software.%0A * Copyright %C2%A9 2017 VillageReach%0A *%0A * This program is free software: you can redistribute it and/or modify it under the terms%0A * of the GNU Affero General Public License as published by the Free Software Foundation, either%0A * version 3 of the License, or (at your option) any later version.%0A * %C2%A0%0A * This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;%0A * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.%C2%A0%0A * See the GNU Affero General Public License for more details. You should have received a copy of%0A * the GNU Affero General Public License along with this program. If not, see%0A * http://www.gnu.org/licenses. %C2%A0For additional information contact info@OpenLMIS.org.%C2%A0%0A */%0A%0Apackage org.openlmis.referencedata.service;%0A%0Aimport static org.junit.Assert.assertEquals;%0Aimport static org.mockito.Mockito.when;%0A%0Aimport org.junit.Test;%0Aimport org.junit.runner.RunWith;%0Aimport org.mockito.InjectMocks;%0Aimport org.mockito.Mock;%0Aimport org.mockito.runners.MockitoJUnitRunner;%0Aimport org.openlmis.referencedata.domain.GeographicZone;%0Aimport org.openlmis.referencedata.repository.GeographicZoneRepository;%0A%0Aimport java.util.Arrays;%0Aimport java.util.Collection;%0Aimport java.util.Collections;%0A%0A@RunWith(MockitoJUnitRunner.class)%0Apublic class GeographicZoneServiceTest %7B%0A%0A  @Mock%0A  private GeographicZoneRepository geographicZoneRepository;%0A%0A  @Mock%0A  private GeographicZone parent;%0A%0A  @Mock%0A  private GeographicZone children;%0A%0A  @Mock%0A  private GeographicZone secondChildren;%0A%0A  @Mock%0A  private GeographicZone childrenOfChildren;%0A%0A  @InjectMocks%0A  private GeographicZoneService geographicZoneService;%0A%0A  @Test%0A  public void shouldRetrieveOneDescendant() %7B%0A    when(geographicZoneRepository.findByParent(parent))%0A        .thenReturn(Collections.singletonList(children));%0A%0A    Collection%3CGeographicZone%3E allZonesInHierarchy =%0A        geographicZoneService.getAllZonesInHierarchy(parent);%0A%0A    assertEquals(Collections.singletonList(children), allZonesInHierarchy);%0A  %7D%0A%0A  @Test%0A  public void shouldRetrieveManyDescendantsWhenTheChildrenHasAChildren() %7B%0A    when(geographicZoneRepository.findByParent(parent))%0A        .thenReturn(Collections.singletonList(children));%0A    when(geographicZoneRepository.findByParent(children))%0A        .thenReturn(Collections.singletonList(childrenOfChildren));%0A%0A    Collection%3CGeographicZone%3E allZonesInHierarchy =%0A        geographicZoneService.getAllZonesInHierarchy(parent);%0A%0A    assertEquals(Arrays.asList(children, childrenOfChildren), allZonesInHierarchy);%0A  %7D%0A%0A  @Test%0A  public void shouldRetrieveManyDescendantsWhenParentHasManyChildren() %7B%0A    when(geographicZoneRepository.findByParent(parent))%0A        .thenReturn(Arrays.asList(children, secondChildren));%0A%0A    Collection%3CGeographicZone%3E allZonesInHierarchy =%0A        geographicZoneService.getAllZonesInHierarchy(parent);%0A%0A    assertEquals(Arrays.asList(children, secondChildren), allZonesInHierarchy);%0A  %7D%0A%0A  @Test%0A  public void shouldNotRetrieveAnyDescendantsWhenParentHasNoChildren() %7B%0A    when(geographicZoneRepository.findByParent(parent))%0A        .thenReturn(Collections.emptyList());%0A%0A    Collection%3CGeographicZone%3E allZonesInHierarchy =%0A        geographicZoneService.getAllZonesInHierarchy(parent);%0A%0A    assertEquals(Collections.emptyList(), allZonesInHierarchy);%0A  %7D%0A%7D

add unit tests for GeographicZoneService