Advertisement
Guest User

Untitled

a guest
Mar 21st, 2018
921
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 5.30 KB | None | 0 0
  1. package tdt4140.gr1855.app.core;
  2.  
  3. import static org.junit.Assert.*;
  4.  
  5. import org.junit.Assert;
  6. import org.junit.Before;
  7. import org.junit.Test;
  8.  
  9. public class DoctorTest {
  10.  
  11.  
  12.  
  13.  
  14. Doctor doctor1 = new Doctor("Yann Kieffer", "yanniboy1@gmail.com", "Spaniatur1", 99887766, "Treungen eldresenter", false);
  15. Doctor doctor2 = new Doctor("Kristian Hagen", "namsosingen1@gmail.com", "Sverige1", 99887755, "Stjoerdalen eldresenter", false);
  16. Patient patient1 = new Patient("Ole Johnny", "olePat@gmail.com", "Turing11", 1997, 99887744);
  17. Patient patient2 = new Patient("Christian Nilsen", "christianPat@gmail.com", "Turing22", 1997, 99887733);
  18. Doctor doctor3;
  19.  
  20.  
  21. //test that patient-list is empty when a doctor is registered
  22. @Test
  23. public void NumberOfPatientsStartsAt0Test(){
  24. assertEquals(doctor1.getNumberOfPatients(),0);
  25. }
  26.  
  27.  
  28. //test getHospital
  29. @Test
  30. public void getHospitalTest() {
  31. assertEquals(doctor1.getHospital(), "Treungen eldresenter");
  32. }
  33.  
  34. //Test password length
  35. @Test
  36. public void PasswordHasCorrectLengthTest() {
  37. try {
  38. doctor3 = new Doctor("Jake Enge", "jak@gmail.com", "Pas1", 99778866, "Kristiansand Eldresenter", false);
  39. } catch (IllegalArgumentException ex) {
  40. assertEquals(ex.getMessage(), "Error: Password must have have length 8 or more");
  41. return;
  42. }
  43. Assert.fail();
  44. }
  45.  
  46.  
  47. //test exception when password does not contain at least a capital letter
  48. @Test
  49. public void testPasswordMustContainAtLeastOneCapitalLetter() {
  50. try {
  51. doctor2.setPassword("password1");
  52. } catch (Exception e) {
  53. assertEquals(e.getMessage(), "Error: Password must consist of at least on capital letter" );
  54. return;
  55. }
  56. Assert.fail("Test failed. Password must consist of at least one capital letter");
  57. }
  58.  
  59. //Test exception. Testing at least on small letter in password
  60. @Test
  61. public void TestPasswordHasAtLeastOneLittleLetter() {
  62. try {
  63. doctor1.setPassword("PASSWORD2");
  64. } catch (IllegalArgumentException ex) {
  65. assertEquals(ex.getMessage(), "Error: Password must consist of at least on small letter");
  66. return;
  67. }
  68. Assert.fail("Password must consist of at least on small letter");
  69. }
  70.  
  71. //Testing password has at least on number
  72. @Test
  73. public void TestPasswordHasAtLeastOneNumber() {
  74. try {
  75. doctor2.setPassword("PASSWORd");
  76. } catch (IllegalArgumentException ex) {
  77. assertEquals(ex.getMessage(), "Error: Password must consist of at least one number");
  78. return;
  79. }
  80. Assert.fail();
  81. }
  82. //testing phone number has length eight
  83. public void TestPhoneNUmberHasEightDigits() {
  84. try {
  85. doctor2.setPhoneNumber(37856);
  86. } catch (IllegalArgumentException e) {
  87. assertEquals(e.getMessage(), "Error:Mobile number must consist of 8 digits and start with 4 or 9");
  88. return;
  89.  
  90. }
  91. Assert.fail("expected IllegalArgumentException phone number must have eight digits");
  92. }
  93. //Testing name consists of more than two letters
  94. @Test
  95. public void TestNameIsMoreThanTwoLetters() {
  96. try {
  97. doctor2.setName("Ivar A");
  98. } catch (IllegalArgumentException ex) {
  99. assertEquals("Error: All parts of name must have at least two letters", ex.getMessage());
  100. return;
  101. } Assert.fail("All parts of name must have at least two letters");
  102. }
  103.  
  104. //testing name only consists of letters
  105. @Test
  106. public void TestNameOnlyContainLetters() {
  107. try {
  108. doctor2.setName("Hans fg4");
  109. } catch (IllegalArgumentException ex) {
  110. assertEquals("Error: Name can only consist of letters", ex.getMessage());
  111. return;
  112. } Assert.fail("Name can only consist of letters");
  113. }
  114.  
  115. //test valid email
  116. @Test
  117. public void testExceptionIfEmailConsistOfInvalidArguments() {
  118. try {
  119. doctor1.setusername("lege@lesen@gmail.com");
  120. } catch (Exception e) {
  121. assertEquals(e.getMessage(), "Error: lege@lesen@gmail.com must have exactly one '@'");
  122. return;
  123. }
  124. Assert.fail("Error. Username can only contain one '@'");
  125. }
  126. //test valid email
  127. @Test
  128. public void testExceptionIfEmailDomainIsHasWrongLength() {
  129. try {
  130. doctor1.setusername("lege@legesen.comm");
  131. } catch (Exception e) {
  132. assertEquals(e.getMessage(), "Error: Country part of domain must cosist of two or three letters");
  133. }
  134. try {
  135. doctor1.setusername("lege@legesen.n");
  136. } catch (Exception e) {
  137. assertEquals(e.getMessage(), "Error: Country part of domain must cosist of two or three letters");
  138. return;
  139. }
  140. Assert.fail("Error. Username can only contain one '@'");
  141. }
  142. //testing phoneNumber
  143. @Test
  144. public void TestExaptioPhoneNumber() {
  145. try {
  146. doctor1.setPhoneNumber(3333333);
  147. } catch (IllegalArgumentException ex) {
  148.  
  149. assertEquals(ex.getMessage(), "Error: Mobile number must consist of 8 digits and start with 4 or 9");
  150. return;
  151. }
  152. Assert.fail();
  153. }
  154.  
  155.  
  156.  
  157.  
  158. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement