Advertisement
Guest User

Application Test

a guest
Jun 16th, 2017
516
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 15.52 KB | None | 0 0
  1. package lapr.project.model;
  2.  
  3. import lapr.project.utils.StringUtil;
  4. import org.junit.Test;
  5. //import org.w3c.dom.Document;
  6. //import org.w3c.dom.Element;
  7. //import org.w3c.dom.Node;
  8. //
  9. //import javax.xml.parsers.DocumentBuilder;
  10. //import javax.xml.parsers.DocumentBuilderFactory;
  11. import java.util.ArrayList;
  12. import java.util.List;
  13. import org.junit.After;
  14. import org.junit.AfterClass;
  15.  
  16. import static org.junit.Assert.*;
  17. import org.junit.Before;
  18. import org.junit.BeforeClass;
  19.  
  20. public class ApplicationTest {
  21.  
  22. private int boothArea = 10;
  23. private int invitesQuantity = 5;
  24. private EventCenter ec;
  25.  
  26. User u1 = new User ("Rui", "Default", "rui@gmail.com", "Ab-12");
  27. User u2 = new User ("David", "Default", "dabide@gmail.com", "Ab-12");
  28. ParticipantRepresentant userMaker1 = new ParticipantRepresentant(u1);
  29. ParticipantRepresentant userMaker2 = new ParticipantRepresentant(u2);
  30. /**
  31. * StringUtil variable to access utils for Strings.
  32. */
  33. private StringUtil stringUtil = new StringUtil();
  34.  
  35. @BeforeClass
  36. public static void setUpClass() throws Exception {
  37. }
  38.  
  39. @AfterClass
  40. public static void tearDownClass() throws Exception {
  41. }
  42.  
  43. @Before
  44. public void setUp() throws Exception {
  45. }
  46.  
  47. @After
  48. public void tearDown() throws Exception {
  49. }
  50.  
  51. /**
  52. * Get OS independent line break.
  53. *
  54. * @return OS independent line break "%n".
  55. */
  56. private String getLineBreak() {
  57. if (stringUtil == null) {
  58. stringUtil = new StringUtil();
  59. }
  60. return stringUtil.getLineBreak();
  61. }
  62.  
  63. @Test
  64. public void ensureAddKeywordIsWorking() throws Exception {
  65. List<Keyword> expectedKeywordList = new ArrayList<>();
  66. expectedKeywordList.add(new Keyword("Doors"));
  67.  
  68. Application candidatura = new Application("MyCandidatura", new ArrayList<>());
  69. candidatura.addKeyword(new Keyword("Doors"));
  70.  
  71. List<Keyword> resultList = candidatura.getKeywordList();
  72.  
  73. assertArrayEquals(expectedKeywordList.toArray(), resultList.toArray());
  74.  
  75. }
  76.  
  77. // @Test
  78. // public void ensureXMLElementExportToStringIsValid() throws Exception
  79. // {
  80. // String expected = "<application>" + getLineBreak()
  81. // + "<description>MyApplication</description>" + getLineBreak()
  82. // + "<keywords>" + getLineBreak()
  83. // + "<keyword>" + getLineBreak()
  84. // + "<value>Doors</value>" + getLineBreak()
  85. // + "</keyword>" + getLineBreak()
  86. // + "<keyword>" + getLineBreak()
  87. // + "<value>Windows</value>" + getLineBreak()
  88. // + "</keyword>" + getLineBreak()
  89. // + "</keywords>" + getLineBreak()
  90. // + "</application>" + getLineBreak();
  91. //
  92. // List<Keyword> keywordList = new ArrayList<>();
  93. // keywordList.add(new Keyword("Doors"));
  94. // keywordList.add(new Keyword("Windows"));
  95. // Application application = new Application("MyApplication", keywordList);
  96. // String result = application.exportContentToString();
  97. // assertEquals(expected, result);
  98. // }
  99. //
  100. // @Test
  101. // public void ensureImportFromXMLElementNodeIsValid() throws Exception
  102. // {
  103. // List<Keyword> keywordList = new ArrayList<>();
  104. // keywordList.add(new Keyword("Doors"));
  105. // keywordList.add(new Keyword("Windows"));
  106. //
  107. // Application expected = new Application("MyApplication", keywordList);
  108. //
  109. // DocumentBuilderFactory factory
  110. // = DocumentBuilderFactory.newInstance();
  111. //
  112. // //Create document builder
  113. // DocumentBuilder builder = factory.newDocumentBuilder();
  114. //
  115. // //Obtain a new document
  116. // Document document = builder.newDocument();
  117. //
  118. // //Create root element
  119. // Element elementCandidatura = document.createElement("application");
  120. //
  121. // //Create a sub-element
  122. // Element elementDescription = document.createElement("description");
  123. //
  124. // //Set the sub-element value
  125. // elementDescription.setTextContent("MyApplication");
  126. //
  127. // //Add sub-element to root element
  128. // elementCandidatura.appendChild(elementDescription);
  129. //
  130. // //Create a sub-element
  131. // Element elementKeywords = document.createElement("keywords");
  132. //
  133. // //iterate over keywords
  134. // for (Keyword keyword : keywordList)
  135. // {
  136. // Node keywordNode = keyword.exportContentToXMLNode();
  137. // elementKeywords.appendChild(document.importNode(keywordNode, true));
  138. // }
  139. //
  140. // elementCandidatura.appendChild(elementKeywords);
  141. //
  142. // //Add root element to document
  143. // document.appendChild(elementCandidatura);
  144. //
  145. // Application result = new Application();
  146. // result = result.importContentFromXMLNode(elementCandidatura);
  147. //
  148. // assertEquals(expected, result);
  149. // }
  150. /**
  151. *
  152. */
  153. @Test
  154. public void ensureSameContentObjectsAreEqual() {
  155. String description = "MyCandidatura";
  156.  
  157. List<Keyword> keywords = new ArrayList<>();
  158. keywords.add(new Keyword("Doors"));
  159. keywords.add(new Keyword("Windows"));
  160.  
  161. Application expected = new Application(description, keywords);
  162. Application result = new Application(description, keywords);
  163.  
  164. assertEquals(expected, result);
  165. }
  166.  
  167. /**
  168. *
  169. */
  170. @Test
  171. public void ensureSameObjectIsEqual() {
  172. String description = "MyCandidatura";
  173.  
  174. List<Keyword> keywords = new ArrayList<>();
  175. keywords.add(new Keyword("Doors"));
  176. keywords.add(new Keyword("Windows"));
  177.  
  178. Application expected = new Application(description, keywords);
  179.  
  180. assertEquals(expected, expected);
  181. }
  182.  
  183. /**
  184. *
  185. */
  186. @Test
  187. public void ensureDifferentObjectsAreNotEqual() {
  188. String description = "MyCandidatura";
  189.  
  190. List<Keyword> keywords = new ArrayList<>();
  191. keywords.add(new Keyword("Doors"));
  192. keywords.add(new Keyword("Windows"));
  193.  
  194. Application expected = new Application(description, keywords);
  195.  
  196. Object result = new Object();
  197. assertNotEquals(expected, result);
  198. }
  199.  
  200. /**
  201. *
  202. */
  203. @Test
  204. public void ensureDifferentDescriptionMakeObjectsNotEqual() {
  205. String description1 = "MyCandidatura1";
  206. String description2 = "MyCandidatura2";
  207.  
  208. List<Keyword> keywords = new ArrayList<>();
  209. keywords.add(new Keyword("Doors"));
  210. keywords.add(new Keyword("Windows"));
  211.  
  212. Application expected = new Application(description1, keywords);
  213. Application result = new Application(description2, keywords);
  214.  
  215. assertNotEquals(expected, result);
  216. }
  217.  
  218. /**
  219. *
  220. */
  221. @Test
  222. public void ensureHashCodeIsCorrect() {
  223. String description = "MyCandidatura";
  224.  
  225. List<Keyword> keywords = new ArrayList<>();
  226. keywords.add(new Keyword("Doors"));
  227. keywords.add(new Keyword("Windows"));
  228.  
  229. Application application = new Application(description, keywords);
  230.  
  231. int expected = 461375881;
  232. int result = application.hashCode();
  233. assertEquals(expected, result);
  234.  
  235. }
  236.  
  237. /**
  238. *
  239. */
  240. @Test
  241. public void testGetApplicationInfo() {
  242. String description = "MyCandidatura";
  243. List<Keyword> keywords = new ArrayList<>();
  244. keywords.add(new Keyword("Doors"));
  245.  
  246. Application application = new Application(description, keywords);
  247.  
  248. String expected = "Description: MyCandidatura" + "\n" + "Área do Stand: 0" + "\n" + "Quantidade de convites: 0" + "\n" + "Keywords: " + keywords;
  249. String result = application.getApplicationInfo();
  250.  
  251. assertEquals(expected, result);
  252.  
  253. }
  254.  
  255. /**
  256. * Test of getKeywordList method, of class Application.
  257. */
  258. @Test
  259. public void testGetKeywordList() {
  260. System.out.println("getKeywordList");
  261. List<Keyword> keywordList = new ArrayList<>();
  262. Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
  263. List<Keyword> expResult = new ArrayList<>();
  264. List<Keyword> result = a.getKeywordList();
  265. assertEquals(expResult, result);
  266.  
  267. }
  268.  
  269. /**
  270. * Test of getAccepted method, of class Application.
  271. */
  272. @Test
  273. public void testGetAccepted() {
  274. System.out.println("getAccepted");
  275. Application instance = new Application();
  276. Boolean expResult = null;
  277. Boolean result = instance.getAccepted();
  278. assertEquals(expResult, result);
  279.  
  280. }
  281.  
  282. /**
  283. * Test of getBoothArea method, of class Application.
  284. */
  285. @Test
  286. public void testGetBoothArea() {
  287. System.out.println("getBoothArea");
  288. List<Keyword> keywordList = new ArrayList<>();
  289. Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
  290. Integer expResult = 20;
  291. Integer result = a.getBoothArea();
  292. assertEquals(expResult, result);
  293.  
  294. }
  295.  
  296. /**
  297. * Test of getInvitesQuantity method, of class Application.
  298. */
  299. @Test
  300. public void testGetInvitesQuantity() {
  301. System.out.println("getInvitesQuantity");
  302. Application instance = new Application();
  303. Integer expResult = null;
  304. Integer result = instance.getInvitesQuantity();
  305. assertEquals(expResult, result);
  306.  
  307. }
  308.  
  309. /**
  310. * Test of equals method, of class Application.
  311. */
  312. @Test
  313. public void testAddAssignment() {
  314. User u = new User("Default User", "Default", "default@gmail.com", "Ab-12");
  315. FuncionarioApoioEvento f = new FuncionarioApoioEvento(u);
  316. Assignment assign = new Assignment(f);
  317. AssignmentList assignmentList = new AssignmentList();
  318. boolean result1 = assignmentList.addAssignment(assign);
  319. boolean expResult1 = true;
  320. assertEquals(expResult1, result1);
  321.  
  322. boolean result2 = assignmentList.addAssignment(assign);
  323. boolean expResult2 =false;
  324. assertEquals(expResult2, result2);
  325. }
  326.  
  327. /**
  328. * Test of equals method, of class Application.
  329. */
  330. @Test
  331. public void testGetAssignList() {
  332. System.out.println("getAssignList");
  333.  
  334. Application a = new Application();
  335. AssignmentList expResult = new AssignmentList();
  336. AssignmentList result = a.getAssignList();
  337. assertEquals(expResult, result);
  338. }
  339.  
  340. /**
  341. * Test of getDescription method, of class Application.
  342. */
  343. @Test
  344. public void testGetDescription() {
  345. System.out.println("getDescription");
  346. List<Keyword> keywordList = new ArrayList<>();
  347. Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
  348.  
  349. String expResult = "ensureWorks";
  350. String result = a.getDescription();
  351. assertEquals(expResult, result);
  352.  
  353. }
  354.  
  355. /**
  356. * Test of getCompanyName method, of class Application.
  357. */
  358. @Test
  359. public void testGetCompanyName() {
  360. System.out.println("getCompanyName");
  361. List<Keyword> keywordList = new ArrayList<>();
  362. Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
  363.  
  364. String expResult = "Company";
  365. String result = a.getCompanyName();
  366. assertEquals(expResult, result);
  367. }
  368.  
  369. /**
  370. * Test of getDescription method, of class Application.
  371. */
  372. @Test
  373. public void testSetCompanyName() {
  374. System.out.println("getCompanyName");
  375. List<Keyword> keywordList = new ArrayList<>();
  376. Application a = new Application("...", "ensureWorks", keywordList, 20, 30,userMaker1);
  377.  
  378. String expResult = "Company";
  379. a.setCompanyName(expResult);
  380. String result = a.getCompanyName();
  381. assertEquals(expResult, result);
  382. }
  383.  
  384. /**
  385. *
  386. */
  387. @Test
  388. public void testSetAccepted() {
  389. System.out.println("setAccepted");
  390. List<Keyword> keywordList = new ArrayList<>();
  391. Application a = new Application("testeSetAccepted", "testeSetAccepted", keywordList, 20, 30,userMaker1);
  392. a.setAccepted(true);
  393. assertEquals(true, a.getAccepted());
  394. }
  395.  
  396. /**
  397. * Test of compareTo method, of class Application.
  398. */
  399. @Test
  400. public void testCompareTo() {
  401. System.out.println("compareTo");
  402. List<Keyword> keywordList = new ArrayList<>();
  403. List<Keyword> keywordList1 = new ArrayList<>();
  404. Keyword k = new Keyword("test");
  405. keywordList1.add(k);
  406. Application a = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
  407. Application app = new Application("Company", "ensureWorks", keywordList, 20, 30,userMaker1);
  408. Application app1 = new Application("Company1", "ensureWorks", keywordList, 20, 30,userMaker1);
  409. Application app2 = new Application("Company", "ensureWorks2", keywordList, 20, 30,userMaker1);
  410. Application app3 = new Application("Company", "ensureWorks", keywordList1, 20, 30,userMaker1);
  411. Application app4 = new Application("Company", "ensureWorks", keywordList, 30, 30,userMaker1);
  412. Application app5 = new Application("Company", "ensureWorks", keywordList, 20, 20,userMaker1);
  413. Application app6 = new Application("Company", "ensureWorks", keywordList, 20, 20,userMaker2);
  414. int expResult = 0;
  415. int result = a.compareTo(app);
  416. assertEquals(expResult, result);
  417. int expResult1 = 1;
  418. int result1 = a.compareTo(app1);
  419. assertEquals(expResult1, result1);
  420. int expResult2 = 1;
  421. int result2 = a.compareTo(app2);
  422. assertEquals(expResult2, result2);
  423. int expResult3 = 1;
  424. int result3 = a.compareTo(app3);
  425. assertEquals(expResult3, result3);
  426. int expResult4 = 1;
  427. int result4 = a.compareTo(app4);
  428. assertEquals(expResult4, result4);
  429. int expResult5 = 1;
  430. int result5 = a.compareTo(app5);
  431. assertEquals(expResult5, result5);
  432. int expResult6 = 1;
  433. int result6 = a.compareTo(app6);
  434. assertEquals(expResult6, result6);
  435.  
  436. }
  437.  
  438. /**
  439. * Test of hashCode method, of class Application.
  440. */
  441. @Test
  442. public void testHashCode() {
  443. System.out.println("hashCode");
  444. List<Keyword> k = new ArrayList<>();
  445. Application a1 = new Application("Company", "description", k, 34, 3 ,userMaker1);
  446. Application a2 = new Application("Company", "description", k, 34, 3,userMaker1);
  447. int expResult = a1.hashCode();
  448. int result = a2.hashCode();
  449. assertEquals(expResult, result);
  450. }
  451.  
  452.  
  453. /**
  454. * Test of getApplicationMaker method, of class Application.
  455. */
  456. @Test
  457. public void testGetApplicationMaker()
  458. {
  459. System.out.println("getApplicationMaker");
  460. Application instance = new Application();
  461. ParticipantRepresentant expResult = null;
  462. ParticipantRepresentant result = instance.getApplicationMaker();
  463. assertEquals(expResult, result);
  464. }
  465.  
  466. /**
  467. * Test of setApplicationMaker method, of class Application.
  468. */
  469. @Test
  470. public void testSetApplicationMaker()
  471. {
  472. System.out.println("setApplicationMaker");
  473. ParticipantRepresentant applicationMaker = null;
  474. Application instance = new Application();
  475. instance.setApplicationMaker(applicationMaker);
  476. }
  477.  
  478. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement