test: add tests for WeatherAPI
This commit is contained in:
parent
e1eb03c622
commit
dc6fbd8c4e
@ -10,8 +10,6 @@ public class SampleTest {
|
|||||||
|
|
||||||
@Test
|
@Test
|
||||||
public void testFetchChuckNorrisJoke() throws IOException {
|
public void testFetchChuckNorrisJoke() throws IOException {
|
||||||
JSONObject res = Main.fetchChuckNorrisJoke();
|
|
||||||
Assertions.assertTrue(res.has("value"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
71
src/test/java/eirb/pg203/WeatherAPITest.java
Normal file
71
src/test/java/eirb/pg203/WeatherAPITest.java
Normal file
@ -0,0 +1,71 @@
|
|||||||
|
package eirb.pg203;
|
||||||
|
|
||||||
|
import org.json.JSONObject;
|
||||||
|
import org.junit.jupiter.api.Assertions;
|
||||||
|
import org.junit.jupiter.api.Test;
|
||||||
|
|
||||||
|
import java.io.IOException;
|
||||||
|
|
||||||
|
public class WeatherAPITest {
|
||||||
|
private static String APIKey = "cef8e1b6ea364994b5072423240111";
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRightAPIKey() {
|
||||||
|
WeatherAPI weatherAPI = new WeatherAPI(WeatherAPITest.APIKey);
|
||||||
|
int day = 0;
|
||||||
|
// int hour = 10;
|
||||||
|
int days = 7;
|
||||||
|
String city = "Bordeaux";
|
||||||
|
|
||||||
|
Assertions.assertAll(
|
||||||
|
() -> weatherAPI.getTemperature(day, city),
|
||||||
|
// () -> weatherAPI.getTemperature(day, hour, city),
|
||||||
|
() -> weatherAPI.getTemperatures(days, city)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongAPIKey() {
|
||||||
|
WeatherAPI weatherAPI = new WeatherAPI("");
|
||||||
|
int day = 0;
|
||||||
|
// int hour = 10;
|
||||||
|
int days = 7;
|
||||||
|
String city = "Bordeaux";
|
||||||
|
|
||||||
|
Assertions.assertThrows(IOException.class, () -> weatherAPI.getTemperature(day, city));
|
||||||
|
Assertions.assertThrows(IOException.class, () -> weatherAPI.getTemperatures(days, city));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testWrongDay() {
|
||||||
|
WeatherAPI weatherAPI = new WeatherAPI(WeatherAPITest.APIKey);
|
||||||
|
String city = "Bordeaux";
|
||||||
|
|
||||||
|
Assertions.assertThrows(IOException.class, () -> weatherAPI.getTemperature(-1, city));
|
||||||
|
Assertions.assertThrows(IOException.class, () -> weatherAPI.getTemperature(15, city));
|
||||||
|
Assertions.assertThrows(IOException.class, () -> weatherAPI.getTemperatures(15, city));
|
||||||
|
Assertions.assertThrows(IOException.class, () -> weatherAPI.getTemperatures(-1, city));
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testRightDay() {
|
||||||
|
WeatherAPI weatherAPI = new WeatherAPI(WeatherAPITest.APIKey);
|
||||||
|
String city = "Bordeaux";
|
||||||
|
|
||||||
|
Assertions.assertAll(
|
||||||
|
() -> weatherAPI.getTemperature(0, city),
|
||||||
|
() -> weatherAPI.getTemperature(5, city),
|
||||||
|
() -> weatherAPI.getTemperature(14, city),
|
||||||
|
() -> weatherAPI.getTemperatures(0, city),
|
||||||
|
() -> weatherAPI.getTemperatures(8, city),
|
||||||
|
() -> weatherAPI.getTemperatures(14, city)
|
||||||
|
);
|
||||||
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void testGetAPIName() {
|
||||||
|
WeatherAPI weatherAPI = new WeatherAPI(WeatherAPITest.APIKey);
|
||||||
|
Assertions.assertTrue(weatherAPI.getAPIName().equals("WeatherAPI"));
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
Loading…
x
Reference in New Issue
Block a user