Advertisement
moreiramota

Untitled

Dec 20th, 2018
157
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 6.70 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.model;
  7.  
  8. import java.sql.Timestamp;
  9. import java.util.Date;
  10. import static org.junit.jupiter.api.Assertions.assertEquals;
  11. import org.junit.jupiter.api.Test;
  12.  
  13. /**
  14. *
  15. * @author morei
  16. */
  17. public class JourneyTest {
  18.  
  19. Journey instance = new Journey();
  20. Journey instance1 = new Journey("1161263@isep.ipp.pt", new Timestamp(10), 1);
  21. Journey instance2 = new Journey(1, "1161263@isep.ipp.pt", new Timestamp(10), 1, 0, new Date(10));
  22. Journey instance3 = new Journey("1161263@isep.ipp.pt", new Timestamp(10), 1, 0);
  23. Journey instance4 = new Journey("1161263@isep.ipp.pt", new Timestamp(10), 1, 0, new Date(10));
  24.  
  25. /**
  26. * Test of getId method, of class Journey.
  27. */
  28. @Test
  29. public void testGetIdReservation() {
  30. System.out.println("getIdReservation");
  31. int expResult = 1;
  32. int result = instance2.getIdReservation();
  33. assertEquals(expResult, result);
  34. }
  35.  
  36. /**
  37. * Test of getReservationDate method, of class Journey.
  38. */
  39. @Test
  40. public void testGetReservationDate() {
  41. System.out.println("getReservationDate");
  42. Timestamp expResult = new Timestamp(10);
  43. Timestamp result = instance2.getReservationDate();
  44. assertEquals(expResult, result);
  45. }
  46.  
  47. /**
  48. * Test of getEmail method, of class Journey.
  49. */
  50. @Test
  51. public void testGetEmail() {
  52. System.out.println("getEmail");
  53. String expResult = "1161263@isep.ipp.pt";
  54. String result = instance2.getEmail();
  55. assertEquals(expResult, result);
  56. }
  57.  
  58. /**
  59. * Test of getIdBicycle method, of class Journey.
  60. */
  61. @Test
  62. public void testGetIdBicycle() {
  63. System.out.println("getIdBicycle");
  64. int expResult = 1;
  65. int result = instance2.getIdBicycle();
  66. assertEquals(expResult, result);
  67. }
  68.  
  69. /**
  70. * Test of getPrice method, of class Journey.
  71. */
  72. @Test
  73. public void testGetPrice() {
  74. System.out.println("getPrice");
  75. int expResult = 0;
  76. int result = instance2.getPrice();
  77. assertEquals(expResult, result);
  78. }
  79.  
  80. /**
  81. * Test of getMonthYear method, of class Journey.
  82. */
  83. @Test
  84. public void testGetMonthYear() {
  85. System.out.println("getMonthYear");
  86. Date expResult = new Date(10);
  87. Date result = instance2.getMonthYear();
  88. assertEquals(expResult, result);
  89. }
  90.  
  91. /**
  92. * Test of setReservationDate method, of class Journey.
  93. */
  94. @Test
  95. public void testSetReservationDate() {
  96. System.out.println("setReservationDate");
  97. Timestamp reservationDate = new Timestamp(15);
  98. instance2.setReservationDate(reservationDate);
  99. assertEquals(reservationDate, instance2.getReservationDate());
  100. }
  101.  
  102. /**
  103. * Test of setEmail method, of class Journey.
  104. */
  105. @Test
  106. public void testSetEmail() {
  107. System.out.println("setEmail");
  108. String email = "1171409@isep.ipp.pt";
  109. instance2.setEmail(email);
  110. assertEquals(email, instance2.getEmail());
  111. }
  112.  
  113. /**
  114. * Test of setIdBicycle method, of class Journey.
  115. */
  116. @Test
  117. public void testSetIdBicycle() {
  118. System.out.println("setIdBicycle");
  119. int idBicycle = 2;
  120. instance2.setIdBicycle(idBicycle);
  121. assertEquals(idBicycle, instance2.getIdBicycle());
  122. }
  123.  
  124. /**
  125. * Test of setPrice method, of class Journey.
  126. */
  127. @Test
  128. public void testSetPrice() {
  129. System.out.println("setPrice");
  130. int price = 15;
  131. instance2.setPrice(price);
  132. assertEquals(price, instance2.getPrice());
  133. }
  134.  
  135. /**
  136. * Test of setMonthYear method, of class Journey.
  137. */
  138. @Test
  139. public void testSetMonthYear() {
  140. System.out.println("setMonthYear");
  141. Date monthYear = new Date(15);
  142. instance2.setMonthYear(monthYear);
  143. assertEquals(monthYear, instance2.getMonthYear());
  144. }
  145.  
  146. /**
  147. * Test of toString method, of class Journey.
  148. */
  149. @Test
  150. public void testToString() {
  151. System.out.println("toString");
  152. String expResult = "Reservation date 1970-01-01 01:00:00.01 Email 1161263@isep.ipp.pt Id bicycle 1 Price 0 Month Year Thu Jan 01 01:00:00 GMT 1970";
  153. String result = instance2.toString();
  154. assertEquals(expResult, result);
  155. }
  156.  
  157. /**
  158. * Test of equals method, of class Journey.
  159. */
  160. @Test
  161. public void testEquals() {
  162. System.out.println("equals");
  163. Object obj = null;
  164. boolean expResult = false;
  165. boolean result = instance.equals(obj);
  166. assertEquals(expResult, result);
  167. }
  168. /**
  169. * Test of equals method, of class Journey.
  170. */
  171. @Test
  172. public void testEqualsDiferentClass() {
  173. System.out.println("equals");
  174. Object obj = new Park(new Location(), 0, 0);
  175. boolean expResult = false;
  176. boolean result = instance.equals(obj);
  177. assertEquals(expResult, result);
  178. }
  179. /**
  180. * Test of equals method, of class Journey.
  181. */
  182. @Test
  183. public void testEquals1() {
  184. System.out.println("equals");
  185. Object obj = instance2;
  186. boolean expResult = true;
  187. boolean result = instance2.equals(obj);
  188. assertEquals(expResult, result);
  189. }
  190. /**
  191. * Test of equals method, of class Journey.
  192. */
  193. @Test
  194. public void testEquals2() {
  195. System.out.println("equals");
  196. Object obj = new Journey(2, "1161263@isep.ipp.pt", new Timestamp(10), 1, 0, new Date(10));
  197. boolean expResult = false;
  198. boolean result = instance2.equals(obj);
  199. assertEquals(expResult, result);
  200. }
  201. /**
  202. * Test of equals method, of class Journey.
  203. */
  204. @Test
  205. public void testEquals3() {
  206. System.out.println("equals");
  207. Object obj = new Journey(1, "1171709@isep.ipp.pt", new Timestamp(15), 2, 2, new Date(15));
  208. boolean expResult = true;
  209. boolean result = instance2.equals(obj);
  210. assertEquals(expResult, result);
  211. }
  212.  
  213. /**
  214. * Test of hashCode method, of class Journey.
  215. */
  216. @Test
  217. public void testHashCode() {
  218. System.out.println("hashCode");
  219. int expResult = hashCode(instance2);
  220. int result = instance2.hashCode();
  221. assertEquals(expResult, result);
  222. }
  223.  
  224. public int hashCode(Journey j) {
  225. int hash = 5;
  226. hash = 37 * hash + j.getIdReservation();
  227. return hash;
  228. }
  229. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement