moreiramota

Untitled

Dec 16th, 2018
60
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.97 KB | None | 0 0
  1. /*
  2. * To change this license header, choose License Headers in Project Properties.
  3. * To change this template file, choose Tools | Templates
  4. * and open the template in the editor.
  5. */
  6. package lapr.project.controller;
  7.  
  8. import java.lang.reflect.Constructor;
  9. import java.lang.reflect.InvocationTargetException;
  10. import java.lang.reflect.Modifier;
  11. import lapr.project.model.Bicycle;
  12. import lapr.project.model.Journey;
  13. import lapr.project.model.Location;
  14. import lapr.project.model.Park;
  15. import lapr.project.model.ParkingSlot;
  16. import org.junit.After;
  17. import org.junit.AfterClass;
  18. import org.junit.Before;
  19. import org.junit.BeforeClass;
  20. import java.sql.Timestamp;
  21. import static org.junit.jupiter.api.Assertions.assertEquals;
  22. import org.junit.jupiter.api.Test;
  23.  
  24. /**
  25. *
  26. * @author morei
  27. */
  28. public class ReturnRentedBicycleControllerTest {
  29.  
  30. public ReturnRentedBicycleControllerTest() {
  31. }
  32.  
  33. @BeforeClass
  34. public static void setUpClass() {
  35. }
  36.  
  37. @AfterClass
  38. public static void tearDownClass() {
  39. }
  40.  
  41. @Before
  42. public void setUp() {
  43. }
  44.  
  45. @After
  46. public void tearDown() {
  47. }
  48.  
  49. @Test
  50. public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
  51. Constructor<ReturnRentedBicycleController> constructor = ReturnRentedBicycleController.class.getDeclaredConstructor();
  52. assertEquals(true, Modifier.isPrivate(constructor.getModifiers()));
  53. constructor.setAccessible(true);
  54. constructor.newInstance();
  55. }
  56.  
  57. /**
  58. * Test of getParkingSlot method, of class ReturnRentedBicycleController.
  59. */
  60. @Test
  61. public void testGetParkingSlot() {
  62. System.out.println("getParkingSlot");
  63. Location location = new Location(1, 1, 1);
  64. ParkingSlot pk = new ParkingSlot(1, 1, 1, 0);
  65. ParkingSlot pk2 = new ParkingSlot(2, 1, 1, 0);
  66. Park p = new Park(1, location, 10, 8, 10, 9);
  67. p.addSlot(pk);
  68. p.addSlot(pk2);
  69. Bicycle b = new Bicycle(1, 1, "y");
  70. ParkingSlot expResult = pk;
  71. ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
  72. assertEquals(expResult, result);
  73. }
  74.  
  75. @Test
  76. public void testGetParkingFull() {
  77. System.out.println("getParkingSlot");
  78. Location location = new Location(1, 1, 1);
  79. ParkingSlot pk = new ParkingSlot(1, 1, 1, 4);
  80. ParkingSlot pk2 = new ParkingSlot(2, 1, 1, 3);
  81. Park p = new Park(1, location, 10, 8, 10, 9);
  82. p.addSlot(pk);
  83. p.addSlot(pk2);
  84. Bicycle b = new Bicycle(1, 1, "y");
  85. ParkingSlot expResult = null;
  86. ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
  87. assertEquals(expResult, result);
  88. }
  89.  
  90. @Test
  91. public void testGetParkingSlotNull() {
  92. System.out.println("getParkingSlot");
  93. Location location = new Location(1, 1, 1);
  94. ParkingSlot pk = new ParkingSlot(1, 1, 1, 0);
  95. ParkingSlot pk2 = new ParkingSlot(2, 1, 1, 0);
  96. Park p = new Park(1, location, 10, 8, 10, 9);
  97. p.addSlot(pk);
  98. p.addSlot(pk2);
  99. Bicycle b = new Bicycle(1, 2, "y");
  100. ParkingSlot expResult = null;
  101. ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
  102. assertEquals(expResult, result);
  103. }
  104.  
  105. /**
  106. * Test of returnRentendBicycle method, of class
  107. * ReturnRentedBicycleController.
  108. */
  109. //@Test
  110. public void testReturnRentendBicycle() {
  111. System.out.println("returnRentendBicycle");
  112. String email = "";
  113. Timestamp inicialDate = null;
  114. Timestamp finalDate = null;
  115. Park destinationPark = null;
  116. boolean expResult = false;
  117. boolean result = ReturnRentedBicycleController.returnRentendBicycle(email, inicialDate, finalDate, destinationPark);
  118. assertEquals(expResult, result);
  119. }
  120.  
  121. /**
  122. * Test of updateParkingSlot method, of class ReturnRentedBicycleController.
  123. */
  124. @Test
  125. public void testUpdateParkingSlot() {
  126. System.out.println("updateParkingSlot");
  127. ParkingSlot parkingSlot = new ParkingSlot(1, 1, 1, 0);
  128. int idBicycle = 1;
  129. boolean expResult = true;
  130. boolean result = ReturnRentedBicycleController.updateParkingSlot(parkingSlot, idBicycle);
  131. assertEquals(expResult, result);
  132. }
  133.  
  134. /**
  135. * Test of updateJourney method, of class ReturnRentedBicycleController.
  136. */
  137. @Test
  138. public void testUpdateJourney() {
  139. System.out.println("updateJourney");
  140. 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));
  141. Timestamp finalDate = new Timestamp(20);
  142. Park destinationPark = new Park(5, new Location(15, 12), 0, 0, 0, 0);
  143. boolean expResult = true;
  144. boolean result = ReturnRentedBicycleController.updateJourney(journey, finalDate, destinationPark);
  145. assertEquals(expResult, result);
  146. }
  147.  
  148. /**
  149. * Test of updatePark method, of class ReturnRentedBicycleController.
  150. */
  151. @Test
  152. public void testUpdateParkEletric() {
  153. System.out.println("updatePark");
  154. Park destinationPark = new Park(4, new Location(11, 11), 0, 0, 0, 0);
  155. Park originPark = new Park(6, new Location(15, 12), 0, 0, 0, 0);
  156. Bicycle bicycle = new Bicycle(0, 1, "y");
  157. boolean expResult = true;
  158. boolean result = ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle);
  159. assertEquals(expResult, result);
  160. }
  161.  
  162. @Test
  163. public void testUpdateParkNonEletric() {
  164. System.out.println("updatePark");
  165. Park destinationPark = new Park(4, new Location(11, 11), 0, 0, 0, 0);
  166. Park originPark = new Park(6, new Location(15, 12), 0, 0, 0, 0);
  167. Bicycle bicycle = new Bicycle(2, 1, "y");
  168. boolean expResult = true;
  169. boolean result = ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle);
  170. assertEquals(expResult, result);
  171. }
  172.  
  173. /**
  174. * Test of getBicycleById method, of class ReturnRentedBicycleController.
  175. */
  176. //@Test
  177. public void testGetBicycleById() {
  178. System.out.println("getBicycleById");
  179. Journey journey = null;
  180. Bicycle expResult = null;
  181. Bicycle result = ReturnRentedBicycleController.getBicycleById(journey);
  182. assertEquals(expResult, result);
  183. }
  184.  
  185. /**
  186. * Test of getJorney method, of class ReturnRentedBicycleController.
  187. */
  188. //@Test
  189. public void testGetJorney() {
  190. System.out.println("getJorney");
  191. String email = "";
  192. Timestamp inicialDate = null;
  193. Journey expResult = null;
  194. Journey result = ReturnRentedBicycleController.getJorney(email, inicialDate);
  195. assertEquals(expResult, result);
  196. }
  197.  
  198. }
Add Comment
Please, Sign In to add comment