@Test public void shouldCreateDistribution() { Distribution distribution = new Distribution(); Distribution expectedDistribution = new Distribution(); when(repository.create(distribution)).thenReturn(expectedDistribution); Map<Long, FacilityDistribution> facilityDistributions = new HashMap<>(); when(facilityDistributionService.createFor(expectedDistribution)).thenReturn(facilityDistributions); Distribution initiatedDistribution = service.create(distribution); verify(repository).create(distribution); assertThat(initiatedDistribution, is(expectedDistribution)); assertThat(initiatedDistribution.getFacilityDistributions(), is(facilityDistributions)); }
@Transactional public Distribution create(Distribution distribution) { Distribution savedDistribution = repository.create(distribution); Map<Long, FacilityDistribution> facilityDistributions = facilityDistributionService.createFor(distribution); savedDistribution.setFacilityDistributions(facilityDistributions); return savedDistribution; }
DistributionService { @Transactional public Distribution create(Distribution distribution) { Distribution savedDistribution = repository.create(distribution); Map<Long, FacilityDistribution> facilityDistributions = facilityDistributionService.createFor(distribution); savedDistribution.setFacilityDistributions(facilityDistributions); return savedDistribution; } }
DistributionService { @Transactional public Distribution create(Distribution distribution) { Distribution savedDistribution = repository.create(distribution); Map<Long, FacilityDistribution> facilityDistributions = facilityDistributionService.createFor(distribution); savedDistribution.setFacilityDistributions(facilityDistributions); return savedDistribution; }  }
DistributionService { @Transactional public Distribution create(Distribution distribution) { Distribution savedDistribution = repository.create(distribution); Map<Long, FacilityDistribution> facilityDistributions = facilityDistributionService.createFor(distribution); savedDistribution.setFacilityDistributions(facilityDistributions); return savedDistribution; }  @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 { @Transactional public Distribution create(Distribution distribution) { Distribution savedDistribution = repository.create(distribution); Map<Long, FacilityDistribution> facilityDistributions = facilityDistributionService.createFor(distribution); savedDistribution.setFacilityDistributions(facilityDistributions); return savedDistribution; }  @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);  }