85 lines
3.1 KiB
Java
85 lines
3.1 KiB
Java
package eirb.pg203.weather;
|
|
|
|
import eirb.pg203.weather.display.WeatherDisplayBasic;
|
|
import eirb.pg203.weather.data.api.OpenMeteo;
|
|
import eirb.pg203.weather.data.api.OpenWeatherMap;
|
|
import eirb.pg203.weather.data.api.WeatherAPI;
|
|
import org.junit.jupiter.api.*;
|
|
import org.junit.jupiter.params.ParameterizedTest;
|
|
import org.junit.jupiter.params.provider.Arguments;
|
|
import org.junit.jupiter.params.provider.MethodSource;
|
|
|
|
import java.io.ByteArrayOutputStream;
|
|
import java.io.PrintStream;
|
|
import java.util.stream.Stream;
|
|
|
|
import static eirb.pg203.weather.data.api.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() {
|
|
|
|
}
|
|
}
|