Skip to content
Snippets Groups Projects
Commit a7cf3285 authored by Bekemeier Fabian's avatar Bekemeier Fabian
Browse files

First Unit Test implemented

parent cfdfbbb8
No related branches found
No related tags found
No related merge requests found
......@@ -21,16 +21,14 @@ public class Forecast {
SearchingAndComparing.MethodSearchingAndComparing();
//TEST FUER GIT PLS IGNORE
CopyToFile.CopyURLToFile();
/*
CopyToFile.CopyURLToFile();
CopyToFile.CopyFileToWeather();
WeatherOutput.PrintWeather();
*/
}
}
......@@ -5,38 +5,37 @@ import org.apache.commons.io.FileUtils;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.sql.Time;
import java.util.Calendar;
public class CopyToFile {
public static String filePath;
public static String CopyURLToFile() {
public static void CopyURLToFile() {
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("weatherCache\\" + SearchingAndComparing.GetID() + ".json").isFile() ||
(Calendar.getInstance().getTimeInMillis() - new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json").lastModified() > 600000) &&
new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json").lastModified() > 0) {
System.out.println("Loading file from cache...");
} else {
try {
FileUtils.copyURLToFile(
URLCreator.CreateUrl(),
new File("weatherCache\\" + SearchingAndComparing.getID() + ".json"));
new File("weatherCache\\" + SearchingAndComparing.GetID() + ".json"));
} catch (IOException e) {
System.out.println("ERROR");
}
}
return "weatherCache\\" + SearchingAndComparing.getID() + ".json";
filePath = "weatherCache\\" + SearchingAndComparing.GetID() + ".json";
//return "weatherCache\\" + SearchingAndComparing.GetID() + ".json";
}
public static Weather CopyFileToWeather() {
Weather weatherObject = null;
try {
weatherObject = WeatherDataParser.parse(CopyToFile.CopyURLToFile());
weatherObject = WeatherDataParser.parse(filePath);
} catch (IOException e) {
System.out.println("ERROR");
}
......
......@@ -9,7 +9,11 @@ import java.util.Scanner;
public class SearchingAndComparing {
static int idToSearch = 0;
static String searchedCity;
static public String GetSearchedCity() {
return searchedCity;
}
static public void MethodSearchingAndComparing() {
System.out.println("Please enter your City: ");
......@@ -70,7 +74,7 @@ public class SearchingAndComparing {
}
public static int getID(){
public static int GetID(){
return idToSearch;
}
......
......@@ -6,7 +6,7 @@ import java.net.URL;
public class URLCreator {
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());
URL linkWithId = new URL("https://api.openweathermap.org/data/2.5/forecast?lang=de&APPID=41d009d32d4e302e0cd3d0f55bf5da24&units=metric&id="+ SearchingAndComparing.GetID());
return linkWithId;
}
}
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 InputTest {
@Test
public void testCityInput() {
Assert.assertNull(SearchingAndComparing.GetSearchedCity());
}
}
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment