убрал нейронки, поменял название переместил классы

This commit is contained in:
swayfarer 2025-05-27 15:54:53 +03:00
parent c992ddccd6
commit 2d6e471c14
6 changed files with 50 additions and 79 deletions

View File

@ -14,6 +14,7 @@ public class WeatherProviderRegistry {
public List<WeatherProvider> getAllWeatherProviders() {
return Collections.unmodifiableList(registeredWeatherProviders);
}
public void addWeatherProvider(WeatherProvider a) {

View File

@ -1,39 +0,0 @@
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import ru.dima.weather.provider.WeatherProvider;
import ru.dima.weather.provider.WeatherProviderRegistry;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
public class WeatherProviderRegistryTest {
private WeatherProviderRegistry registry;
@BeforeEach
public void setUp() {
registry = new WeatherProviderRegistry();
}
@Test
public void testRegisterAndGetWeatherProvider() {
WeatherProvider provider = mock(WeatherProvider.class);
registry.registerWeatherProvider(provider);
List<WeatherProvider> providers = registry.getAllWeatherProviders();
assertEquals(1, providers.size());
assertSame(provider, providers.get(0));
}
@Test
public void testGetAllWeatherProviders_Empty() {
assertTrue(registry.getAllWeatherProviders().isEmpty());
}
@Test
public void testGetAllWeatherProviders_Unmodifiable() {
List<WeatherProvider> providers = registry.getAllWeatherProviders();
assertThrows(UnsupportedOperationException.class, () -> providers.add(mock(WeatherProvider.class)));
}
}

View File

@ -1,10 +1,10 @@
package ru.dima.weather.city;
import org.junit.jupiter.api.Test;
import org.mockito.Mockito;
import ru.dima.weather.cli.CLIInputReader;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.UUID;
import static org.junit.jupiter.api.Assertions.assertEquals;

View File

@ -15,9 +15,9 @@ public class OpenWeatherMapWeatherProviderTest {
@Test
void TestGetName() {
HttpRequester HttpRequester = mock(HttpRequester.class);
OpenWeatherMapWeatherProvider OpenWeatherMapWeatherProvider = new OpenWeatherMapWeatherProvider(HttpRequester, "29ed5ca47c3d0c32385b18f1e82e522f");
void testGetName() {
HttpRequester httpRequester = mock(HttpRequester.class);
OpenWeatherMapWeatherProvider OpenWeatherMapWeatherProvider = new OpenWeatherMapWeatherProvider(httpRequester, "29ed5ca47c3d0c32385b18f1e82e522f");
OpenWeatherMapWeatherProvider.getName();
assertEquals("open-weather-map", OpenWeatherMapWeatherProvider.getName(), "open-weather-map");
@ -30,8 +30,8 @@ public class OpenWeatherMapWeatherProviderTest {
when(httpRequester.getString(anyString())).thenReturn(ft);
OpenWeatherMapWeatherProvider OpenWeatherMapWeatherProvider = new OpenWeatherMapWeatherProvider(httpRequester , "29ed5ca47c3d0c32385b18f1e82e522f" );
var weatherInfo = OpenWeatherMapWeatherProvider.getWeeklyWeatherInCity("Москва");
OpenWeatherMapWeatherProvider openWeatherMapWeatherProvider = new OpenWeatherMapWeatherProvider(httpRequester , "29ed5ca47c3d0c32385b18f1e82e522f" );
var weatherInfo = openWeatherMapWeatherProvider.getWeeklyWeatherInCity("Москва");
assertEquals("MultiDaysWeatherInfo{perDayWeather=[WeatherInfo{temperature=22.5}, WeatherInfo{temperature=19.85}, WeatherInfo{temperature=20.97}, WeatherInfo{temperature=22.19}, WeatherInfo{temperature=25.41}, WeatherInfo{temperature=26.21}, WeatherInfo{temperature=22.53}]}",weatherInfo,"s");
}

View File

@ -7,45 +7,29 @@ import ru.dima.weather.cli.WeatherProviderCLISelector;
import ru.dima.weather.provider.WeatherProvider;
import ru.dima.weather.provider.WeatherProviderRegistry;
import java.io.ByteArrayInputStream;
import java.io.InputStream;
import java.util.Arrays;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.*;
public class WeatherProviderCLISelectorTest {
private CLIInputReader cliInputReader;
private WeatherProviderRegistry weatherProviderRegistry;
private WeatherProviderCLISelector selector;
@BeforeEach
public void setUp() {
cliInputReader = mock(CLIInputReader.class);
weatherProviderRegistry = mock(WeatherProviderRegistry.class);
selector = new WeatherProviderCLISelector(cliInputReader, weatherProviderRegistry);
}
@Test
public void testSelectWeatherProvider_ValidInput() {
WeatherProvider provider = mock(WeatherProvider.class);
when(provider.getName()).thenReturn("Provider 1");
when(weatherProviderRegistry.getAllWeatherProviders()).thenReturn(Arrays.asList(provider));
when(cliInputReader.readInteger()).thenReturn(1);
void testSelectWeatherProviderFromCLI(){
WeatherProviderRegistry weatherProviderRegistry = mock(WeatherProviderRegistry.class);
WeatherProvider provider = Mockito.mock("open-weather-map");
List<WeatherProvider> providers = Arrays.asList(provider);
when(weatherProviderRegistry.getAllWeatherProviders()).thenReturn(providers);
var j = "1";
InputStream inputStream = new ByteArrayInputStream(j.getBytes());
CLIInputReader inputReader = new CLIInputReader(inputStream);
assertEquals(provider, selector.selectWeatherProviderFromCLI());
}
@Test
public void testSelectWeatherProvider_InvalidInput() {
WeatherProvider provider = mock(WeatherProvider.class);
when(provider.getName()).thenReturn("Provider 1");
when(weatherProviderRegistry.getAllWeatherProviders()).thenReturn(Arrays.asList(provider));
when(cliInputReader.readInteger()).thenReturn(2).thenReturn(1);
assertEquals(provider, selector.selectWeatherProviderFromCLI());
}
@Test
public void testSelectWeatherProvider_EmptyProviderList() {
when(weatherProviderRegistry.getAllWeatherProviders()).thenReturn(Arrays.asList());
assertThrows(IndexOutOfBoundsException.class, () -> selector.selectWeatherProviderFromCLI());
}
WeatherProviderCLISelector t = new WeatherProviderCLISelector(inputReader, weatherProviderRegistry);
assertEquals("open-weather-map" , t.selectWeatherProviderFromCLI());
}
}

View File

@ -0,0 +1,25 @@
package ru.dima.weather.city;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import ru.dima.weather.provider.WeatherProvider;
import ru.dima.weather.provider.WeatherProviderRegistry;
import java.util.List;
import static org.junit.jupiter.api.Assertions.*;
import static org.mockito.Mockito.mock;
public class WeatherProviderRegistryTest {
@Test
void registerWeatherProvider(){
WeatherProviderRegistry registry = new WeatherProviderRegistry();
WeatherProvider provider = mock(WeatherProvider.class);
registry.registerWeatherProvider(provider);
List<WeatherProvider> providers = registry.getAllWeatherProviders();
assertEquals(1, providers.size());
assertTrue(providers.contains(provider));
}
}