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 static org.junit.jupiter.api.Assertions.assertEquals;
- import org.junit.jupiter.api.Test;
- /**
- *
- * @author morei
- */
- public class ReturnRentedBicycleControllerTest {
- 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");
- Location location = new Location(1, 1, 1);
- ParkingSlot pk = new ParkingSlot(1, 1, 1, 0);
- ParkingSlot pk2 = new ParkingSlot(2, 1, 1, 0);
- Park p = new Park(1, location, 10, 8, 10, 9);
- p.addSlot(pk);
- p.addSlot(pk2);
- Bicycle b = new Bicycle(1, 1, "y");
- 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);
- ParkingSlot pk = new ParkingSlot(1, 1, 1, 4);
- ParkingSlot pk2 = new ParkingSlot(2, 1, 1, 3);
- Park p = new Park(1, location, 10, 8, 10, 9);
- p.addSlot(pk);
- p.addSlot(pk2);
- Bicycle b = new Bicycle(1, 1, "y");
- 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);
- ParkingSlot pk = new ParkingSlot(1, 1, 1, 0);
- ParkingSlot pk2 = new ParkingSlot(2, 1, 1, 0);
- Park p = new Park(1, location, 10, 8, 10, 9);
- p.addSlot(pk);
- p.addSlot(pk2);
- Bicycle b = new Bicycle(1, 2, "y");
- 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");
- ParkingSlot parkingSlot = new ParkingSlot(1, 1, 1, 0);
- int idBicycle = 1;
- boolean expResult = true;
- boolean result = ReturnRentedBicycleController.updateParkingSlot(parkingSlot, idBicycle);
- assertEquals(expResult, result);
- }
- /**
- * 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(5, new Location(15, 12), 0, 0, 0, 0);
- boolean expResult = true;
- boolean result = ReturnRentedBicycleController.updateJourney(journey, finalDate, destinationPark);
- assertEquals(expResult, result);
- }
- /**
- * Test of updatePark method, of class ReturnRentedBicycleController.
- */
- @Test
- public void testUpdateParkEletric() {
- System.out.println("updatePark");
- Park destinationPark = new Park(4, new Location(11, 11), 0, 0, 0, 0);
- Park originPark = new Park(6, new Location(15, 12), 0, 0, 0, 0);
- Bicycle bicycle = new Bicycle(0, 1, "y");
- boolean expResult = true;
- boolean result = ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle);
- assertEquals(expResult, result);
- }
- @Test
- public void testUpdateParkNonEletric() {
- System.out.println("updatePark");
- Park destinationPark = new Park(4, new Location(11, 11), 0, 0, 0, 0);
- Park originPark = new Park(6, new Location(15, 12), 0, 0, 0, 0);
- Bicycle bicycle = new Bicycle(2, 1, "y");
- boolean expResult = true;
- boolean result = ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle);
- assertEquals(expResult, result);
- }
- /**
- * 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);
- }
- }
Add Comment
Please, Sign In to add comment