"refonte debut annee"

This commit is contained in:
JunkJumper
2020-09-09 14:43:31 +02:00
parent bae81ba64e
commit 6a1b2f5c36
72 changed files with 0 additions and 0 deletions

View File

@@ -0,0 +1,87 @@
package openClosedPrinciples.core;
import static org.junit.Assert.*;
import java.time.LocalDate;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import openClosedPrinciples.core.Car;
import openClosedPrinciples.core.CarRental;
import openClosedPrinciples.core.CarRentalService;
import openClosedPrinciples.core.NotPossibleCarRentalException;
public class CarRentalServiceTest {
CarRentalService service ;
Car myCar0 = new Car("1111 AB 06",50);
Car myCar1 = new Car("1111 AB 75",100);
Car myCar2 = new Car("1111 AB 83",75);
LocalDate currentDate;
@Before
public void setUp() throws Exception {
myCar0 = new Car("1111 AB 06",50);
myCar1 = new Car("1111 AB 75",100);
myCar2 = new Car("1111 AB 83",75);
service = new CarRentalService( new ArrayList<>(Arrays.asList(myCar0, myCar1, myCar2) ) ) ;
}
@Test
public void testGetAvailableCars() {
ArrayList<Car> possibleCars =
(ArrayList<Car>) service.getAvailableCars(LocalDate.of(2018,9,11), 2);
assertEquals(3, possibleCars.size());
}
@Test
public void testBookAnAvalaibleCar() throws NotPossibleCarRentalException {
CarRental carRental = service.book(myCar0,LocalDate.of(2018,9,11), 2);
assertFalse(carRental==null);
List<Car> possibleCars = service.getAvailableCars(LocalDate.of(2018,9,11), 1);
assertEquals(2, possibleCars.size());
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,12), 3);
assertEquals(2, possibleCars.size());
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,13), 3);
assertEquals(3, possibleCars.size());
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,9), 4);
assertEquals(2, possibleCars.size());
possibleCars = service.getAvailableCars(LocalDate.of(2018,9,19), 7);
assertEquals(3, possibleCars.size());
}
@Test
public void testBookANonAvalaibleCar() throws NotPossibleCarRentalException {
CarRental carRental = service.book(myCar0,LocalDate.of(2017,9,11), 2);
assertFalse(carRental==null);
carRental = service.book(myCar0,LocalDate.of(2017,9,12), 2);
assertTrue(carRental==null);
}
@Test
public void testGetNotAvailableCars() throws NotPossibleCarRentalException {
service.book(myCar0,LocalDate.of(2017,9,11), 2);
List<Car> possibleCars = service.getAvailableCars(LocalDate.of(2017,9,11), 2);
assertEquals(2, possibleCars.size());
possibleCars = service.getAvailableCars(LocalDate.of(2017,9,12), 2);
assertEquals(2, possibleCars.size());
possibleCars = service.getAvailableCars(LocalDate.of(2017,9,13), 2);
assertEquals(3, possibleCars.size());
}
}

View File

@@ -0,0 +1,61 @@
package openClosedPrinciples.core;
import static org.junit.jupiter.api.Assertions.*;
import java.time.LocalDate;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import openClosedPrinciples.core.Car;
import openClosedPrinciples.core.CarRental;
import openClosedPrinciples.core.DateTools;
class CarRentalTest {
Car myCar = new Car("1111 AB 06",50);
CarRental carRental;
@BeforeEach
public void setUp() throws Exception {
myCar = new Car("1111 AB 06",50);
}
@Test
public void testCarRental() {
carRental = new CarRental(myCar, LocalDate.of(2018, 8, 30), 3);
assertEquals( myCar.getDayPrice()*3, carRental.getPrice());
}
@Test
public void testCarRentalAvailability() {
carRental = new CarRental(myCar, LocalDate.of(2018, 8, 30), 3);
LocalDate[] dates = DateTools.getDays(LocalDate.of(2018, 8, 30), 3);
assertEquals(3, dates.length );
dates = DateTools.getDays(LocalDate.of(2018, 8, 30), 1);
assertTrue(carRental.includeADate(dates),"date de début OK");
dates = DateTools.getDays(LocalDate.of(2018, 8, 29), 1);
assertFalse(carRental.includeADate(dates),"date à un jour avant");
dates = DateTools.getDays(LocalDate.of(2018, 9, 2), 1);
assertFalse(carRental.includeADate(dates),"date à un jour après");
dates = DateTools.getDays(LocalDate.of(2018, 8, 25), 10);
assertTrue(carRental.includeADate(dates),"date incluse après");
dates = DateTools.getDays(LocalDate.of(2018, 9, 1), 1);
assertTrue(carRental.includeADate(dates),"date incluse sur la fin");
dates = DateTools.getDays(LocalDate.of(2018, 8, 31), 10);
assertTrue(carRental.includeADate(dates),"date incluse sur la fin");
}
@Test
public void testGetPrice() {
carRental = new CarRental(myCar, LocalDate.of(2017, 8, 31), 3);
assertEquals(50,myCar.getDayPrice());
assertEquals(50*3,carRental.getPrice());
}
}

View File

@@ -0,0 +1,47 @@
package openClosedPrinciples.core;
import static org.junit.Assert.*;
import java.time.LocalDate;
import java.time.LocalTime;
import java.util.ArrayList;
import java.util.List;
import org.junit.Before;
import org.junit.Test;
import openClosedPrinciples.core.Flight;
import openClosedPrinciples.core.FlightService;
public class FlightServiceTest {
FlightService service ;
@Before
public void setUp() throws Exception {
ArrayList<Flight> list = new ArrayList<>();
list.add(new Flight("Belfort"));
list.add(new Flight("Nice"));
list.add(new Flight(100, LocalDate.of(2017, 12, 24), LocalTime.of(7, 45),"Nice", "Paris"));
list.add(new Flight(150, LocalDate.of(2017, 12, 24), LocalTime.of(9, 30), "Nice", "Paris"));
list.add(new Flight(150, LocalDate.of(2017, 12, 24), 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(LocalDate.of(2017, 12, 24));
assertEquals(3, flights.size());
}
@Test
public void testGetFlights() {
List<Flight> flights = service.getFlights(LocalDate.now(),"Nice","Paris");
assertEquals(1, flights.size());
flights = service.getFlights(LocalDate.of(2017, 12, 24),"Nice","Paris");
assertEquals(2, flights.size());
}
}

View File

@@ -0,0 +1,30 @@
package openClosedPrinciples.core;
import static org.junit.Assert.*;
import java.time.LocalDate;
import java.time.LocalTime;
import org.junit.Before;
import org.junit.Test;
import openClosedPrinciples.core.Flight;
public class FlightTest {
Flight f1 = new Flight(100, LocalDate.of(2017,11,11), LocalTime.of(7, 45),"Nice","Paris");
@Before
public void setUp() throws Exception {
}
@Test
public void testGetPrice() {
assertEquals(100,f1.getPrice(),0);
f1.setPrice(-1);
assertTrue(f1.getPrice()>=10);
assertTrue(f1.getPrice()<=1000);
}
}