diff --git a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/Forecast.java b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/Forecast.java index 2635917061eb51d60658aac9d8cf1f704c0d9c87..49cf6c5af85cc0f76ef840f0a39ae221a2d0f125 100755 --- a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/Forecast.java +++ b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/Forecast.java @@ -23,7 +23,7 @@ public class Forecast { - CopyToFile.CopyURLToFile(); + CopyToFile.CopyURLToFile("weatherCache\\" + SearchingAndComparing.GetID() + ".json"); CopyToFile.CopyFileToWeather(); diff --git a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/CopyToFile.java b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/CopyToFile.java index 89e8ff3f0673b54463edcd7221c48dd88bd27e51..7f7099c2a42a9f4843c2798cfc99e33a1a747283 100755 --- a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/CopyToFile.java +++ b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/CopyToFile.java @@ -11,24 +11,24 @@ public class CopyToFile { public static String filePath; - public static void CopyURLToFile() { + public static void CopyURLToFile(String pathname) { - if (new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json").isFile() || - (Calendar.getInstance().getTimeInMillis() - new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json").lastModified() > 600000) && - new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json").lastModified() > 0) { + if (new File(pathname).isFile() || + (Calendar.getInstance().getTimeInMillis() - new File(pathname).lastModified() > 600000) && + new File(pathname).lastModified() > 0) { System.out.println("Loading file from cache..."); } else { try { FileUtils.copyURLToFile( URLCreator.CreateUrl(), - new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json")); + new File(pathname)); } catch (IOException e) { System.out.println("ERROR"); } } - filePath = "weatherCache\\" + SearchingAndComparing.GetID() + ".json"; - //return "weatherCache\\" + SearchingAndComparing.GetID() + ".json"; + filePath = pathname; + //return pathname; } diff --git a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/SearchingAndComparing.java b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/SearchingAndComparing.java index 0d25bffd1502701359ac100d0fe48ecb2cfdb64b..6c67780aeef542a8185d2ecd4909f3fd37625b60 100755 --- a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/SearchingAndComparing.java +++ b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/SearchingAndComparing.java @@ -19,7 +19,7 @@ public class SearchingAndComparing { System.out.println("Please enter your City: "); Scanner scanCity = new Scanner(System.in); String searchedCity = scanCity.nextLine(); - //String searchedCity = "Republic of India"; + // String searchedCity = "Republic of India"; /** * Searching and comparing cities @@ -49,7 +49,7 @@ public class SearchingAndComparing { City[] multipleResults = Arrays.copyOf(citySelector, k); for (int i = 0; i < multipleResults.length; i++) { - System.out.println(i + 1 + ". " + multipleResults[i].getName() + " \n country: " + multipleResults[i].getCountry() + " | coordinates: " + citySelector[0].getAdditionalProperties()); + System.out.println(i + 1 + ". " + multipleResults[i].getName() + " \n country: " + multipleResults[i].getCountry() + " | coordinates: " + citySelector[i].getAdditionalProperties()); } System.out.println("Please enter the number of the city you want weatherdata for: "); Scanner scanCityChoice = new Scanner(System.in); diff --git a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/ErrorInput.java b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/ErrorInput.java new file mode 100755 index 0000000000000000000000000000000000000000..a08e514e6363e650d9be6f8d35def533cdb361ab --- /dev/null +++ b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/ErrorInput.java @@ -0,0 +1,26 @@ +/* + +package de.hdm_stuttgart.mi.sd1.weather; + +import org.junit.Assert; +import org.junit.Test; +public class ErrorInput { + @Test + int SkyPercent = 50; + int SkyPercent2 = 101; + public void TestErrorInput(){ + Assert.assertEquals(" Something wrong with the sky - just run" + "\n", ); + } + + + + + + + + + + + +} +*/ \ No newline at end of file diff --git a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/GetIDTest.java b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/GetIDTest.java new file mode 100755 index 0000000000000000000000000000000000000000..ad0c7b42553988e185f37dbcfd3711d15da24a52 --- /dev/null +++ b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/GetIDTest.java @@ -0,0 +1,13 @@ +package de.hdm_stuttgart.mi.sd1.weather; + +import de.hdm_stuttgart.mi.sd1.weather.model.SearchingAndComparing; +import org.junit.Assert; +import org.junit.Test; + +public class GetIDTest { + @Test + public void GetIDTest() { + Assert.assertEquals(0,SearchingAndComparing.GetID()); + } + +} diff --git a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherDataParseTest.java b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherDataParseTest.java index 161556c6d531b796e9d9000d4fe96903225f85de..e03bf2fc41c88588ac6796888271a6d96bdd2d83 100755 --- a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherDataParseTest.java +++ b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherDataParseTest.java @@ -6,7 +6,8 @@ import org.junit.Test; import java.io.IOException; -public class WeatherDataParseTest { +public class +WeatherDataParseTest { @Test public void testParseWeatherData() { final String sampleWeatherDataFileName = "src/main/resources/stuttgart.weather.json";