From 5c3f3f2c6ccd4177aa2455ed69327c181394fae6 Mon Sep 17 00:00:00 2001
From: Haug Michael <mh306@hdm-stuttgart.de>
Date: Thu, 21 Jun 2018 19:35:48 +0200
Subject: [PATCH] added 3 tests

---
 .../mi/sd1/weather/Forecast.java              |  2 +-
 .../mi/sd1/weather/model/CopyToFile.java      | 12 +++--
 .../mi/sd1/weather/model/WeatherOutput.java   |  2 +-
 .../mi/sd1/weather/CopyToFileTest.java        | 45 +++++++++++++++++++
 4 files changed, 52 insertions(+), 9 deletions(-)
 create mode 100644 src/test/java/de/hdm_stuttgart/mi/sd1/weather/CopyToFileTest.java

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 33e607a..37a0112 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 b79571d..ba8018f 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 8b57080..b523e4f 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 0000000..8711160
--- /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"));
+
+
+    }
+}
-- 
GitLab