Skip to content
Snippets Groups Projects
Commit 5c3f3f2c authored by Haug Michael's avatar Haug Michael
Browse files

added 3 tests

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