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 33e607a0a662c537969aa12784eb03dc43d9a6b3..37a011262e8178e07a2cae50497160f29876c913 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 @@ -25,7 +25,7 @@ public class Forecast { CopyToFile.CopyURLToFile("weatherCache\\" + SearchingAndComparing.GetID() + ".json"); - CopyToFile.CopyFileToWeather(); + CopyToFile.CopyFileToWeather("weatherCache\\" + SearchingAndComparing.GetID() + ".json"); WeatherOutput.PrintWeather(); 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 b79571d2684ec42b53b03639509654eb553e6783..ba8018ffb5fa26d934706bf4c4299939ec384b4a 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 @@ -35,7 +35,7 @@ public class CopyToFile { } - public static Weather CopyFileToWeather() { + public static Weather CopyFileToWeather(String filePath) { /** *Parse the weather data from the file. */ @@ -43,15 +43,13 @@ public class CopyToFile { try { weatherObject = WeatherDataParser.parse(filePath); } catch (IOException e) { - System.out.println("ERROR"); + System.out.println("Something went wrong while parsing"); } return weatherObject; } - /* public static long test() { - File fileTest = new File("weatherdata.json"); - boolean ergebnis = fileTest.setLastModified(Calendar.getInstance().getTimeInMillis()); - return fileTest.lastModified(); + + public static String getFilePath() { + return filePath; } -*/ } \ No newline at end of file diff --git a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/WeatherOutput.java b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/WeatherOutput.java index 8b570804e5d4b2cb79f0d6258ef5c16099f12f59..b523e4fab81293ff9fc7bb71940e778b226dc9d8 100755 --- a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/WeatherOutput.java +++ b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/WeatherOutput.java @@ -4,7 +4,7 @@ public class WeatherOutput { public static void PrintWeather() { - Weather weatherObject = CopyToFile.CopyFileToWeather(); + Weather weatherObject = CopyToFile.CopyFileToWeather("weatherCache\\" + SearchingAndComparing.GetID() + ".json"); /** * method to print the temperature diff --git a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/CopyToFileTest.java b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/CopyToFileTest.java new file mode 100644 index 0000000000000000000000000000000000000000..87111607510aa7e1384e1ec21acf5565db9640ce --- /dev/null +++ b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/CopyToFileTest.java @@ -0,0 +1,45 @@ +package de.hdm_stuttgart.mi.sd1.weather; + +import de.hdm_stuttgart.mi.sd1.weather.model.CopyToFile; +import de.hdm_stuttgart.mi.sd1.weather.model.SearchingAndComparing; +import de.hdm_stuttgart.mi.sd1.weather.model.Weather; +import org.junit.Assert; +import org.junit.Test; + +import java.io.File; +import java.io.IOException; + +public class CopyToFileTest { + + @Test + public void TestCopyFileToWeatherClass() { + Weather weatherForTest = new Weather(); + Assert.assertEquals(weatherForTest.getClass(), CopyToFile.CopyFileToWeather("weatherCache\\" + "3220785.json").getClass()); + } + + + @Test + public void TestCopyFIleToWeatherException() { + + try { + CopyToFile.CopyFileToWeather("wrong path"); + } catch (Exception e) { + Assert.fail(); + } + } + + @Test + public void TestCopyURLToFile() throws IOException { + String testName = "testfile"; + File test = new File(testName + ".json"); + test.createNewFile(); + CopyToFile.CopyURLToFile(testName + ".json"); + + + Assert.assertEquals(CopyToFile.getFilePath(), testName + ".json"); + + // Assert.assertTrue(CopyToFile.getFilePath().equals(testName + ".json")); + + + } +}