Advertisement
moreiramota

Untitled

Dec 21st, 2018
113
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 11.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 java.util.ArrayList;
  22. import java.util.List;
  23. import lapr.project.model.Route;
  24. import static org.junit.jupiter.api.Assertions.assertEquals;
  25. import static org.junit.jupiter.api.Assertions.assertFalse;
  26. import static org.junit.jupiter.api.Assertions.assertTrue;
  27. import org.junit.jupiter.api.Test;
  28.  
  29. /**
  30. *
  31. * @author morei
  32. */
  33. public class ReturnRentedBicycleControllerTest {
  34.  
  35. List<Route> routes = new ArrayList<>();
  36. Route r1 = new Route(1, 1, new Timestamp(1), 0);
  37. Route r2 = new Route(2, 2, new Timestamp(2), 2);
  38. Route r3 = new Route(3, 3, new Timestamp(3), 3);
  39. Route r4 = new Route(4, 4, new Timestamp(4), 4);
  40.  
  41. public ReturnRentedBicycleControllerTest() {
  42. }
  43.  
  44. @BeforeClass
  45. public static void setUpClass() {
  46. }
  47.  
  48. @AfterClass
  49. public static void tearDownClass() {
  50. }
  51.  
  52. @Before
  53. public void setUp() {
  54. }
  55.  
  56. @After
  57. public void tearDown() {
  58. }
  59.  
  60. @Test
  61. public void testConstructorIsPrivate() throws NoSuchMethodException, IllegalAccessException, InvocationTargetException, InstantiationException {
  62. Constructor<ReturnRentedBicycleController> constructor = ReturnRentedBicycleController.class.getDeclaredConstructor();
  63. assertEquals(true, Modifier.isPrivate(constructor.getModifiers()));
  64. constructor.setAccessible(true);
  65. constructor.newInstance();
  66. }
  67.  
  68. // /**
  69. // * Test of getParkingSlot method, of class ReturnRentedBicycleController.
  70. // */
  71. // @Test
  72. // public void testGetParkingSlot() {
  73. // System.out.println("getParkingSlot");
  74. // Bicycle b = new Bicycle( 1,2, "y", 13.6);
  75. // Bicycle b1 = new Bicycle( 2,2, "y", 12.6);
  76. // Location location = new Location(1, 1, 1);
  77. // ParkingSlot pk = new ParkingSlot(1, 1, 1, b1);
  78. // ParkingSlot pk2 = new ParkingSlot(2, 1, 1, b);
  79. // Park p = new Park(1, location, 10, 8, 10);
  80. // p.addSlot(pk);
  81. // p.addSlot(pk2);
  82. // ParkingSlot expResult = pk;
  83. // ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
  84. // assertEquals(expResult, result);
  85. // }
  86. //
  87. // @Test
  88. // public void testGetParkingFull() {
  89. // System.out.println("getParkingSlot");
  90. // Location location = new Location(1, 1, 1);
  91. // Bicycle b = new Bicycle(2, "y", 15.6);
  92. // ParkingSlot pk = new ParkingSlot(1, 1, 1, b);
  93. // ParkingSlot pk2 = new ParkingSlot(2, 1, 1, b);
  94. // Park p = new Park(1, location, 10, 8, 10);
  95. // p.addSlot(pk);
  96. // p.addSlot(pk2);
  97. // ParkingSlot expResult = null;
  98. // ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
  99. // assertEquals(expResult, result);
  100. // }
  101. //
  102. // @Test
  103. // public void testGetParkingSlotNull() {
  104. // System.out.println("getParkingSlot");
  105. // Location location = new Location(1, 1, 1);
  106. // Bicycle b = new Bicycle(1, 2, "y", 15.6);
  107. // ParkingSlot pk = new ParkingSlot(1, 1, 1, b);
  108. // ParkingSlot pk2 = new ParkingSlot(2, 1, 1, b);
  109. // Park p = new Park(1, location, 10, 8, 10);
  110. // p.addSlot(pk);
  111. // p.addSlot(pk2);
  112. //
  113. // ParkingSlot expResult = null;
  114. // ParkingSlot result = ReturnRentedBicycleController.getParkingSlot(p, b);
  115. // assertEquals(expResult, result);
  116. // }
  117. //
  118. // /**
  119. // * Test of returnRentendBicycle method, of class
  120. // * ReturnRentedBicycleController.
  121. // */
  122. // @Test
  123. // public void testReturnRentendBicycle() {
  124. // System.out.println("returnRentendBicycle");
  125. // String email = "";
  126. // Timestamp inicialDate = null;
  127. // Timestamp finalDate = null;
  128. // Park destinationPark = null;
  129. // boolean expResult = false;
  130. // boolean result = ReturnRentedBicycleController.returnRentendBicycle(email, inicialDate, finalDate, destinationPark);
  131. // assertEquals(expResult, result);
  132. // }
  133. //
  134. // /**
  135. // * Test of updateParkingSlot method, of class ReturnRentedBicycleController.
  136. // */
  137. // @Test
  138. // public void testUpdateParkingSlot() {
  139. // System.out.println("updateParkingSlot");
  140. // Bicycle b = new Bicycle(1, 2, "y", 15.6);
  141. // ParkingSlot parkingSlot = new ParkingSlot(1, 1, 1, null);
  142. // boolean expResult = true;
  143. // boolean result = ReturnRentedBicycleController.updateParkingSlot(parkingSlot, b);
  144. // assertEquals(expResult, result);
  145. // assertTrue(parkingSlot.getBicycle().equals(b));
  146. // }
  147. //
  148. // /**
  149. // * Test of updateJourney method, of class ReturnRentedBicycleController.
  150. // */
  151. // @Test
  152. // public void testUpdateJourney() {
  153. // System.out.println("updateJourney");
  154. // 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));
  155. // Timestamp finalDate = new Timestamp(20);
  156. // Park destinationPark = new Park(4, new Location(15, 12, 0), 0, 0, 0);
  157. // boolean expResult = true;
  158. // boolean result = ReturnRentedBicycleController.updateJourney(journey, finalDate, destinationPark);
  159. // assertEquals(expResult, result);
  160. // assertTrue(finalDate.equals(journey.getFinalDate()));
  161. // assertEquals(destinationPark, journey.getDestinationPark());
  162. // }
  163. //
  164. // @Test
  165. // public void testUpdatePark() {
  166. // System.out.println("updatePark");
  167. // Park destinationPark = new Park(4, new Location(11, 11, 0), 1, 1, 1);
  168. // Park originPark = new Park(6, new Location(15, 12, 0), 1, 0, 0);
  169. // destinationPark.addSlot(new ParkingSlot(4, 2));
  170. // originPark.addSlot(new ParkingSlot(6, 2));
  171. // Bicycle bicycle = new Bicycle(1, 2, "y", 15.6);
  172. // assertTrue(originPark.addBicycle(bicycle)!=null);
  173. // boolean expResult = true;
  174. // boolean result = ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle);
  175. //
  176. // assertEquals(expResult, result);
  177. // assertTrue(originPark.removeBicycle(bicycle)==null);
  178. // assertTrue(destinationPark.removeBicycle(bicycle)!=null);
  179. // assertTrue(destinationPark.addBicycle(bicycle)!=null);
  180. //
  181. // assertFalse(ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle));
  182. // assertTrue(originPark.removeBicycle(bicycle)==null);
  183. // assertTrue(destinationPark.removeBicycle(bicycle)!=null);
  184. // assertTrue(destinationPark.addBicycle(new Bicycle(1, 2, "y", 15.6))!=null);
  185. // assertTrue(originPark.addBicycle(bicycle)!=null);
  186. //
  187. // assertFalse(ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle));
  188. // assertTrue(originPark.removeBicycle(bicycle)==null);
  189. // assertTrue(destinationPark.removeBicycle(bicycle)==null);
  190. // assertTrue(destinationPark.removeBicycle(new Bicycle(1, 2, "y", 15.6))!=null);
  191. //
  192. // assertFalse(ReturnRentedBicycleController.updatePark(destinationPark, originPark, bicycle));
  193. //
  194. // assertTrue(originPark.removeBicycle(bicycle)==null);
  195. // assertTrue(destinationPark.removeBicycle(bicycle)!=null);
  196. //
  197. // }
  198. //
  199. // /**
  200. // * Test of getBicycleById method, of class ReturnRentedBicycleController.
  201. // */
  202. // @Test
  203. // public void testGetBicycleById() {
  204. // System.out.println("getBicycleById");
  205. // Journey journey = null;
  206. // Bicycle expResult = null;
  207. // Bicycle result = ReturnRentedBicycleController.getBicycleById(journey);
  208. // assertEquals(expResult, result);
  209. // }
  210. //
  211. // /**
  212. // * Test of getJorney method, of class ReturnRentedBicycleController.
  213. // */
  214. // @Test
  215. // public void testGetJorney() {
  216. // System.out.println("getJorney");
  217. // String email = "";
  218. // Timestamp inicialDate = null;
  219. // Journey expResult = null;
  220. // Journey result = ReturnRentedBicycleController.getJorney(email, inicialDate);
  221. // assertEquals(expResult, result);
  222. // }
  223. //
  224. // /**
  225. // * Test of updateBicycle method, of class ReturnRentedBicycleController.
  226. // */
  227. // @Test
  228. // public void testUpdateBicycle() {
  229. // System.out.println("updateBicycle");
  230. // Bicycle bicycle = null;
  231. // boolean expResult = false;
  232. // boolean result = ReturnRentedBicycleController.updateBicycle(bicycle);
  233. // assertEquals(expResult, result);
  234. // }
  235.  
  236. /**
  237. * Test of getPrice method, of class ReturnRentedBicycleController.
  238. */
  239. @Test
  240. public void testGetPrice() {
  241. System.out.println("getPrice");
  242. r1.setVisitDate(new Timestamp(0,0,0,1,0,0,0));
  243. r4.setVisitDate(new Timestamp(0,0,0,2,0,0,0));
  244. int expResult = 3;
  245. int result = ReturnRentedBicycleController.getPrice(r1, r2);
  246. assertEquals(expResult, result);
  247. }
  248.  
  249. @Test
  250. public void testGetPriceZero() {
  251. System.out.println("getPrice");
  252. r1.setVisitDate(new Timestamp(0,0,0,2,0,0,0));
  253. r4.setVisitDate(new Timestamp(0,0,0,2,40,0,0));
  254. int expResult = 0;
  255. int result = ReturnRentedBicycleController.getPrice(r1, r2);
  256. assertEquals(expResult, result);
  257. }
  258.  
  259. @Test
  260. public void testGetPriceMinute() {
  261. System.out.println("getPrice");
  262. r1.setVisitDate(new Timestamp(0,0,0,1,0,0,0));
  263. r4.setVisitDate(new Timestamp(0,0,0,2,29,0,0));
  264. int expResult = 3;
  265. int result = ReturnRentedBicycleController.getPrice(r1, r2);
  266. assertEquals(expResult, result);
  267. }
  268.  
  269. /**
  270. * Test of getDiferencaTempo method, of class ReturnRentedBicycleController.
  271. */
  272. @Test
  273. public void testGetDiferencaTempo() {
  274. System.out.println("getDiferencaTempo");
  275. Timestamp visitDateI = new Timestamp(0,0,0,1,0,0,0);
  276. Timestamp visitDateF = new Timestamp(0,0,0,2,0,0,0);
  277. int expResult = 1;
  278. int result = ReturnRentedBicycleController.getDiferencaTempo(visitDateI, visitDateF);
  279. assertEquals(expResult, result);
  280. }
  281.  
  282. @Test
  283. public void testGetDiferencaTempo2() {
  284. System.out.println("getDiferencaTempo");
  285. Timestamp visitDateI = new Timestamp(0,0,0,1,0,0,0);
  286. Timestamp visitDateF2 = new Timestamp(0,0,0,2,1,0,0);
  287. int expResult = 1;
  288. int result = ReturnRentedBicycleController.getDiferencaTempo(visitDateI, visitDateF2);
  289. assertEquals(expResult, result);
  290. }
  291.  
  292. /**
  293. * Test of getDestinationRoute method, of class ReturnRentedBicycleController.
  294. */
  295. @Test
  296. public void testGetDestinationRoute() {
  297. System.out.println("getDestinationRoute");
  298. routes.add(r1);
  299. routes.add(r2);
  300. routes.add(r3);
  301. routes.add(r4);
  302. Route result = ReturnRentedBicycleController.getDestinationRoute(routes);
  303. assertEquals(r4, result);
  304. }
  305.  
  306. /**
  307. * Test of getOriginRoute method, of class ReturnRentedBicycleController.
  308. */
  309. @Test
  310. public void testGetOriginRoute() {
  311. System.out.println("getOriginRoute");
  312. routes.add(r1);
  313. routes.add(r2);
  314. routes.add(r3);
  315. routes.add(r4);
  316. Route result = ReturnRentedBicycleController.getOriginRoute(routes);
  317. assertEquals(r1, result);
  318. }
  319. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement