TD4
This commit is contained in:
75
2020-2021/tests/TD4/flights/FlightServiceTest.java
Normal file
75
2020-2021/tests/TD4/flights/FlightServiceTest.java
Normal file
@@ -0,0 +1,75 @@
|
||||
package TD4.flights;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
import static org.junit.jupiter.api.Assertions.assertEquals;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
|
||||
|
||||
public class FlightServiceTest {
|
||||
|
||||
private static final String PARIS = "Paris";
|
||||
private static final String NICE = "Nice";
|
||||
private static final LocalDate dateToTest = LocalDate.of(2017, 12, 24);
|
||||
|
||||
FlightService service ;
|
||||
|
||||
@Before
|
||||
public void setUp() {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight("Belfort"));
|
||||
list.add(new Flight(NICE));
|
||||
list.add(new Flight(100, dateToTest, LocalTime.of(7, 45),NICE, PARIS));
|
||||
list.add(new Flight(20, dateToTest, LocalTime.of(9, 30), NICE, PARIS));
|
||||
list.add(new Flight(150, dateToTest, LocalTime.of(18, 30), PARIS, NICE));
|
||||
service = new FlightService(list);
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetFlightsOnADivenDate() {
|
||||
List<Flight> flights = service.getFlights(LocalDate.now());
|
||||
assertEquals(2, flights.size());
|
||||
flights = service.getFlights(dateToTest);
|
||||
assertEquals(3, flights.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetFlights() {
|
||||
List<Flight> flights = service.getFlights(LocalDate.now(),NICE,PARIS);
|
||||
assertEquals(1, flights.size());
|
||||
flights = service.getFlights(dateToTest,NICE,PARIS);
|
||||
assertEquals(2, flights.size());
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSortedByPrice() {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight(100, dateToTest, LocalTime.of(7, 45),NICE, PARIS));
|
||||
list.add(new Flight(20, dateToTest, LocalTime.of(9, 30), NICE, PARIS));
|
||||
list.add(new Flight(150, dateToTest, LocalTime.of(18, 30), PARIS, NICE));
|
||||
service = new FlightService(list);
|
||||
List<Flight> flights = service.sortedByPrice();
|
||||
assertEquals(20,flights.get(0).getPrice(),0.01);
|
||||
assertEquals(100,flights.get(1).getPrice(),0.01);
|
||||
assertEquals(150,flights.get(2).getPrice(),0.01);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testGetBestPrice() {
|
||||
ArrayList<Flight> list = new ArrayList<>();
|
||||
list.add(new Flight(100, dateToTest, LocalTime.of(7, 45),NICE, PARIS));
|
||||
list.add(new Flight(20, dateToTest, LocalTime.of(9, 30), NICE, PARIS));
|
||||
list.add(new Flight(150, dateToTest, LocalTime.of(18, 30), PARIS, NICE));
|
||||
service = new FlightService(list);
|
||||
assertEquals(20, service.getFlyWithBestPrice().getPrice());
|
||||
}
|
||||
|
||||
}
|
29
2020-2021/tests/TD4/flights/FlightTest.java
Normal file
29
2020-2021/tests/TD4/flights/FlightTest.java
Normal file
@@ -0,0 +1,29 @@
|
||||
package TD4.flights;
|
||||
|
||||
import static org.junit.Assert.*;
|
||||
|
||||
import java.time.LocalDate;
|
||||
import java.time.LocalTime;
|
||||
|
||||
import org.junit.Before;
|
||||
import org.junit.Test;
|
||||
|
||||
public class FlightTest {
|
||||
|
||||
|
||||
Flight f1 ;
|
||||
@Before
|
||||
public void setUp() {
|
||||
f1 = new Flight(100, LocalDate.of(2017,11,11), LocalTime.of(7, 45),"Nice","Paris");
|
||||
}
|
||||
|
||||
|
||||
@Test
|
||||
public void testGetPrice() {
|
||||
assertEquals(100,f1.getPrice(),0);
|
||||
f1.setPrice(-1);
|
||||
assertTrue(f1.getPrice()>=10);
|
||||
assertTrue(f1.getPrice()<=1000);
|
||||
}
|
||||
|
||||
}
|
Reference in New Issue
Block a user