Advertisement
Guest User

FileReaderTest

a guest
Oct 15th, 2017
397
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.48 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 Model;
  7.  
  8. import DoublyLinkedList.DoublyLinkedList;
  9. import java.io.File;
  10. import java.util.HashSet;
  11. import java.util.Set;
  12. import org.junit.After;
  13. import org.junit.AfterClass;
  14. import org.junit.Before;
  15. import org.junit.BeforeClass;
  16. import org.junit.Test;
  17. import static org.junit.Assert.*;
  18.  
  19. /**
  20. *
  21. * @author Pedro Quinta
  22. */
  23. public class FileReaderTest {
  24.  
  25. public FileReaderTest() {
  26. }
  27.  
  28. @BeforeClass
  29. public static void setUpClass() {
  30. }
  31.  
  32. @AfterClass
  33. public static void tearDownClass() {
  34. }
  35.  
  36. @Before
  37. public void setUp() {
  38. }
  39.  
  40. @After
  41. public void tearDown() {
  42. }
  43.  
  44. /**
  45. * Test of readFileCidadao method, of class FileReader.
  46. */
  47. @Test
  48. public void testReadFileCidadao() {
  49. System.out.println("readFileCidadao");
  50.  
  51. FileReader instance = new FileReader();
  52.  
  53. GestaoReparticao reparticao = new GestaoReparticao();
  54. Set<Cidadao> cidadaos = reparticao.getSetCidadao();
  55.  
  56. Cidadao cid = new Cidadao("Ana", 111222333, "ana@gmail.com", "4200-072", 1234);
  57. Cidadao cid1 = new Cidadao("Berta", 223344, "berta@gmail.com", "4200-071", 1234);
  58. Cidadao cid2 = new Cidadao("Manuel", 584769, "manuel@gmail.com", "4715-357", 5762);
  59. Cidadao cid3 = new Cidadao("Pedro", 53263622, "pedro@gmail.com", "4400-321", 3421);
  60. Cidadao cid4 = new Cidadao("Beatriz", 3121121, "beatriz@gmail.com", "4400-123", 2543);
  61. Cidadao cid5 = new Cidadao("Joao", 2311212, "joao@gmail.com", "4450-321", 1243);
  62.  
  63. cidadaos.add(cid);
  64. cidadaos.add(cid1);
  65. cidadaos.add(cid2);
  66. cidadaos.add(cid3);
  67. cidadaos.add(cid4);
  68. cidadaos.add(cid5);
  69.  
  70. Set<Cidadao> expResult = cidadaos;
  71.  
  72. instance.readFileCidadao();
  73. Set<Cidadao> result = instance.getCidadaos();
  74.  
  75. assertEquals(expResult, result);
  76.  
  77. }
  78.  
  79. /**
  80. * Test of readFileReparticao method, of class FileReader.
  81. */
  82. @Test
  83. public void testReadFileReparticao() {
  84. System.out.println("readFileReparticao");
  85.  
  86. FileReader instance = new FileReader();
  87.  
  88. GestaoReparticao reparticao = new GestaoReparticao();
  89. DoublyLinkedList<Reparticao> reparticoes = reparticao.getListaReparticoes();
  90.  
  91. Set<String> setServicos = new HashSet<>();
  92. setServicos.add("A");
  93. setServicos.add("C");
  94. setServicos.add("D");
  95. Reparticao rep = new Reparticao("Porto", 1234, 4200, setServicos);
  96. Set<String> setServicos1 = new HashSet<>();
  97. setServicos1.add("A");
  98. setServicos1.add("B");
  99. Reparticao rep1 = new Reparticao("Maia", 1235, 4470, setServicos1);
  100. Set<String> setServicos2 = new HashSet<>();
  101. setServicos2.add("C");
  102. setServicos2.add("D");
  103. Reparticao rep2 = new Reparticao("Lisboa", 1256, 4300, setServicos2);
  104. Set<String> setServicos3 = new HashSet<>();
  105. setServicos3.add("A");
  106. setServicos3.add("C");
  107. Reparticao rep3 = new Reparticao("Coimbra", 1289, 4120, setServicos3);
  108. Set<String> setServicos4 = new HashSet<>();
  109. setServicos1.add("B");
  110. setServicos1.add("D");
  111. Reparticao rep4 = new Reparticao("Braga", 1254, 4250, setServicos4);
  112. Set<String> setServicos5 = new HashSet<>();
  113. setServicos5.add("B");
  114. setServicos5.add("A");
  115. Reparticao rep5 = new Reparticao("Algarve", 5637, 1287, setServicos5);
  116.  
  117. reparticoes.addFirst(rep);
  118. reparticoes.addLast(rep1);
  119. reparticoes.addLast(rep2);
  120. reparticoes.addLast(rep3);
  121. reparticoes.addLast(rep4);
  122. reparticoes.addLast(rep5);
  123.  
  124. DoublyLinkedList<Reparticao> expResult = reparticoes;
  125. Reparticao h = expResult.first();
  126. Reparticao t = expResult.last();
  127. int L = expResult.size();
  128.  
  129. instance.readFileReparticao();
  130.  
  131. DoublyLinkedList<Reparticao> result = instance.getReparticoes();
  132. Reparticao h1 = result.first();
  133. Reparticao t1 = result.last();
  134. int L1 = result.size();
  135.  
  136. assertEquals(h, h1);
  137. assertEquals(t, t1);
  138. assertEquals(L, L1);
  139.  
  140. }
  141.  
  142. /**
  143. * Test of readFileSenha method, of class FileReader.
  144. */
  145. @Test
  146. public void testReadFileSenha() {
  147. System.out.println("readFileSenha");
  148. FileReader instance = new FileReader();
  149.  
  150. GestaoReparticao reparticao = new GestaoReparticao();
  151. Set<Senha> senhas = reparticao.getSetSenha();
  152.  
  153. Senha sen = new Senha(111222333, 'A', 1);
  154. Senha sen1 = new Senha(111222333, 'C', 1);
  155. Senha sen2 = new Senha(222333444, 'A', 2);
  156. Senha sen3 = new Senha(333444555, 'A', 3);
  157. Senha sen4 = new Senha(152626121, 'C', 2);
  158. Senha sen5 = new Senha(153632887, 'D', 1);
  159. Senha sen6 = new Senha(167788289, 'B', 1);
  160. Senha sen7 = new Senha(124536373, 'B', 2);
  161.  
  162. senhas.add(sen);
  163. senhas.add(sen1);
  164. senhas.add(sen2);
  165. senhas.add(sen3);
  166. senhas.add(sen4);
  167. senhas.add(sen5);
  168. senhas.add(sen6);
  169. senhas.add(sen7);
  170.  
  171. Set<Senha> expResult = senhas;
  172.  
  173. instance.readFileSenha();
  174. Set<Senha> result = instance.getSenhas();
  175.  
  176. assertEquals(expResult, result);
  177.  
  178. }
  179. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement