From 12e8d636956ec788906e08f8e69486bc410c2b9c Mon Sep 17 00:00:00 2001
From: Haug Michael <mh306@hdm-stuttgart.de>
Date: Fri, 22 Jun 2018 11:49:06 +0200
Subject: [PATCH] i !<3 tests

---
 .../mi/sd1/weather/model/CopyToFile.java      | 20 ++++++++------
 .../weather/model/SearchingAndComparing.java  |  2 +-
 .../mi/sd1/weather/model/URLCreator.java      |  9 +++++--
 .../mi/sd1/weather/model/WeatherOutput.java   | 11 ++++----
 .../mi/sd1/weather/ErrorInput.java            | 26 ------------------
 .../mi/sd1/weather/URLCreatorTest.java        | 27 +++++++++++++++++++
 .../mi/sd1/weather/WeatherOutputTest.java     | 12 ++++-----
 7 files changed, 58 insertions(+), 49 deletions(-)
 delete mode 100755 src/test/java/de/hdm_stuttgart/mi/sd1/weather/ErrorInput.java
 create mode 100644 src/test/java/de/hdm_stuttgart/mi/sd1/weather/URLCreatorTest.java

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 ba8018f..b417ffd 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
@@ -5,18 +5,21 @@ import org.apache.commons.io.FileUtils;
 
 import java.io.File;
 import java.io.IOException;
+import java.net.URL;
 import java.util.Calendar;
 
 public class CopyToFile {
 
     static String filePath;
 
+
+    /**
+     * Copy data from the URL to a file,
+     * only if the file doesn't exist already or
+     * if it's content is older than 10 minutes.
+     */
     public static void CopyURLToFile(String pathname) {
-        /**
-         * Copy data from the URL to a file,
-         * only if the file doesn't exist already or
-         * if it's content is older than 10 minutes.
-         */
+
         if (new File(pathname).isFile() ||
                 (Calendar.getInstance().getTimeInMillis() - new File(pathname).lastModified() > 600000) &&
                         new File(pathname).lastModified() > 0) {
@@ -35,10 +38,11 @@ public class CopyToFile {
 
     }
 
+    /**
+     *Parse the weather data from the file.
+     */
     public static Weather CopyFileToWeather(String filePath) {
-        /**
-         *Parse the weather data from the file.
-         */
+
         Weather weatherObject = null;
         try {
             weatherObject = WeatherDataParser.parse(filePath);
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 634cddf..890339c 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
@@ -50,7 +50,7 @@ public class SearchingAndComparing {
         if (citySelector[1] != null) {
             City[] multipleResults = Arrays.copyOf(citySelector, k);
 
-            for (int i = 0; i < multipleResults.length; i++) {
+            for (int i = 0; i < multipleResults.length ; i++) {
                 System.out.println(i + 1 + ". " + multipleResults[i].getName() + " \n country: " + multipleResults[i].getCountry() + " | coordinates: " + FormatOutput.cleanCoordOutput(citySelector[i].getAdditionalProperties().toString()));
             }
 
diff --git a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/URLCreator.java b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/URLCreator.java
index cbc2385..3f097ea 100755
--- a/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/URLCreator.java
+++ b/src/main/java/de/hdm_stuttgart/mi/sd1/weather/model/URLCreator.java
@@ -8,8 +8,13 @@ public  class URLCreator {
      * create the URL with the corresponding
      * city ID value created from SearchingAndComparing.
      */
-    public static URL CreateUrl () throws MalformedURLException {
-        URL linkWithId = new URL("https://api.openweathermap.org/data/2.5/forecast?lang=de&APPID=41d009d32d4e302e0cd3d0f55bf5da24&units=metric&id="+ SearchingAndComparing.GetID());
+    public static URL CreateUrl () {
+        URL linkWithId = null;
+        try {
+            linkWithId = new URL("https://api.openweathermap.org/data/2.5/forecast?lang=de&APPID=41d009d32d4e302e0cd3d0f55bf5da24&units=metric&id=" + SearchingAndComparing.GetID());
+        } catch (MalformedURLException e) {
+            System.out.println("ERROR while creating URL");
+        }
         return linkWithId;
     }
 }
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 88a3b60..8d14736 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
@@ -11,7 +11,6 @@ public class WeatherOutput {
          *  of current day + 5 in 3 hour segments
          * @param i timestamps for weatherdata
          */
-
         for (int i = 0; i < weatherObject.getList().length - 1; i++) {
 
             if ((weatherObject.getList()[i].getDtTxt().substring(11, 13).equals("00")) || i == 0) {
@@ -22,7 +21,7 @@ public class WeatherOutput {
 
             System.out.print(Math.round(weatherObject.getList()[i].getMain().getTemp()) + "°C,");
 
-            System.out.print(WeatherOutput.SkyCondidtionOutput(weatherObject.getList()[i].getClouds().getAll()));
+            System.out.print(WeatherOutput.PrintSkyCondidtion(weatherObject.getList()[i].getClouds().getAll()));
 
         }
 
@@ -34,12 +33,12 @@ public class WeatherOutput {
      * @param SkyPercent
      * @return skycondition as String
      */
-    public static String SkyCondidtionOutput(int SkyPercent) {
-        if (SkyPercent < 25 && SkyPercent >= 0) {
+    public static String PrintSkyCondidtion(int SkyPercent) {
+        if (SkyPercent < 15 && SkyPercent >= 0) {
             return " Klarer Himmel" + "\n";
-        } else if (SkyPercent > 25 && SkyPercent < 50) {
+        } else if (SkyPercent > 15 && SkyPercent < 40) {
             return " Ein paar Wolken" + "\n";
-        } else if (SkyPercent > 50 && SkyPercent < 75) {
+        } else if (SkyPercent > 40 && SkyPercent < 75) {
             return " Wolkig" + "\n";
         } else if (SkyPercent > 75 && SkyPercent <= 100) {
             return " Bedeckter Himmel" + "\n";
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
deleted file mode 100755
index a08e514..0000000
--- a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/ErrorInput.java
+++ /dev/null
@@ -1,26 +0,0 @@
-/*
-
-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/URLCreatorTest.java b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/URLCreatorTest.java
new file mode 100644
index 0000000..905dd11
--- /dev/null
+++ b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/URLCreatorTest.java
@@ -0,0 +1,27 @@
+package de.hdm_stuttgart.mi.sd1.weather;
+
+import de.hdm_stuttgart.mi.sd1.weather.model.SearchingAndComparing;
+import de.hdm_stuttgart.mi.sd1.weather.model.URLCreator;
+import org.junit.Assert;
+import org.junit.Test;
+
+import java.net.MalformedURLException;
+import java.net.URL;
+
+public class URLCreatorTest {
+
+     @Test
+    public void CreateURLTest() throws MalformedURLException {
+
+        URL testURL = new URL("https://www.google.de/");
+        Assert.assertEquals(testURL.getClass(),URLCreator.CreateUrl().getClass());
+    }
+
+
+    @Test
+    public void CreateURLTest2() throws MalformedURLException {
+
+        URL testURL = new URL("https://api.openweathermap.org/data/2.5/forecast?lang=de&APPID=41d009d32d4e302e0cd3d0f55bf5da24&units=metric&id=" + SearchingAndComparing.GetID());
+        Assert.assertEquals(testURL,URLCreator.CreateUrl());
+    }
+}
diff --git a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherOutputTest.java b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherOutputTest.java
index ad5a9a6..14bbcfd 100644
--- a/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherOutputTest.java
+++ b/src/test/java/de/hdm_stuttgart/mi/sd1/weather/WeatherOutputTest.java
@@ -12,20 +12,20 @@ public class WeatherOutputTest {
     @Test
     public void TestSkyConditionOutput(){
         String testValue = " Klarer Himmel" + "\n";
-       Assert.assertEquals(WeatherOutput.SkyCondidtionOutput(10),testValue);
+       Assert.assertEquals(WeatherOutput.PrintSkyCondidtion(10),testValue);
 
         testValue = " Ein paar Wolken" + "\n";
-        Assert.assertEquals(WeatherOutput.SkyCondidtionOutput(35),testValue);
+        Assert.assertEquals(WeatherOutput.PrintSkyCondidtion(35),testValue);
 
        testValue = " Wolkig" + "\n";
-        Assert.assertEquals(WeatherOutput.SkyCondidtionOutput(70),testValue);
+        Assert.assertEquals(WeatherOutput.PrintSkyCondidtion(70),testValue);
 
         testValue = " Bedeckter Himmel" + "\n";
-        Assert.assertEquals(WeatherOutput.SkyCondidtionOutput(99),testValue);
+        Assert.assertEquals(WeatherOutput.PrintSkyCondidtion(99),testValue);
 
         testValue = " Something wrong with the sky - just run" + "\n";
-        Assert.assertEquals(WeatherOutput.SkyCondidtionOutput(-666),testValue);
-        Assert.assertEquals(WeatherOutput.SkyCondidtionOutput(666),testValue);
+        Assert.assertEquals(WeatherOutput.PrintSkyCondidtion(-666),testValue);
+        Assert.assertEquals(WeatherOutput.PrintSkyCondidtion(666),testValue);
 
     }
 
-- 
GitLab