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

i !<3 tests

parent 21403e9c
No related branches found
No related tags found
No related merge requests found
......@@ -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);
......
......@@ -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()));
}
......
......@@ -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;
}
}
......@@ -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";
......
/*
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 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());
}
}
......@@ -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);
}
......
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