Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- /*
- * To change this license header, choose License Headers in Project Properties.
- * To change this template file, choose Tools | Templates
- * and open the template in the editor.
- */
- package lapr.project.controller;
- import java.lang.reflect.Constructor;
- import java.lang.reflect.InvocationTargetException;
- import java.lang.reflect.Modifier;
- import lapr.project.model.Bicycle;
- import lapr.project.model.Journey;
- import lapr.project.model.Location;
- import lapr.project.model.Park;
- import lapr.project.model.ParkingSlot;
- import org.junit.After;
- import org.junit.AfterClass;
- import org.junit.Before;
- import org.junit.BeforeClass;
- import java.sql.Timestamp;
- import java.util.ArrayList;
- import java.util.List;
- import lapr.project.model.Route;
- import static org.junit.jupiter.api.Assertions.assertEquals;
- import static org.junit.jupiter.api.Assertions.assertFalse;
- import static org.junit.jupiter.api.Assertions.assertTrue;
- import org.junit.jupiter.api.Test;
- /**
- *
- * @author morei
- */
- public class ReturnRentedBicycleControllerTest {
- List<Route> routes = new ArrayList<>();
- Route r1 = new Route(1, 1, new Timestamp(1), 0);
- Route r2 = new Route(2, 2, new Timestamp(2), 2);
- Route r3 = new Route(3, 3, new Timestamp(3), 3);
- Route r4 = new Route(4, 4, new Timestamp(4), 4);
- public ReturnRentedBicycleControllerTest() {
- }
- @BeforeClass
- public static void setUpClass() {
- }
- @AfterClass
- public static void tearDownClass() {
- }
- @Before
- public void setUp() {
- }
- @After
- public void tearDown() {
- }
- @Test
- public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
- Constructor<ReturnRentedBicycleController> constructor = ReturnRentedBicycleController.class.getDeclaredConstructor();
- assertEquals(true, Modifier.isPrivate(constructor.getModifiers()));
- constructor.setAccessible(true);
- constructor.newInstance();
- }
- // /**
- // * Test of getParkingSlot method, of class ReturnRentedBicycleController.
- // */
- // @Test
- // public void testGetParkingSlot() {
- // System.out.println("getParkingSlot");
- // Bicycle b = new Bicycle( 1,2, "y", 13.6);
- // Bicycle b1 = new Bicycle( 2,2, "y", 12.6);
- // Location location = new Location(1, 1, 1);
- // ParkingSlot pk = new ParkingSlot(1, 1, 1, b1);
- // ParkingSlot pk2 = new ParkingSlot(2, 1, 1, b);
- // Park p = new Park(1, location, 10, 8, 10);
- // p.addSlot(pk);
- // p.addSlot(pk2);
- // ParkingSlot expResult = pk;
- // ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
- // assertEquals(expResult, result);
- // }
- //
- // @Test
- // public void testGetParkingFull() {
- // System.out.println("getParkingSlot");
- // Location location = new Location(1, 1, 1);
- // Bicycle b = new Bicycle(2, "y", 15.6);
- // ParkingSlot pk = new ParkingSlot(1, 1, 1, b);
- // ParkingSlot pk2 = new ParkingSlot(2, 1, 1, b);
- // Park p = new Park(1, location, 10, 8, 10);
- // p.addSlot(pk);
- // p.addSlot(pk2);
- // ParkingSlot expResult = null;
- // ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
- // assertEquals(expResult, result);
- // }
- //
- // @Test
- // public void testGetParkingSlotNull() {
- // System.out.println("getParkingSlot");
- // Location location = new Location(1, 1, 1);
- // Bicycle b = new Bicycle(1, 2, "y", 15.6);
- // ParkingSlot pk = new ParkingSlot(1, 1, 1, b);
- // ParkingSlot pk2 = new ParkingSlot(2, 1, 1, b);
- // Park p = new Park(1, location, 10, 8, 10);
- // p.addSlot(pk);
- // p.addSlot(pk2);
- //
- // ParkingSlot expResult = null;
- // ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
- // assertEquals(expResult, result);
- // }
- //
- // /**
- // * Test of returnRentendBicycle method, of class
- // * ReturnRentedBicycleController.
- // */
- // @Test
- // public void testReturnRentendBicycle() {
- // System.out.println("returnRentendBicycle");
- // String email = "";
- // Timestamp inicialDate = null;
- // Timestamp finalDate = null;
- // Park destinationPark = null;
- // boolean expResult = false;
- // boolean result = ReturnRentedBicycleController.returnRentendBicycle(email, inicialDate, finalDate, destinationPark);
- // assertEquals(expResult, result);
- // }
- //
- // /**
- // * Test of updateParkingSlot method, of class ReturnRentedBicycleController.
- // */
- // @Test
- // public void testUpdateParkingSlot() {
- // System.out.println("updateParkingSlot");
- // Bicycle b = new Bicycle(1, 2, "y", 15.6);
- // ParkingSlot parkingSlot = new ParkingSlot(1, 1, 1, null);
- // boolean expResult = true;
- // boolean result = ReturnRentedBicycleController.updateParkingSlot(parkingSlot, b);
- // assertEquals(expResult, result);
- // assertTrue(parkingSlot.getBicycle().equals(b));
- // }
- //
- // /**
- // * Test of updateJourney method, of class ReturnRentedBicycleController.
- // */
- // @Test
- // public void testUpdateJourney() {
- // System.out.println("updateJourney");
- // Journey journey = new Journey("adminbikeshare@isep.ipp.pt", new Timestamp(10), new Timestamp(18), 1, new Park(4, new Location(11, 11, 0), 0, 0, 0), new Park(5, new Location(12, 12, 0), 0, 0, 0));
- // Timestamp finalDate = new Timestamp(20);
- // Park destinationPark = new Park(4, new Location(15, 12, 0), 0, 0, 0);
- // boolean expResult = true;
- // boolean result = ReturnRentedBicycleController.updateJourney(journey, finalDate, destinationPark);
- // assertEquals(expResult, result);
- // assertTrue(finalDate.equals(journey.getFinalDate()));
- // assertEquals(destinationPark, journey.getDestinationPark());
- // }
- //
- // @Test
- // public void testUpdatePark() {
- // System.out.println("updatePark");
- // Park destinationPark = new Park(4, new Location(11, 11, 0), 1, 1, 1);
- // Park originPark = new Park(6, new Location(15, 12, 0), 1, 0, 0);
- // destinationPark.addSlot(new ParkingSlot(4, 2));
- // originPark.addSlot(new ParkingSlot(6, 2));
- // Bicycle bicycle = new Bicycle(1, 2, "y", 15.6);
- // assertTrue(originPark.addBicycle(bicycle)!=null);
- // boolean expResult = true;
- // boolean result = ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle);
- //
- // assertEquals(expResult, result);
- // assertTrue(originPark.removeBicycle(bicycle)==null);
- // assertTrue(destinationPark.removeBicycle(bicycle)!=null);
- // assertTrue(destinationPark.addBicycle(bicycle)!=null);
- //
- // assertFalse(ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle));
- // assertTrue(originPark.removeBicycle(bicycle)==null);
- // assertTrue(destinationPark.removeBicycle(bicycle)!=null);
- // assertTrue(destinationPark.addBicycle(new Bicycle(1, 2, "y", 15.6))!=null);
- // assertTrue(originPark.addBicycle(bicycle)!=null);
- //
- // assertFalse(ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle));
- // assertTrue(originPark.removeBicycle(bicycle)==null);
- // assertTrue(destinationPark.removeBicycle(bicycle)==null);
- // assertTrue(destinationPark.removeBicycle(new Bicycle(1, 2, "y", 15.6))!=null);
- //
- // assertFalse(ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle));
- //
- // assertTrue(originPark.removeBicycle(bicycle)==null);
- // assertTrue(destinationPark.removeBicycle(bicycle)!=null);
- //
- // }
- //
- // /**
- // * Test of getBicycleById method, of class ReturnRentedBicycleController.
- // */
- // @Test
- // public void testGetBicycleById() {
- // System.out.println("getBicycleById");
- // Journey journey = null;
- // Bicycle expResult = null;
- // Bicycle result = ReturnRentedBicycleController.getBicycleById(journey);
- // assertEquals(expResult, result);
- // }
- //
- // /**
- // * Test of getJorney method, of class ReturnRentedBicycleController.
- // */
- // @Test
- // public void testGetJorney() {
- // System.out.println("getJorney");
- // String email = "";
- // Timestamp inicialDate = null;
- // Journey expResult = null;
- // Journey result = ReturnRentedBicycleController.getJorney(email, inicialDate);
- // assertEquals(expResult, result);
- // }
- //
- // /**
- // * Test of updateBicycle method, of class ReturnRentedBicycleController.
- // */
- // @Test
- // public void testUpdateBicycle() {
- // System.out.println("updateBicycle");
- // Bicycle bicycle = null;
- // boolean expResult = false;
- // boolean result = ReturnRentedBicycleController.updateBicycle(bicycle);
- // assertEquals(expResult, result);
- // }
- /**
- * Test of getPrice method, of class ReturnRentedBicycleController.
- */
- @Test
- public void testGetPrice() {
- System.out.println("getPrice");
- r1.setVisitDate(new Timestamp(0,0,0,1,0,0,0));
- r4.setVisitDate(new Timestamp(0,0,0,2,0,0,0));
- int expResult = 3;
- int result = ReturnRentedBicycleController.getPrice(r1, r2);
- assertEquals(expResult, result);
- }
- @Test
- public void testGetPriceZero() {
- System.out.println("getPrice");
- r1.setVisitDate(new Timestamp(0,0,0,2,0,0,0));
- r4.setVisitDate(new Timestamp(0,0,0,2,40,0,0));
- int expResult = 0;
- int result = ReturnRentedBicycleController.getPrice(r1, r2);
- assertEquals(expResult, result);
- }
- @Test
- public void testGetPriceMinute() {
- System.out.println("getPrice");
- r1.setVisitDate(new Timestamp(0,0,0,1,0,0,0));
- r4.setVisitDate(new Timestamp(0,0,0,2,29,0,0));
- int expResult = 3;
- int result = ReturnRentedBicycleController.getPrice(r1, r2);
- assertEquals(expResult, result);
- }
- /**
- * Test of getDiferencaTempo method, of class ReturnRentedBicycleController.
- */
- @Test
- public void testGetDiferencaTempo() {
- System.out.println("getDiferencaTempo");
- Timestamp visitDateI = new Timestamp(0,0,0,1,0,0,0);
- Timestamp visitDateF = new Timestamp(0,0,0,2,0,0,0);
- int expResult = 1;
- int result = ReturnRentedBicycleController.getDiferencaTempo(visitDateI, visitDateF);
- assertEquals(expResult, result);
- }
- @Test
- public void testGetDiferencaTempo2() {
- System.out.println("getDiferencaTempo");
- Timestamp visitDateI = new Timestamp(0,0,0,1,0,0,0);
- Timestamp visitDateF2 = new Timestamp(0,0,0,2,1,0,0);
- int expResult = 1;
- int result = ReturnRentedBicycleController.getDiferencaTempo(visitDateI, visitDateF2);
- assertEquals(expResult, result);
- }
- /**
- * Test of getDestinationRoute method, of class ReturnRentedBicycleController.
- */
- @Test
- public void testGetDestinationRoute() {
- System.out.println("getDestinationRoute");
- routes.add(r1);
- routes.add(r2);
- routes.add(r3);
- routes.add(r4);
- Route result = ReturnRentedBicycleController.getDestinationRoute(routes);
- assertEquals(r4, result);
- }
- /**
- * Test of getOriginRoute method, of class ReturnRentedBicycleController.
- */
- @Test
- public void testGetOriginRoute() {
- System.out.println("getOriginRoute");
- routes.add(r1);
- routes.add(r2);
- routes.add(r3);
- routes.add(r4);
- Route result = ReturnRentedBicycleController.getOriginRoute(routes);
- assertEquals(r1, result);
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement