|
16 | 16 | import org.prebid.server.geolocation.model.GeoInfo; |
17 | 17 |
|
18 | 18 | import java.io.IOException; |
19 | | -import java.util.ArrayList; |
20 | 19 |
|
21 | 20 | import static java.util.Collections.singletonList; |
22 | 21 | import static java.util.Collections.singletonMap; |
@@ -62,21 +61,37 @@ public void setDatabaseReaderShouldReturnFailedFutureIfDatabaseArchiveNotFound() |
62 | 61 | public void lookupShouldReturnCountryIsoWhenDatabaseReaderWasSet() throws NoSuchFieldException, IOException, |
63 | 62 | GeoIp2Exception, IllegalAccessException { |
64 | 63 | // given |
65 | | - final Country country = new Country(null, null, null, "fr", null); |
66 | | - final Continent continent = new Continent(null, "eu", null, null); |
67 | | - final City city = new City(singletonList("test"), null, null, singletonMap("test", "Paris")); |
68 | | - final Location location = new Location(null, null, 48.8566, 2.3522, |
69 | | - null, null, null); |
70 | | - final ArrayList<Subdivision> subdivisions = new ArrayList<>(); |
71 | | - subdivisions.add(new Subdivision(null, null, null, "paris", null)); |
72 | | - final CityResponse cityResponse = new CityResponse(city, continent, country, location, null, |
73 | | - null, null, null, subdivisions, null); |
| 64 | + final Country country = Mockito.mock(Country.class); |
| 65 | + Mockito.when(country.getIsoCode()).thenReturn("fr"); |
| 66 | + |
| 67 | + final Continent continent = Mockito.mock(Continent.class); |
| 68 | + Mockito.when(continent.getCode()).thenReturn("eu"); |
| 69 | + |
| 70 | + final City city = Mockito.mock(City.class); |
| 71 | + Mockito.when(city.getNames()).thenReturn(singletonMap("en", "Paris")); |
| 72 | + Mockito.when(city.getName()).thenReturn("Paris"); |
| 73 | + |
| 74 | + final Location location = Mockito.mock(Location.class); |
| 75 | + Mockito.when(location.getLatitude()).thenReturn(48.8566); |
| 76 | + Mockito.when(location.getLongitude()).thenReturn(2.3522); |
| 77 | + |
| 78 | + final Subdivision subdivision = Mockito.mock(Subdivision.class); |
| 79 | + Mockito.when(subdivision.getIsoCode()).thenReturn("paris"); |
| 80 | + |
| 81 | + final CityResponse cityResponse = Mockito.mock(CityResponse.class); |
| 82 | + Mockito.when(cityResponse.getCountry()).thenReturn(country); |
| 83 | + Mockito.when(cityResponse.getContinent()).thenReturn(continent); |
| 84 | + Mockito.when(cityResponse.getCity()).thenReturn(city); |
| 85 | + Mockito.when(cityResponse.getLocation()).thenReturn(location); |
| 86 | + Mockito.when(cityResponse.getSubdivisions()).thenReturn(singletonList(subdivision)); |
74 | 87 |
|
75 | 88 | final DatabaseReader databaseReader = Mockito.mock(DatabaseReader.class); |
76 | 89 | given(databaseReader.city(any())).willReturn(cityResponse); |
77 | 90 |
|
78 | | - new ReflectionMemberAccessor().set(maxMindGeoLocationService.getClass().getDeclaredField("databaseReader"), |
79 | | - maxMindGeoLocationService, databaseReader); |
| 91 | + new ReflectionMemberAccessor().set( |
| 92 | + maxMindGeoLocationService.getClass().getDeclaredField("databaseReader"), |
| 93 | + maxMindGeoLocationService, |
| 94 | + databaseReader); |
80 | 95 |
|
81 | 96 | // when |
82 | 97 | final Future<GeoInfo> future = maxMindGeoLocationService.lookup(TEST_IP, null); |
|
0 commit comments