Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package tdt4140.gr1855.app.core;
- import static org.junit.Assert.*;
- import org.junit.Assert;
- import org.junit.Before;
- import org.junit.Test;
- public class DoctorTest {
- Doctor doctor1 = new Doctor("Yann Kieffer", "yanniboy1@gmail.com", "Spaniatur1", 99887766, "Treungen eldresenter", false);
- Doctor doctor2 = new Doctor("Kristian Hagen", "namsosingen1@gmail.com", "Sverige1", 99887755, "Stjoerdalen eldresenter", false);
- Patient patient1 = new Patient("Ole Johnny", "olePat@gmail.com", "Turing11", 1997, 99887744);
- Patient patient2 = new Patient("Christian Nilsen", "christianPat@gmail.com", "Turing22", 1997, 99887733);
- Doctor doctor3;
- //test that patient-list is empty when a doctor is registered
- @Test
- public void NumberOfPatientsStartsAt0Test(){
- assertEquals(doctor1.getNumberOfPatients(),0);
- }
- //test getHospital
- @Test
- public void getHospitalTest() {
- assertEquals(doctor1.getHospital(), "Treungen eldresenter");
- }
- //Test password length
- @Test
- public void PasswordHasCorrectLengthTest() {
- try {
- doctor3 = new Doctor("Jake Enge", "jak@gmail.com", "Pas1", 99778866, "Kristiansand Eldresenter", false);
- } catch (IllegalArgumentException ex) {
- assertEquals(ex.getMessage(), "Error: Password must have have length 8 or more");
- return;
- }
- Assert.fail();
- }
- //test exception when password does not contain at least a capital letter
- @Test
- public void testPasswordMustContainAtLeastOneCapitalLetter() {
- try {
- doctor2.setPassword("password1");
- } catch (Exception e) {
- assertEquals(e.getMessage(), "Error: Password must consist of at least on capital letter" );
- return;
- }
- Assert.fail("Test failed. Password must consist of at least one capital letter");
- }
- //Test exception. Testing at least on small letter in password
- @Test
- public void TestPasswordHasAtLeastOneLittleLetter() {
- try {
- doctor1.setPassword("PASSWORD2");
- } catch (IllegalArgumentException ex) {
- assertEquals(ex.getMessage(), "Error: Password must consist of at least on small letter");
- return;
- }
- Assert.fail("Password must consist of at least on small letter");
- }
- //Testing password has at least on number
- @Test
- public void TestPasswordHasAtLeastOneNumber() {
- try {
- doctor2.setPassword("PASSWORd");
- } catch (IllegalArgumentException ex) {
- assertEquals(ex.getMessage(), "Error: Password must consist of at least one number");
- return;
- }
- Assert.fail();
- }
- //testing phone number has length eight
- public void TestPhoneNUmberHasEightDigits() {
- try {
- doctor2.setPhoneNumber(37856);
- } catch (IllegalArgumentException e) {
- assertEquals(e.getMessage(), "Error:Mobile number must consist of 8 digits and start with 4 or 9");
- return;
- }
- Assert.fail("expected IllegalArgumentException phone number must have eight digits");
- }
- //Testing name consists of more than two letters
- @Test
- public void TestNameIsMoreThanTwoLetters() {
- try {
- doctor2.setName("Ivar A");
- } catch (IllegalArgumentException ex) {
- assertEquals("Error: All parts of name must have at least two letters", ex.getMessage());
- return;
- } Assert.fail("All parts of name must have at least two letters");
- }
- //testing name only consists of letters
- @Test
- public void TestNameOnlyContainLetters() {
- try {
- doctor2.setName("Hans fg4");
- } catch (IllegalArgumentException ex) {
- assertEquals("Error: Name can only consist of letters", ex.getMessage());
- return;
- } Assert.fail("Name can only consist of letters");
- }
- //test valid email
- @Test
- public void testExceptionIfEmailConsistOfInvalidArguments() {
- try {
- doctor1.setusername("lege@lesen@gmail.com");
- } catch (Exception e) {
- assertEquals(e.getMessage(), "Error: lege@lesen@gmail.com must have exactly one '@'");
- return;
- }
- Assert.fail("Error. Username can only contain one '@'");
- }
- //test valid email
- @Test
- public void testExceptionIfEmailDomainIsHasWrongLength() {
- try {
- doctor1.setusername("lege@legesen.comm");
- } catch (Exception e) {
- assertEquals(e.getMessage(), "Error: Country part of domain must cosist of two or three letters");
- }
- try {
- doctor1.setusername("lege@legesen.n");
- } catch (Exception e) {
- assertEquals(e.getMessage(), "Error: Country part of domain must cosist of two or three letters");
- return;
- }
- Assert.fail("Error. Username can only contain one '@'");
- }
- //testing phoneNumber
- @Test
- public void TestExaptioPhoneNumber() {
- try {
- doctor1.setPhoneNumber(3333333);
- } catch (IllegalArgumentException ex) {
- assertEquals(ex.getMessage(), "Error: Mobile number must consist of 8 digits and start with 4 or 9");
- return;
- }
- Assert.fail();
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement