diff --git a/src/main/java/eirb/pg203/Main.java b/src/main/java/eirb/pg203/Main.java index 25b7d95..800cd5f 100644 --- a/src/main/java/eirb/pg203/Main.java +++ b/src/main/java/eirb/pg203/Main.java @@ -1,5 +1,11 @@ package eirb.pg203; +import eirb.pg203.weather.display.WeatherDisplay; +import eirb.pg203.weather.display.WeatherDisplayBasic; +import eirb.pg203.weather.data.api.OpenMeteo; +import eirb.pg203.weather.data.api.OpenWeatherMap; +import eirb.pg203.weather.data.api.WeatherAPI; + import java.util.ArrayList; import java.util.HashMap; import java.util.List; diff --git a/src/main/java/eirb/pg203/exceptions/WeatherFetchingExceptionApi.java b/src/main/java/eirb/pg203/exceptions/WeatherFetchingExceptionApi.java deleted file mode 100644 index c6657e0..0000000 --- a/src/main/java/eirb/pg203/exceptions/WeatherFetchingExceptionApi.java +++ /dev/null @@ -1,7 +0,0 @@ -package eirb.pg203.exceptions; - -public class WeatherFetchingExceptionApi extends WeatherFetchingException{ - public WeatherFetchingExceptionApi() { - super("An error occurred during API fetching"); - } -} diff --git a/src/main/java/eirb/pg203/exceptions/WeatherFetchingExceptionCityCoords.java b/src/main/java/eirb/pg203/exceptions/WeatherFetchingExceptionCityCoords.java deleted file mode 100644 index 75f472c..0000000 --- a/src/main/java/eirb/pg203/exceptions/WeatherFetchingExceptionCityCoords.java +++ /dev/null @@ -1,7 +0,0 @@ -package eirb.pg203.exceptions; - -public class WeatherFetchingExceptionCityCoords extends WeatherFetchingException{ - public WeatherFetchingExceptionCityCoords() { - super("Impossible to get city coords"); - } -} diff --git a/src/main/java/eirb/pg203/WeatherData.java b/src/main/java/eirb/pg203/weather/data/WeatherData.java similarity index 96% rename from src/main/java/eirb/pg203/WeatherData.java rename to src/main/java/eirb/pg203/weather/data/WeatherData.java index 1a03b68..b728906 100644 --- a/src/main/java/eirb/pg203/WeatherData.java +++ b/src/main/java/eirb/pg203/weather/data/WeatherData.java @@ -1,8 +1,9 @@ -package eirb.pg203; +package eirb.pg203.weather.data; + +import eirb.pg203.weather.utils.City; import java.time.Instant; import java.util.Locale; -import java.util.concurrent.locks.Condition; /** * Weather Data representation @@ -131,7 +132,7 @@ public class WeatherData { } - WeatherData(City city, Instant date, float temp, float windSpeed, float windDirectionAngle, Condition condition) { + public WeatherData(City city, Instant date, float temp, float windSpeed, float windDirectionAngle, Condition condition) { this.city = city; this.date = date; this.temp = temp; diff --git a/src/main/java/eirb/pg203/OpenMeteo.java b/src/main/java/eirb/pg203/weather/data/api/OpenMeteo.java similarity index 91% rename from src/main/java/eirb/pg203/OpenMeteo.java rename to src/main/java/eirb/pg203/weather/data/api/OpenMeteo.java index 75fa51f..ad31c79 100644 --- a/src/main/java/eirb/pg203/OpenMeteo.java +++ b/src/main/java/eirb/pg203/weather/data/api/OpenMeteo.java @@ -1,10 +1,12 @@ -package eirb.pg203; +package eirb.pg203.weather.data.api; -import eirb.pg203.exceptions.WeatherFetchingException; -import eirb.pg203.exceptions.WeatherFetchingExceptionApi; +import eirb.pg203.weather.utils.City; +import eirb.pg203.weather.exceptions.WeatherFetchingException; +import eirb.pg203.weather.exceptions.WeatherFetchingExceptionApi; +import eirb.pg203.weather.data.WeatherData; import org.json.JSONObject; -import eirb.pg203.utils.JSONFetcher; +import eirb.pg203.weather.utils.JSONFetcher; import java.io.IOException; import java.net.URI; @@ -14,7 +16,7 @@ import java.time.Instant; import java.util.ArrayList; import java.util.Locale; -import eirb.pg203.WeatherData.Condition; +import eirb.pg203.weather.data.WeatherData.Condition; // https://api.open-meteo.com/v1/forecast?latitude=52.52&longitude=13.41&hourly=temperature_2m diff --git a/src/main/java/eirb/pg203/OpenWeatherMap.java b/src/main/java/eirb/pg203/weather/data/api/OpenWeatherMap.java similarity index 89% rename from src/main/java/eirb/pg203/OpenWeatherMap.java rename to src/main/java/eirb/pg203/weather/data/api/OpenWeatherMap.java index 2e4e424..ac3d088 100644 --- a/src/main/java/eirb/pg203/OpenWeatherMap.java +++ b/src/main/java/eirb/pg203/weather/data/api/OpenWeatherMap.java @@ -1,12 +1,14 @@ -package eirb.pg203; +package eirb.pg203.weather.data.api; -import eirb.pg203.exceptions.WeatherFetchingException; -import eirb.pg203.exceptions.WeatherFetchingExceptionApi; -import eirb.pg203.exceptions.WeatherFetchingExceptionCityCoords; +import eirb.pg203.weather.utils.City; +import eirb.pg203.weather.exceptions.WeatherFetchingException; +import eirb.pg203.weather.exceptions.WeatherFetchingExceptionApi; +import eirb.pg203.weather.exceptions.WeatherFetchingExceptionCityCoords; +import eirb.pg203.weather.data.WeatherData; import org.json.JSONObject; import org.json.JSONArray; -import eirb.pg203.utils.JSONFetcher; +import eirb.pg203.weather.utils.JSONFetcher; import java.io.IOException; import java.net.URI; @@ -18,7 +20,7 @@ import java.time.ZoneId; import java.util.ArrayList; import java.util.Locale; -import eirb.pg203.WeatherData.Condition; +import eirb.pg203.weather.data.WeatherData.Condition; /** * OpenWeatherMap api implementation @@ -29,7 +31,7 @@ public class OpenWeatherMap implements WeatherDataAPI { Clock clock = Clock.systemUTC(); JSONFetcher JSONFetcher = new JSONFetcher(); - OpenWeatherMap(String APIKey) { + public OpenWeatherMap(String APIKey) { this.APIKey = APIKey; } diff --git a/src/main/java/eirb/pg203/WeatherAPI.java b/src/main/java/eirb/pg203/weather/data/api/WeatherAPI.java similarity index 88% rename from src/main/java/eirb/pg203/WeatherAPI.java rename to src/main/java/eirb/pg203/weather/data/api/WeatherAPI.java index 570b169..02ba852 100644 --- a/src/main/java/eirb/pg203/WeatherAPI.java +++ b/src/main/java/eirb/pg203/weather/data/api/WeatherAPI.java @@ -1,12 +1,14 @@ -package eirb.pg203; +package eirb.pg203.weather.data.api; -import eirb.pg203.exceptions.WeatherFetchingException; -import eirb.pg203.exceptions.WeatherFetchingExceptionApi; +import eirb.pg203.weather.utils.City; +import eirb.pg203.weather.exceptions.WeatherFetchingException; +import eirb.pg203.weather.exceptions.WeatherFetchingExceptionApi; +import eirb.pg203.weather.data.WeatherData; import org.json.JSONArray; import org.json.JSONObject; -import eirb.pg203.WeatherData.Condition; -import eirb.pg203.utils.JSONFetcher; +import eirb.pg203.weather.data.WeatherData.Condition; +import eirb.pg203.weather.utils.JSONFetcher; import java.io.IOException; import java.net.MalformedURLException; @@ -24,7 +26,7 @@ public class WeatherAPI implements WeatherDataAPI{ JSONFetcher JSONFetcher = new JSONFetcher(); private static final String forecastBaseURL = "https://api.weatherapi.com/v1/forecast.json"; - WeatherAPI(String weatherAPIKey) { + public WeatherAPI(String weatherAPIKey) { this.weatherAPIKey = weatherAPIKey; } @@ -49,7 +51,7 @@ public class WeatherAPI implements WeatherDataAPI{ } } - private static WeatherData.Condition getConditionFromString(String str) { + private static Condition getConditionFromString(String str) { if (str.toLowerCase().contains("rain")) return Condition.RAINY; diff --git a/src/main/java/eirb/pg203/WeatherDataAPI.java b/src/main/java/eirb/pg203/weather/data/api/WeatherDataAPI.java similarity index 89% rename from src/main/java/eirb/pg203/WeatherDataAPI.java rename to src/main/java/eirb/pg203/weather/data/api/WeatherDataAPI.java index e9bc5c6..7c922ec 100644 --- a/src/main/java/eirb/pg203/WeatherDataAPI.java +++ b/src/main/java/eirb/pg203/weather/data/api/WeatherDataAPI.java @@ -1,8 +1,8 @@ -package eirb.pg203; +package eirb.pg203.weather.data.api; -import eirb.pg203.exceptions.WeatherFetchingException; +import eirb.pg203.weather.exceptions.WeatherFetchingException; +import eirb.pg203.weather.data.WeatherData; -import java.io.IOException; import java.util.ArrayList; /** diff --git a/src/main/java/eirb/pg203/WeatherDisplay.java b/src/main/java/eirb/pg203/weather/display/WeatherDisplay.java similarity index 84% rename from src/main/java/eirb/pg203/WeatherDisplay.java rename to src/main/java/eirb/pg203/weather/display/WeatherDisplay.java index d6adc3d..6aaf15c 100644 --- a/src/main/java/eirb/pg203/WeatherDisplay.java +++ b/src/main/java/eirb/pg203/weather/display/WeatherDisplay.java @@ -1,4 +1,6 @@ -package eirb.pg203; +package eirb.pg203.weather.display; + +import eirb.pg203.weather.data.api.WeatherDataAPI; /** * How to display weather information, make the API calls based on the collection of WheatherDataAPI diff --git a/src/main/java/eirb/pg203/WeatherDisplayBasic.java b/src/main/java/eirb/pg203/weather/display/WeatherDisplayBasic.java similarity index 95% rename from src/main/java/eirb/pg203/WeatherDisplayBasic.java rename to src/main/java/eirb/pg203/weather/display/WeatherDisplayBasic.java index 887a27f..408d4a8 100644 --- a/src/main/java/eirb/pg203/WeatherDisplayBasic.java +++ b/src/main/java/eirb/pg203/weather/display/WeatherDisplayBasic.java @@ -1,11 +1,13 @@ -package eirb.pg203; +package eirb.pg203.weather.display; -import eirb.pg203.exceptions.WeatherFetchingException; +import eirb.pg203.weather.exceptions.WeatherFetchingException; +import eirb.pg203.weather.data.WeatherData; +import eirb.pg203.weather.data.api.WeatherDataAPI; import java.util.ArrayList; import java.util.HashMap; -class WeatherDisplayBasic implements WeatherDisplay { +public class WeatherDisplayBasic implements eirb.pg203.weather.display.WeatherDisplay { /** * List of apis */ diff --git a/src/main/java/eirb/pg203/exceptions/WeatherFetchingException.java b/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingException.java similarity index 88% rename from src/main/java/eirb/pg203/exceptions/WeatherFetchingException.java rename to src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingException.java index bf286f4..bd6ff28 100644 --- a/src/main/java/eirb/pg203/exceptions/WeatherFetchingException.java +++ b/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingException.java @@ -1,4 +1,4 @@ -package eirb.pg203.exceptions; +package eirb.pg203.weather.exceptions; /** * Exception when an error during the api call diff --git a/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingExceptionApi.java b/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingExceptionApi.java new file mode 100644 index 0000000..16bdf62 --- /dev/null +++ b/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingExceptionApi.java @@ -0,0 +1,7 @@ +package eirb.pg203.weather.exceptions; + +public class WeatherFetchingExceptionApi extends eirb.pg203.weather.exceptions.WeatherFetchingException { + public WeatherFetchingExceptionApi() { + super("An error occurred during API fetching"); + } +} diff --git a/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingExceptionCityCoords.java b/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingExceptionCityCoords.java new file mode 100644 index 0000000..0a71eda --- /dev/null +++ b/src/main/java/eirb/pg203/weather/exceptions/WeatherFetchingExceptionCityCoords.java @@ -0,0 +1,7 @@ +package eirb.pg203.weather.exceptions; + +public class WeatherFetchingExceptionCityCoords extends eirb.pg203.weather.exceptions.WeatherFetchingException { + public WeatherFetchingExceptionCityCoords() { + super("Impossible to get city coords"); + } +} diff --git a/src/main/java/eirb/pg203/City.java b/src/main/java/eirb/pg203/weather/utils/City.java similarity index 93% rename from src/main/java/eirb/pg203/City.java rename to src/main/java/eirb/pg203/weather/utils/City.java index 5084fae..7d76044 100644 --- a/src/main/java/eirb/pg203/City.java +++ b/src/main/java/eirb/pg203/weather/utils/City.java @@ -1,17 +1,16 @@ -package eirb.pg203; +package eirb.pg203.weather.utils; import java.io.IOException; import java.net.URI; import java.net.URL; import java.util.Locale; -import eirb.pg203.utils.JSONFetcher; +import eirb.pg203.weather.utils.Coords; +import eirb.pg203.weather.utils.JSONFetcher; import org.json.JSONArray; import org.json.JSONException; import org.json.JSONObject; -import eirb.pg203.utils.Coords; - /** * Representation of a city * Possibility to get city coordinates based on the name @@ -54,7 +53,7 @@ public class City { return new Coords(lat, lon); } - City (String cityName) { + public City (String cityName) { this.cityName = cityName; } diff --git a/src/main/java/eirb/pg203/utils/Coords.java b/src/main/java/eirb/pg203/weather/utils/Coords.java similarity index 95% rename from src/main/java/eirb/pg203/utils/Coords.java rename to src/main/java/eirb/pg203/weather/utils/Coords.java index 4308549..c78effc 100644 --- a/src/main/java/eirb/pg203/utils/Coords.java +++ b/src/main/java/eirb/pg203/weather/utils/Coords.java @@ -1,4 +1,4 @@ -package eirb.pg203.utils; +package eirb.pg203.weather.utils; /** * Coordinates representation diff --git a/src/main/java/eirb/pg203/utils/JSONFetcher.java b/src/main/java/eirb/pg203/weather/utils/JSONFetcher.java similarity index 80% rename from src/main/java/eirb/pg203/utils/JSONFetcher.java rename to src/main/java/eirb/pg203/weather/utils/JSONFetcher.java index 49d7799..be1b544 100644 --- a/src/main/java/eirb/pg203/utils/JSONFetcher.java +++ b/src/main/java/eirb/pg203/weather/utils/JSONFetcher.java @@ -1,4 +1,4 @@ -package eirb.pg203.utils; +package eirb.pg203.weather.utils; import java.io.BufferedReader; import java.io.IOException; @@ -49,16 +49,4 @@ public class JSONFetcher { return new JSONObject(result); } - - /** - * Fetch a Json array from an url - * @param url url - * @return JSON array - * @throws IOException when request failed - */ - public JSONArray fetchArray(URL url) throws IOException { - String result = fetchString(url); - - return new JSONArray(result); - } } diff --git a/src/test/java/eirb/pg203/WeatherDisplayBasicTest.java b/src/test/java/eirb/pg203/weather/WeatherDisplayBasicTest.java similarity index 90% rename from src/test/java/eirb/pg203/WeatherDisplayBasicTest.java rename to src/test/java/eirb/pg203/weather/WeatherDisplayBasicTest.java index 23656f2..69c2ea2 100644 --- a/src/test/java/eirb/pg203/WeatherDisplayBasicTest.java +++ b/src/test/java/eirb/pg203/weather/WeatherDisplayBasicTest.java @@ -1,17 +1,19 @@ -package eirb.pg203; +package eirb.pg203.weather; +import eirb.pg203.weather.display.WeatherDisplayBasic; +import eirb.pg203.weather.data.api.OpenMeteo; +import eirb.pg203.weather.data.api.OpenWeatherMap; +import eirb.pg203.weather.data.api.WeatherAPI; import org.junit.jupiter.api.*; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; -import org.junit.jupiter.params.provider.CsvSource; import org.junit.jupiter.params.provider.MethodSource; -import org.junit.jupiter.params.provider.ValueSource; import java.io.ByteArrayOutputStream; import java.io.PrintStream; import java.util.stream.Stream; -import static eirb.pg203.WeatherDataAPITest.*; +import static eirb.pg203.weather.data.api.WeatherDataAPITest.*; public class WeatherDisplayBasicTest { private final ByteArrayOutputStream outContent = new ByteArrayOutputStream(); diff --git a/src/test/java/eirb/pg203/WeatherDataTest.java b/src/test/java/eirb/pg203/weather/data/WeatherDataTest.java similarity index 97% rename from src/test/java/eirb/pg203/WeatherDataTest.java rename to src/test/java/eirb/pg203/weather/data/WeatherDataTest.java index 5dac2bc..bbf7a5c 100644 --- a/src/test/java/eirb/pg203/WeatherDataTest.java +++ b/src/test/java/eirb/pg203/weather/data/WeatherDataTest.java @@ -1,5 +1,6 @@ -package eirb.pg203; +package eirb.pg203.weather.data; +import eirb.pg203.weather.utils.City; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; diff --git a/src/test/java/eirb/pg203/WeatherAPITest.java b/src/test/java/eirb/pg203/weather/data/api/WeatherAPITest.java similarity index 62% rename from src/test/java/eirb/pg203/WeatherAPITest.java rename to src/test/java/eirb/pg203/weather/data/api/WeatherAPITest.java index 907ab10..3ecaeb0 100644 --- a/src/test/java/eirb/pg203/WeatherAPITest.java +++ b/src/test/java/eirb/pg203/weather/data/api/WeatherAPITest.java @@ -1,16 +1,9 @@ -package eirb.pg203; +package eirb.pg203.weather.data.api; -import eirb.pg203.fakeJSONFetcher.FakeJSONFetcherWeatherAPI; +import eirb.pg203.weather.fakeJSONFetcher.FakeJSONFetcherWeatherAPI; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.DisplayName; import org.junit.jupiter.api.Test; -import org.junit.jupiter.params.ParameterizedTest; -import org.junit.jupiter.params.provider.*; - -import java.io.IOException; -import java.util.ArrayList; -import java.util.stream.Stream; public class WeatherAPITest { private static final String APIKey = "realKey"; diff --git a/src/test/java/eirb/pg203/WeatherDataAPITest.java b/src/test/java/eirb/pg203/weather/data/api/WeatherDataAPITest.java similarity index 92% rename from src/test/java/eirb/pg203/WeatherDataAPITest.java rename to src/test/java/eirb/pg203/weather/data/api/WeatherDataAPITest.java index 738b262..4d40335 100644 --- a/src/test/java/eirb/pg203/WeatherDataAPITest.java +++ b/src/test/java/eirb/pg203/weather/data/api/WeatherDataAPITest.java @@ -1,17 +1,15 @@ -package eirb.pg203; +package eirb.pg203.weather.data.api; -import eirb.pg203.exceptions.WeatherFetchingException; -import eirb.pg203.fakeJSONFetcher.FakeJSONFetcherOpenMeteo; -import eirb.pg203.fakeJSONFetcher.FakeJSONFetcherOpenWeatherMap; -import eirb.pg203.fakeJSONFetcher.FakeJSONFetcherWeatherAPI; +import eirb.pg203.weather.fakeJSONFetcher.FakeJSONFetcherOpenMeteo; +import eirb.pg203.weather.fakeJSONFetcher.FakeJSONFetcherOpenWeatherMap; +import eirb.pg203.weather.fakeJSONFetcher.FakeJSONFetcherWeatherAPI; +import eirb.pg203.weather.exceptions.WeatherFetchingException; +import eirb.pg203.weather.data.WeatherData; import org.junit.jupiter.api.Assertions; -import org.junit.jupiter.api.DisplayName; -import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; import org.junit.jupiter.params.provider.Arguments; import org.junit.jupiter.params.provider.MethodSource; -import java.io.IOException; import java.time.Clock; import java.time.Instant; import java.time.ZoneId; @@ -22,13 +20,13 @@ public class WeatherDataAPITest { private static final float epsilon = 0.01F; private static final String APIKey = "realKey"; - static WeatherAPI weatherAPI(){ + public static WeatherAPI weatherAPI(){ WeatherAPI weatherAPI = new WeatherAPI(APIKey); weatherAPI.JSONFetcher = new FakeJSONFetcherWeatherAPI(); return weatherAPI; } - static OpenWeatherMap openWeatherMap(){ + public static OpenWeatherMap openWeatherMap(){ // Fix clock for testing String instantExpected = "2024-11-24T00:00:00.00Z"; Clock clock = Clock.fixed(Instant.parse(instantExpected), ZoneId.systemDefault()); @@ -39,7 +37,7 @@ public class WeatherDataAPITest { return openWeatherMap; } - static OpenMeteo openMeteo() { + public static OpenMeteo openMeteo() { // Fix clock for testing String instantExpected = "2024-11-24T00:00:00.00Z"; Clock clock = Clock.fixed(Instant.parse(instantExpected), ZoneId.systemDefault()); @@ -59,7 +57,7 @@ public class WeatherDataAPITest { return Stream.of( /* WeatherAPI */ - Arguments.arguments(weatherAPI(), 0, 8.1F,WeatherData.Condition.PARTIAL, 17.45F, 142.08F), + Arguments.arguments(weatherAPI(), 0, 8.1F, WeatherData.Condition.PARTIAL, 17.45F, 142.08F), Arguments.arguments(weatherAPI(), 1, 13F, WeatherData.Condition.SUNNY, 23.03F, 142.58F), Arguments.arguments(weatherAPI(), 2, 12.7F, WeatherData.Condition.RAINY, 13.19F, 222.92F), Arguments.arguments(weatherAPI(), 3, 8.1F,WeatherData.Condition.CLOUDY, 17.45F, 142.08F), diff --git a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherCity.java b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherCity.java similarity index 60% rename from src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherCity.java rename to src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherCity.java index 8634f12..f9eb3c2 100644 --- a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherCity.java +++ b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherCity.java @@ -1,8 +1,8 @@ -package eirb.pg203.fakeJSONFetcher; +package eirb.pg203.weather.fakeJSONFetcher; -import eirb.pg203.utils.FileResourcesUtils; -import eirb.pg203.utils.JSONFetcher; -import eirb.pg203.utils.SplitQueryUrl; +import eirb.pg203.weather.utils.FileResourcesUtils; +import eirb.pg203.weather.utils.SplitQueryUrl; +import eirb.pg203.weather.utils.JSONFetcher; import org.json.JSONArray; import org.json.JSONObject; @@ -17,9 +17,9 @@ public class FakeJSONFetcherCity extends JSONFetcher{ private static HashMap cities(){ HashMap cities = new HashMap<>(); - cities.put("bordeaux", FileResourcesUtils.getFileFromResourceAsJson("City/bordeaux.json")); - cities.put("paris", FileResourcesUtils.getFileFromResourceAsJson("City/paris.json")); - cities.put("unknown", FileResourcesUtils.getFileFromResourceAsJson("City/fakeCity.json")); + cities.put("bordeaux", eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("City/bordeaux.json")); + cities.put("paris", eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("City/paris.json")); + cities.put("unknown", eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("City/fakeCity.json")); return cities; } diff --git a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherOpenMeteo.java b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherOpenMeteo.java similarity index 79% rename from src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherOpenMeteo.java rename to src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherOpenMeteo.java index 9630f7f..fd9e5e5 100644 --- a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherOpenMeteo.java +++ b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherOpenMeteo.java @@ -1,7 +1,7 @@ -package eirb.pg203.fakeJSONFetcher; +package eirb.pg203.weather.fakeJSONFetcher; -import eirb.pg203.utils.FileResourcesUtils; -import eirb.pg203.utils.JSONFetcher; +import eirb.pg203.weather.utils.FileResourcesUtils; +import eirb.pg203.weather.utils.JSONFetcher; import org.json.JSONArray; import org.json.JSONObject; diff --git a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherOpenWeatherMap.java b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherOpenWeatherMap.java similarity index 70% rename from src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherOpenWeatherMap.java rename to src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherOpenWeatherMap.java index 2561930..5d50e75 100644 --- a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherOpenWeatherMap.java +++ b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherOpenWeatherMap.java @@ -1,8 +1,8 @@ -package eirb.pg203.fakeJSONFetcher; +package eirb.pg203.weather.fakeJSONFetcher; -import eirb.pg203.utils.FileResourcesUtils; -import eirb.pg203.utils.JSONFetcher; -import eirb.pg203.utils.SplitQueryUrl; +import eirb.pg203.weather.utils.FileResourcesUtils; +import eirb.pg203.weather.utils.SplitQueryUrl; +import eirb.pg203.weather.utils.JSONFetcher; import org.json.JSONArray; import org.json.JSONObject; @@ -15,7 +15,7 @@ public class FakeJSONFetcherOpenWeatherMap extends JSONFetcher { private final JSONObject wrongKeyResponse = FileResourcesUtils.getFileFromResourceAsJson("OpenWeatherMap/wrong-apikey.json"); private JSONObject responseExample() { - return FileResourcesUtils.getFileFromResourceAsJson("OpenWeatherMap/Bordeaux-partial-cloudy-rain-sunny.json"); + return eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("OpenWeatherMap/Bordeaux-partial-cloudy-rain-sunny.json"); } @Override public JSONObject fetch(URL url) throws IOException { diff --git a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherWeatherAPI.java b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherWeatherAPI.java similarity index 59% rename from src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherWeatherAPI.java rename to src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherWeatherAPI.java index e5d4170..3f8ab6f 100644 --- a/src/test/java/eirb/pg203/fakeJSONFetcher/FakeJSONFetcherWeatherAPI.java +++ b/src/test/java/eirb/pg203/weather/fakeJSONFetcher/FakeJSONFetcherWeatherAPI.java @@ -1,8 +1,8 @@ -package eirb.pg203.fakeJSONFetcher; +package eirb.pg203.weather.fakeJSONFetcher; -import eirb.pg203.utils.FileResourcesUtils; -import eirb.pg203.utils.JSONFetcher; -import eirb.pg203.utils.SplitQueryUrl; +import eirb.pg203.weather.utils.FileResourcesUtils; +import eirb.pg203.weather.utils.SplitQueryUrl; +import eirb.pg203.weather.utils.JSONFetcher; import org.json.JSONArray; import org.json.JSONObject; @@ -17,10 +17,10 @@ public class FakeJSONFetcherWeatherAPI extends JSONFetcher { private static final JSONObject wrongKeyRequest = FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/wrong-apikey.json"); private static ArrayList bordeauxRequests() { ArrayList bordeauxRequest = new ArrayList<>(); - bordeauxRequest.add(FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-1-partial.json")); - bordeauxRequest.add(FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-2-partial-sunny.json")); - bordeauxRequest.add(FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-3-partial-sunny-rain.json")); - bordeauxRequest.add(FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-4-partial-sunny-rain-cloudy.json")); + bordeauxRequest.add(eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-1-partial.json")); + bordeauxRequest.add(eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-2-partial-sunny.json")); + bordeauxRequest.add(eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-3-partial-sunny-rain.json")); + bordeauxRequest.add(eirb.pg203.weather.utils.FileResourcesUtils.getFileFromResourceAsJson("WeatherAPI/Bordeaux-4-partial-sunny-rain-cloudy.json")); return bordeauxRequest; } diff --git a/src/test/java/eirb/pg203/CityTest.java b/src/test/java/eirb/pg203/weather/utils/CityTest.java similarity index 94% rename from src/test/java/eirb/pg203/CityTest.java rename to src/test/java/eirb/pg203/weather/utils/CityTest.java index 2dad7b6..a0833ff 100644 --- a/src/test/java/eirb/pg203/CityTest.java +++ b/src/test/java/eirb/pg203/weather/utils/CityTest.java @@ -1,7 +1,6 @@ -package eirb.pg203; +package eirb.pg203.weather.utils; -import eirb.pg203.fakeJSONFetcher.FakeJSONFetcherCity; -import eirb.pg203.utils.Coords; +import eirb.pg203.weather.fakeJSONFetcher.FakeJSONFetcherCity; import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import org.junit.jupiter.params.ParameterizedTest; diff --git a/src/test/java/eirb/pg203/utils/CoordsTest.java b/src/test/java/eirb/pg203/weather/utils/CoordsTest.java similarity index 70% rename from src/test/java/eirb/pg203/utils/CoordsTest.java rename to src/test/java/eirb/pg203/weather/utils/CoordsTest.java index 374e731..c2a24e0 100644 --- a/src/test/java/eirb/pg203/utils/CoordsTest.java +++ b/src/test/java/eirb/pg203/weather/utils/CoordsTest.java @@ -1,6 +1,5 @@ -package eirb.pg203.utils; +package eirb.pg203.weather.utils; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.*; @@ -14,7 +13,7 @@ class CoordsTest { float lon = 2f; Coords coords = new Coords(lat, lon); - Assertions.assertEquals(lat, coords.getLat(), epsilon); + assertEquals(lat, coords.getLat(), epsilon); } @Test @@ -23,7 +22,7 @@ class CoordsTest { float lon = 2f; Coords coords = new Coords(lat, lon); - Assertions.assertEquals(lon, coords.getLon(), epsilon); + assertEquals(lon, coords.getLon(), epsilon); } @Test @@ -35,7 +34,7 @@ class CoordsTest { float sndLat = 3f; coords.setLat(sndLat); - Assertions.assertEquals(sndLat, coords.getLat(), epsilon); + assertEquals(sndLat, coords.getLat(), epsilon); } @@ -48,7 +47,7 @@ class CoordsTest { float sndLon = 4f; coords.setLon(sndLon); - Assertions.assertEquals(sndLon, coords.getLon(), epsilon); + assertEquals(sndLon, coords.getLon(), epsilon); } } \ No newline at end of file diff --git a/src/test/java/eirb/pg203/utils/FileResourcesUtils.java b/src/test/java/eirb/pg203/weather/utils/FileResourcesUtils.java similarity index 97% rename from src/test/java/eirb/pg203/utils/FileResourcesUtils.java rename to src/test/java/eirb/pg203/weather/utils/FileResourcesUtils.java index 8398e38..2e83ade 100644 --- a/src/test/java/eirb/pg203/utils/FileResourcesUtils.java +++ b/src/test/java/eirb/pg203/weather/utils/FileResourcesUtils.java @@ -1,4 +1,4 @@ -package eirb.pg203.utils; +package eirb.pg203.weather.utils; import org.json.JSONObject; diff --git a/src/test/java/eirb/pg203/utils/SplitQueryUrl.java b/src/test/java/eirb/pg203/weather/utils/SplitQueryUrl.java similarity index 95% rename from src/test/java/eirb/pg203/utils/SplitQueryUrl.java rename to src/test/java/eirb/pg203/weather/utils/SplitQueryUrl.java index 00819c6..881a9ab 100644 --- a/src/test/java/eirb/pg203/utils/SplitQueryUrl.java +++ b/src/test/java/eirb/pg203/weather/utils/SplitQueryUrl.java @@ -1,4 +1,4 @@ -package eirb.pg203.utils; +package eirb.pg203.weather.utils; import java.io.UnsupportedEncodingException; import java.net.URL;