Skip to content

Commit

Permalink
Add Builder classes
Browse files Browse the repository at this point in the history
Allows the creation of SearchLocationService.java and LocationService.java to be more controlled.

Fixes #13
  • Loading branch information
tomaytotomato committed Aug 11, 2024
1 parent 15b6480 commit 83fd87e
Show file tree
Hide file tree
Showing 10 changed files with 22 additions and 23 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,10 @@ protected LocationService(TextNormaliser textNormaliser, CountriesDataLoader dat
buildDataStructures();
}

public static LocationServiceBuilder builder() {
return new LocationServiceBuilder();
}

private void buildDataStructures() {

countries.forEach(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,7 @@ public final class LocationServiceBuilder {
private TextNormaliser textNormaliser = new DefaultTextNormaliser();
private CountriesDataLoader countriesDataLoader = new DefaultCountriesDataLoaderImpl();

public static LocationServiceBuilder builder() {
return new LocationServiceBuilder();
}

private LocationServiceBuilder() {
LocationServiceBuilder() {
}

public LocationServiceBuilder withCountriesDataLoader(CountriesDataLoader countriesDataLoader) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -57,6 +57,10 @@ protected SearchLocationService(TextTokeniser textTokeniser, TextNormaliser text
buildDataStructures();
}

public static SearchLocationServiceBuilder builder() {
return new SearchLocationServiceBuilder();
}

private static Location buildLocationResult(Country topCountry, State topState, City topCity) {
var locationBuilder = Location.builder()

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,7 @@ public final class SearchLocationServiceBuilder {
private LocationAliases locationAliases = new DefaultLocationAliases();
private CountriesDataLoader countriesDataLoader = new DefaultCountriesDataLoaderImpl();

public static SearchLocationServiceBuilder builder() {
return new SearchLocationServiceBuilder();
}

private SearchLocationServiceBuilder() {
SearchLocationServiceBuilder() {
}

public SearchLocationServiceBuilder withTextTokeniser(TextTokeniser textTokeniser) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.assertj.core.api.Assertions.assertThatThrownBy;
import static org.junit.jupiter.api.Assertions.assertEquals;

import com.tomaytotomato.LocationServiceBuilder;
import com.tomaytotomato.LocationService;
import java.math.BigDecimal;
import jdk.jfr.Description;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -19,8 +19,7 @@ class FindCityTest {
private final FindCity locationService;

public FindCityTest() {
locationService = LocationServiceBuilder.builder()
.build();
locationService = LocationService.builder().build();
}

@Description("Find City by Lat/long with BigDecimal")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.tomaytotomato.LocationServiceBuilder;
import com.tomaytotomato.LocationService;
import com.tomaytotomato.model.Country;
import jdk.jfr.Description;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -18,7 +18,7 @@ class FindCountriesByStateTest {
private final FindCountry locationService;

public FindCountriesByStateTest() {
locationService = LocationServiceBuilder.builder().build();
locationService = LocationService.builder().build();
}

@Description("Find All Countries By State Name, when null or blank then throw exception")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.tomaytotomato.LocationServiceBuilder;
import com.tomaytotomato.LocationService;
import com.tomaytotomato.loader.DefaultCountriesDataLoaderImpl;
import com.tomaytotomato.text.normaliser.DefaultTextNormaliser;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -19,7 +19,7 @@ class FindCountryByISOCodeTest {
private final FindCountry locationService;

public FindCountryByISOCodeTest() {
locationService = LocationServiceBuilder.builder()
locationService = LocationService.builder()
.withCountriesDataLoader(new DefaultCountriesDataLoaderImpl())
.withTextNormaliser(new DefaultTextNormaliser())
.build();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.tomaytotomato.LocationServiceBuilder;
import com.tomaytotomato.LocationService;
import com.tomaytotomato.model.Country;
import java.util.List;
import org.junit.jupiter.api.DisplayName;
Expand All @@ -19,7 +19,7 @@ class FindCountryTest {
private final FindCountry locationService;

public FindCountryTest() {
locationService = LocationServiceBuilder.builder().build();
locationService = LocationService.builder().build();
}

@DisplayName("Find Country By ID, when valid and exists, then return Country")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.assertj.core.api.Assertions.assertThat;
import static org.assertj.core.api.Assertions.assertThatThrownBy;

import com.tomaytotomato.LocationServiceBuilder;
import com.tomaytotomato.LocationService;
import jdk.jfr.Description;
import org.junit.jupiter.api.DisplayName;
import org.junit.jupiter.api.Test;
Expand All @@ -18,7 +18,7 @@ class FindStateTest {
private final FindState locationService;

public FindStateTest() {
locationService = LocationServiceBuilder.builder().build();
locationService = LocationService.builder().build();
}

@Description("Find State By ID, when null then throw exception")
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
import static org.assertj.core.api.Assertions.tuple;
import static org.assertj.core.api.AssertionsForInterfaceTypes.assertThat;

import com.tomaytotomato.SearchLocationServiceBuilder;
import com.tomaytotomato.SearchLocationService;
import com.tomaytotomato.aliases.DefaultLocationAliases;
import com.tomaytotomato.loader.DefaultCountriesDataLoaderImpl;
import com.tomaytotomato.mapper.DefaultLocationMapper;
Expand All @@ -23,7 +23,7 @@ class SearchLocationTest {
private final SearchLocation searchLocationService;

public SearchLocationTest() {
searchLocationService = SearchLocationServiceBuilder.builder()
searchLocationService = SearchLocationService.builder()
.withLocationAliases(new DefaultLocationAliases())
.withLocationMapper(new DefaultLocationMapper())
.withCountriesDataLoader(new DefaultCountriesDataLoaderImpl())
Expand Down

0 comments on commit 83fd87e

Please sign in to comment.