diff --git a/.idea/.gitignore b/.idea/.gitignore new file mode 100644 index 0000000..13566b8 --- /dev/null +++ b/.idea/.gitignore @@ -0,0 +1,8 @@ +# Default ignored files +/shelf/ +/workspace.xml +# Editor-based HTTP Client requests +/httpRequests/ +# Datasource local storage ignored files +/dataSources/ +/dataSources.local.xml diff --git a/.idea/compiler.xml b/.idea/compiler.xml new file mode 100644 index 0000000..ac216bc --- /dev/null +++ b/.idea/compiler.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/.idea/gradle.xml b/.idea/gradle.xml new file mode 100644 index 0000000..ce1c62c --- /dev/null +++ b/.idea/gradle.xml @@ -0,0 +1,16 @@ + + + + + + + \ No newline at end of file diff --git a/.idea/misc.xml b/.idea/misc.xml new file mode 100644 index 0000000..057f261 --- /dev/null +++ b/.idea/misc.xml @@ -0,0 +1,5 @@ + + + + + \ No newline at end of file diff --git a/.idea/vcs.xml b/.idea/vcs.xml new file mode 100644 index 0000000..35eb1dd --- /dev/null +++ b/.idea/vcs.xml @@ -0,0 +1,6 @@ + + + + + + \ No newline at end of file diff --git a/src/main/java/ru/dima/weather/city/CityByIpResolver.java b/src/main/java/ru/dima/weather/city/CityByIpResolver.java deleted file mode 100644 index 1d5016b..0000000 --- a/src/main/java/ru/dima/weather/city/CityByIpResolver.java +++ /dev/null @@ -1,20 +0,0 @@ -package ru.dima.weather.city; - -import ru.dima.weather.http.HttpRequester; - -public class CityByIpResolver { - - public static final String IP_INFO_URL = "https://ipinfo.io/city"; - - private HttpRequester httpRequester; - - public CityByIpResolver(HttpRequester httpRequester) { - this.httpRequester = httpRequester; - } - - public String getCurrentCityViaIP() { - return httpRequester.getString(IP_INFO_URL) - .replace("\n", "") - .replace("\r", ""); - } -} diff --git a/src/main/java/ru/dima/weather/city/IpProvider.java b/src/main/java/ru/dima/weather/city/IpProvider.java new file mode 100644 index 0000000..77c5c40 --- /dev/null +++ b/src/main/java/ru/dima/weather/city/IpProvider.java @@ -0,0 +1,6 @@ +package ru.dima.weather.city; + +public interface IpProvider { + String getCurrentCityViaIP(); + String getName(); +} diff --git a/src/test/java/ru/dima/weather/city/CityByIpResolverTest.java b/src/test/java/ru/dima/weather/city/CityByIpResolverTest.java deleted file mode 100644 index 6a2dc5f..0000000 --- a/src/test/java/ru/dima/weather/city/CityByIpResolverTest.java +++ /dev/null @@ -1,26 +0,0 @@ -package ru.dima.weather.city; - -import org.junit.jupiter.api.Test; -import org.mockito.Mockito; -import ru.dima.weather.http.HttpRequester; - -import java.util.UUID; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -class CityByIpResolverTest { - - @Test - void mustReturnPlaintextCityFromIp() { - var mockHttpRequester = Mockito.mock(HttpRequester.class); - var cityByIpResolver = new IpInfoService(mockHttpRequester); - var randomCityName = UUID.randomUUID().toString(); - - Mockito.when(mockHttpRequester.getString(Mockito.any())).thenReturn(randomCityName); - - var currentCity = cityByIpResolver.getCurrentCityViaIP(); - assertEquals(randomCityName, currentCity); - - } - -} \ No newline at end of file