org.catools.common.facker.provider.CFakerAddressProvider Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of common-randomize Show documentation
Show all versions of common-randomize Show documentation
The Common Randomize Implementation
package org.catools.common.facker.provider;
import lombok.AllArgsConstructor;
import org.catools.common.facker.model.CRandomAddress;
import org.catools.common.facker.model.CRandomCity;
import org.catools.common.facker.model.CRandomStreetInfo;
@AllArgsConstructor
public class CFakerAddressProvider {
private final CFakerCountryProvider country;
private final CFakerStreetAddressProvider streetAddressProvider;
public CRandomAddress getAny() {
return getAny(country.getStateProviders().getAny().getState().getCode());
}
public CRandomAddress getAny(String stateCode) {
CFakerStateProvider state = country.getStateProviders().getFirst(s -> s.getState().getCode().equalsIgnoreCase(stateCode));
return getAny(stateCode, state.getRandomCity().getName());
}
public CRandomAddress getAny(String stateCode, String cityname) {
CFakerStateProvider state = country.getStateProviders().getFirst(s -> s.getState().getCode().equalsIgnoreCase(stateCode));
CRandomCity city = state.getCities().getFirst(s -> s.getName().equalsIgnoreCase(cityname));
CRandomStreetInfo streetInfo = streetAddressProvider.getAny();
return new CRandomAddress(country.getCountry(),
state.getState(),
city,
streetInfo.getStreetName(),
streetInfo.getStreetSuffix(),
streetInfo.getStreetPrefix(),
streetInfo.getStreetNumber(),
streetInfo.getBuildingNumber());
}
}