@Test public void shouldNotUpdateDistributionIfAllFacilitiesAreNotSynced() { Long distributionId = 1L; Long modifiedBy = 2L; when(facilityVisitService.getUnsyncedFacilityCountForDistribution(distributionId)).thenReturn(1); DistributionStatus distributionStatus = service.updateDistributionStatus(distributionId, modifiedBy); verify(repository).updateDistributionStatus(distributionId, INITIATED, modifiedBy); assertThat(distributionStatus, is(INITIATED)); }
public DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy) { DistributionStatus distributionStatus = INITIATED; if (facilityVisitService.getUnsyncedFacilityCountForDistribution(distributionId) == 0) { distributionStatus = SYNCED; } repository.updateDistributionStatus(distributionId, distributionStatus, modifiedBy); return distributionStatus; }
DistributionService { public DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy) { DistributionStatus distributionStatus = INITIATED; if (facilityVisitService.getUnsyncedFacilityCountForDistribution(distributionId) == 0) { distributionStatus = SYNCED; } repository.updateDistributionStatus(distributionId, distributionStatus, modifiedBy); return distributionStatus; } }
DistributionService { public DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy) { DistributionStatus distributionStatus = INITIATED; if (facilityVisitService.getUnsyncedFacilityCountForDistribution(distributionId) == 0) { distributionStatus = SYNCED; } repository.updateDistributionStatus(distributionId, distributionStatus, modifiedBy); return distributionStatus; }  }
DistributionService { public DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy) { DistributionStatus distributionStatus = INITIATED; if (facilityVisitService.getUnsyncedFacilityCountForDistribution(distributionId) == 0) { distributionStatus = SYNCED; } repository.updateDistributionStatus(distributionId, distributionStatus, modifiedBy); return distributionStatus; }  @Transactional Distribution create(Distribution distribution); @Transactional FacilityDistribution sync(FacilityDistribution facilityDistribution); Distribution get(Distribution distribution); DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy); List<Long> getSyncedPeriodsForDeliveryZoneAndProgram(Long zoneId, Long programId); Distribution getBy(Long distributionId); }
DistributionService { public DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy) { DistributionStatus distributionStatus = INITIATED; if (facilityVisitService.getUnsyncedFacilityCountForDistribution(distributionId) == 0) { distributionStatus = SYNCED; } repository.updateDistributionStatus(distributionId, distributionStatus, modifiedBy); return distributionStatus; }  @Transactional Distribution create(Distribution distribution); @Transactional FacilityDistribution sync(FacilityDistribution facilityDistribution); Distribution get(Distribution distribution); DistributionStatus updateDistributionStatus(Long distributionId, Long modifiedBy); List<Long> getSyncedPeriodsForDeliveryZoneAndProgram(Long zoneId, Long programId); Distribution getBy(Long distributionId);  }