feat: display tests
This commit is contained in:
parent
00f77897c9
commit
288895f065
@ -21,13 +21,13 @@ public class WeatherDataAPITest {
|
||||
private static final float epsilon = 0.01F;
|
||||
private static final String APIKey = "realKey";
|
||||
|
||||
private static WeatherAPI weatherAPI(){
|
||||
static WeatherAPI weatherAPI(){
|
||||
WeatherAPI weatherAPI = new WeatherAPI(APIKey);
|
||||
weatherAPI.JSONFetcher = new FakeJSONFetcherWeatherAPI();
|
||||
return weatherAPI;
|
||||
}
|
||||
|
||||
private static OpenWeatherMap openWeatherMap(){
|
||||
static OpenWeatherMap openWeatherMap(){
|
||||
// Fix clock for testing
|
||||
String instantExpected = "2024-11-24T00:00:00.00Z";
|
||||
Clock clock = Clock.fixed(Instant.parse(instantExpected), ZoneId.systemDefault());
|
||||
@ -38,7 +38,7 @@ public class WeatherDataAPITest {
|
||||
return openWeatherMap;
|
||||
}
|
||||
|
||||
private static OpenMeteo openMeteo() {
|
||||
static OpenMeteo openMeteo() {
|
||||
// Fix clock for testing
|
||||
String instantExpected = "2024-11-24T00:00:00.00Z";
|
||||
Clock clock = Clock.fixed(Instant.parse(instantExpected), ZoneId.systemDefault());
|
||||
|
82
src/test/java/eirb/pg203/WeatherDisplayBasicTest.java
Normal file
82
src/test/java/eirb/pg203/WeatherDisplayBasicTest.java
Normal file
@ -0,0 +1,82 @@
|
||||
package eirb.pg203;
|
||||
|
||||
import org.junit.jupiter.api.*;
|
||||
import org.junit.jupiter.params.ParameterizedTest;
|
||||
import org.junit.jupiter.params.provider.Arguments;
|
||||
import org.junit.jupiter.params.provider.CsvSource;
|
||||
import org.junit.jupiter.params.provider.MethodSource;
|
||||
import org.junit.jupiter.params.provider.ValueSource;
|
||||
|
||||
import java.io.ByteArrayOutputStream;
|
||||
import java.io.PrintStream;
|
||||
import java.util.stream.Stream;
|
||||
|
||||
import static eirb.pg203.WeatherDataAPITest.*;
|
||||
|
||||
public class WeatherDisplayBasicTest {
|
||||
private final ByteArrayOutputStream outContent = new ByteArrayOutputStream();
|
||||
private final ByteArrayOutputStream errContent = new ByteArrayOutputStream();
|
||||
private final PrintStream originalOut = System.out;
|
||||
private final PrintStream originalErr = System.err;
|
||||
|
||||
@BeforeEach
|
||||
public void setUpStreams() {
|
||||
System.setOut(new PrintStream(outContent));
|
||||
System.setErr(new PrintStream(errContent));
|
||||
}
|
||||
|
||||
@AfterEach
|
||||
public void restoreStreams() {
|
||||
System.setOut(originalOut);
|
||||
System.setErr(originalErr);
|
||||
}
|
||||
|
||||
private WeatherDisplayBasic weatherDisplayBasic;
|
||||
|
||||
private WeatherDisplayBasic setWeatherDisplayBasic() {
|
||||
/* Fake apis */
|
||||
OpenMeteo openMeteo = openMeteo();
|
||||
OpenWeatherMap openWeatherMap = openWeatherMap();
|
||||
WeatherAPI weatherAPI = weatherAPI();
|
||||
|
||||
WeatherDisplayBasic weatherDisplay = new WeatherDisplayBasic();
|
||||
weatherDisplay.addAPI(openMeteo);
|
||||
weatherDisplay.addAPI(openWeatherMap);
|
||||
weatherDisplay.addAPI(weatherAPI);
|
||||
|
||||
return weatherDisplay;
|
||||
}
|
||||
|
||||
private static Stream<Arguments> display() {
|
||||
return Stream.of(
|
||||
Arguments.arguments(1, new StringBuilder()
|
||||
.append("Source J + 0 \n")
|
||||
.append("------------------------------+-----------------------------+\n")
|
||||
.append("OpenMeteo | 07.60° 🌤 17.60km/h 151.00° 🡮| \n")
|
||||
.append("------------------------------+-----------------------------+\n")
|
||||
.append("WeatherAPI | 08.10° 🌤 17.45km/h 142.08° 🡮| \n")
|
||||
.append("------------------------------+-----------------------------+\n")
|
||||
.append("OpenWeatherMap | 13.41° 🌤 05.74km/h 142.13° 🡮| \n")
|
||||
.append("------------------------------+-----------------------------+\n")
|
||||
.toString()
|
||||
)
|
||||
);
|
||||
|
||||
}
|
||||
|
||||
@ParameterizedTest
|
||||
@MethodSource
|
||||
void display(int days, String expectedDisplay) {
|
||||
String city = "Bordeaux";
|
||||
WeatherDisplayBasic weatherDisplayBasic = setWeatherDisplayBasic();
|
||||
weatherDisplayBasic.display(days, city);
|
||||
|
||||
Assertions.assertEquals(expectedDisplay, outContent.toString());
|
||||
|
||||
}
|
||||
|
||||
@Test
|
||||
void addAPI() {
|
||||
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user