@Test public void shouldRemoveTheStreetsIfStreetContainsNoVoters() throws Exception { User u = user().build(); String wardCode = "E0911135"; given(wardService.getByCode(wardCode, u)).willReturn(Try.success(ward().withWardCode(wardCode).build())); given(pafAddressService.getStreetsByWard(wardCode)).willReturn(Try.success( ImmutableStreetsByWardResponse.builder() .withStats( ImmutableStats.builder() .withVoters(10) .withCanvassed(5) .build()) .withStreets( asList(street() .withNumVoters(51) .withPostTown("Coventry") .withDependentLocality("") .withMainStreet("London Road") .withNumCanvassed(10) .withPostTown("Coventry") .withPostcode("CV2 4DK") .withPriority(2) .withVotedPledges(3) .withPledged(4) .withNumPostalVoters(23) .build(), street() .withNumVoters(10) .withNumPostalVoters(31) .build()) ) .build())); Try<StreetsByWardResponse> streetsByWardCode = underTest.getTownStreetsByWardCode(wardCode, u); assertThat(streetsByWardCode.isSuccess(), equalTo(true)); StreetsByWardResponse streetsByWardResponse = streetsByWardCode.get(); Stats stats = streetsByWardResponse.stats(); assertThat(stats.canvassed(), is(5)); assertThat(stats.voters(), is(10)); Street street = streetsByWardResponse.streets().get(0); assertThat(street.priority(), is(2)); assertThat(street.postTown(), is("Coventry")); assertThat(street.postcode(), is("CV2 4DK")); assertThat(street.dependentLocality(), is("")); assertThat(street.numCanvassed(), is(10)); }
public Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user) { return wardService .getByCode(wardCode, user) .flatMap(ward -> pafAddressService.getStreetsByWard(ward.getCode())); }
AddressService { public Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user) { return wardService .getByCode(wardCode, user) .flatMap(ward -> pafAddressService.getStreetsByWard(ward.getCode())); } }
AddressService { public Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user) { return wardService .getByCode(wardCode, user) .flatMap(ward -> pafAddressService.getStreetsByWard(ward.getCode())); } @Autowired  AddressService(WardService wardService,
                          PafAddressService pafAddressService); }
AddressService { public Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user) { return wardService .getByCode(wardCode, user) .flatMap(ward -> pafAddressService.getStreetsByWard(ward.getCode())); } @Autowired  AddressService(WardService wardService,
                          PafAddressService pafAddressService); Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user); }
AddressService { public Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user) { return wardService .getByCode(wardCode, user) .flatMap(ward -> pafAddressService.getStreetsByWard(ward.getCode())); } @Autowired  AddressService(WardService wardService,
                          PafAddressService pafAddressService); Try<StreetsByWardResponse> getTownStreetsByWardCode(String wardCode, User user);  }