Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * Commit:
- * -------------------------------------------------------------------
- * | Author | Commit | Message | Date |
- * | Oscar Nivor | 01ddbab | feat: new class | 45 seconds ago |
- * -------------------------------------------------------------------
- */
- /*
- * *******************************************************************************
- * ******************************** MAIN CODE ************************************
- * *******************************************************************************
- */
- import java.util.*;
- import com.rentalServiceRegistry.*;
- @Component
- public class Service {
- public final static String apiKey = "fez67fezyb223";
- private long timeToExecute = 0;
- @Autowired
- private RentalServiceRegistry rentalServiceRegistry;
- // Renvoie les noms des services de locations
- public ArrayList<String> ListRentalServices(String country, Integer mp, Integer limit, String city, Boolean airport, String typeVoiture) throws NoServiceFoundException {
- timeToExecute = System.currentTimeMillis();
- ArrayList<String> servicesToReturn = new ArrayList<>();
- rentalServiceRegistry.setAPIKey(apiKey);
- RentalServiceCriteria rentalServiceCriteria = new RentalServiceCriteria();
- rentalServiceCriteria.setCountry(country);
- rentalServiceCriteria.setCity(city);
- if (airport == true)
- rentalServiceCriteria.setAirport(true);
- ArrayList<RentalServices> services;
- try {
- services = rentalServiceRegistry.getRentalServices(rentalServiceCriteria);
- } catch (NoServiceFoundException e) {
- System.out.println("No service match the criteria");
- throw e;
- } catch (Exception e) {
- System.out.println(e.getMessage());
- throw e;
- }
- for (RentalService service : services) {
- if (service.getPrice() < mp ) {
- if (service.getCarType() == typeVoiture) {
- if (servicesToReturn.size() < limit)
- servicesToReturn.add(service.getName());
- }
- }
- }
- timeToExecute = System.currentTimeMillis() - timeToExecute;
- System.out.println("Time to execute : " + timeToExecute);
- // Return the services
- return servicesToReturn;
- }
- }
- /*
- * *******************************************************************************
- * ********************************** TESTS **************************************
- * *******************************************************************************
- */
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.Test;
- import java.util.ArrayList;
- public class ServiceTest {
- private final Service serviceToTest;
- @Test
- public void test1() {
- serviceToTest = new Service();
- ArrayList<String> services = serviceToTest.ListRentalServices("france", 500, 20, "nice", true, "economique");
- assertTrue(services.size() > 0);
- }
- @Test
- public void test2() {
- ArrayList<String> services = serviceToTest.ListRentalServices("france", 500, 20, "nice", false, "economique");
- assertTrue(services.size() > 0);
- }
- @Test
- public void test3() {
- ArrayList<String> services = serviceToTest.ListRentalServices("france", 500, 20, "nice", false, "mini");
- assertTrue(services.size() > 0);
- }
- @Test
- public void test4() {
- ArrayList<String> services = serviceToTest.ListRentalServices("allemagne", 500, 20, "nice", false, "mini");
- assertTrue(services.size() > 0);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement