123
This commit is contained in:
parent
4acd29c16d
commit
6a77945c6a
8
.idea/.gitignore
generated
vendored
Normal file
8
.idea/.gitignore
generated
vendored
Normal file
@ -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
|
6
.idea/compiler.xml
generated
Normal file
6
.idea/compiler.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="CompilerConfiguration">
|
||||
<bytecodeTargetLevel target="14" />
|
||||
</component>
|
||||
</project>
|
16
.idea/gradle.xml
generated
Normal file
16
.idea/gradle.xml
generated
Normal file
@ -0,0 +1,16 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="GradleMigrationSettings" migrationVersion="1" />
|
||||
<component name="GradleSettings">
|
||||
<option name="linkedExternalProjectsSettings">
|
||||
<GradleProjectSettings>
|
||||
<option name="externalProjectPath" value="$PROJECT_DIR$" />
|
||||
<option name="modules">
|
||||
<set>
|
||||
<option value="$PROJECT_DIR$" />
|
||||
</set>
|
||||
</option>
|
||||
</GradleProjectSettings>
|
||||
</option>
|
||||
</component>
|
||||
</project>
|
5
.idea/misc.xml
generated
Normal file
5
.idea/misc.xml
generated
Normal file
@ -0,0 +1,5 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="ExternalStorageConfigurationManager" enabled="true" />
|
||||
<component name="ProjectRootManager" version="2" languageLevel="JDK_14" default="true" project-jdk-name="liberica-14" project-jdk-type="JavaSDK" />
|
||||
</project>
|
6
.idea/vcs.xml
generated
Normal file
6
.idea/vcs.xml
generated
Normal file
@ -0,0 +1,6 @@
|
||||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<project version="4">
|
||||
<component name="VcsDirectoryMappings">
|
||||
<mapping directory="" vcs="Git" />
|
||||
</component>
|
||||
</project>
|
@ -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", "");
|
||||
}
|
||||
}
|
6
src/main/java/ru/dima/weather/city/IpProvider.java
Normal file
6
src/main/java/ru/dima/weather/city/IpProvider.java
Normal file
@ -0,0 +1,6 @@
|
||||
package ru.dima.weather.city;
|
||||
|
||||
public interface IpProvider {
|
||||
String getCurrentCityViaIP();
|
||||
String getName();
|
||||
}
|
@ -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);
|
||||
|
||||
}
|
||||
|
||||
}
|
Loading…
Reference in New Issue
Block a user