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

More unit tests and code cleanup

parent a7cf3285
No related branches found
No related tags found
No related merge requests found
......@@ -23,7 +23,7 @@ public class Forecast {
CopyToFile.CopyURLToFile();
CopyToFile.CopyURLToFile("weatherCache\\" + SearchingAndComparing.GetID() + ".json");
CopyToFile.CopyFileToWeather();
......
......@@ -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;
}
......
......@@ -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);
......
/*
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
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());
}
}
......@@ -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";
......
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