Добавил еще тестов и вроде бы починил вывод температуры
This commit is contained in:
parent
887a936791
commit
4acd29c16d
@ -35,7 +35,6 @@ public class WeatherApp {
|
|||||||
var weatherProviderCliSelector = new WeatherProviderCLISelector(new CLIInputReader(System.in), weatherProviderRegistry);
|
var weatherProviderCliSelector = new WeatherProviderCLISelector(new CLIInputReader(System.in), weatherProviderRegistry);
|
||||||
var weatherProviderSelectedByUser = weatherProviderCliSelector.selectWeatherProviderFromCLI();
|
var weatherProviderSelectedByUser = weatherProviderCliSelector.selectWeatherProviderFromCLI();
|
||||||
|
|
||||||
|
System.out.println(openWeatherMapProvider.getWeeklyWeatherInCity(ipInfoService.getCurrentCityViaIP()));
|
||||||
// System.out.println(openWeatherMapProvider.getWeeklyWeatherInCity(cityByIpResolver.getCurrentCityViaIP()));
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
27
src/test/java/ru/dima/weather/city/IpInfoServiceTest.java
Normal file
27
src/test/java/ru/dima/weather/city/IpInfoServiceTest.java
Normal file
@ -0,0 +1,27 @@
|
|||||||
|
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;
|
||||||
|
|
||||||
|
public class IpInfoServiceTest {
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testGetCurrentCityViaIP(){
|
||||||
|
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);
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
@ -12,17 +12,34 @@ import static org.mockito.Mockito.when;
|
|||||||
|
|
||||||
public class IpProviderCLISelectorTest {
|
public class IpProviderCLISelectorTest {
|
||||||
@Test
|
@Test
|
||||||
void testSelectIpProviderFromCLI(){
|
void testSelectIpProviderFromCLI_ValidInput() {
|
||||||
CLIInputReader cliInputReader = new CLIInputReader(System.in);
|
CLIInputReader cliInputReader = mock(CLIInputReader.class);
|
||||||
when(cliInputReader.readInteger()).thenReturn(1);
|
when(cliInputReader.readInteger()).thenReturn(1);
|
||||||
|
|
||||||
IpProvider ipProvider1 = mock();
|
IpProvider ipProvider1 = mock(IpProvider.class);
|
||||||
when(ipProvider1.getName()).thenReturn("ubuy");
|
when(ipProvider1.getName()).thenReturn("Provider 1");
|
||||||
|
|
||||||
List<IpProvider> ipProviders = new ArrayList<>();
|
List<IpProvider> ipProviders = new ArrayList<>();
|
||||||
ipProviders.add(ipProvider1);
|
ipProviders.add(ipProvider1);
|
||||||
|
|
||||||
IpProviderCLISelector ipProviderCLISelector = new IpProviderCLISelector(cliInputReader, ipProviders);
|
IpProviderCLISelector ipProviderCLISelector = new IpProviderCLISelector(cliInputReader, ipProviders);
|
||||||
assertEquals("ubuy", ipProviderCLISelector.selectIpProviderFromCLI());
|
assertEquals(ipProvider1, ipProviderCLISelector.selectIpProviderFromCLI());
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
void testSelectIpProviderFromCLI_InvalidInput() {
|
||||||
|
CLIInputReader cliInputReader = mock(CLIInputReader.class);
|
||||||
|
when(cliInputReader.readInteger())
|
||||||
|
.thenReturn(3)
|
||||||
|
.thenReturn(1);
|
||||||
|
|
||||||
|
IpProvider ipProvider1 = mock(IpProvider.class);
|
||||||
|
when(ipProvider1.getName()).thenReturn("Provider 1");
|
||||||
|
|
||||||
|
List<IpProvider> ipProviders = new ArrayList<>();
|
||||||
|
ipProviders.add(ipProvider1);
|
||||||
|
|
||||||
|
IpProviderCLISelector ipProviderCLISelector = new IpProviderCLISelector(cliInputReader, ipProviders);
|
||||||
|
assertEquals(ipProvider1, ipProviderCLISelector.selectIpProviderFromCLI());
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user