Esempio n. 1
0
  /** constuctor test */
  @Test
  public void testGeneralConstructor() {
    // valid name
    assertEquals(doctor1.getName(), "Bobby Bob");
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.YEAR), 1960);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.MONTH), 5);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 10);
    assertEquals(doctor1.getGender(), "male");
    assertEquals(doctor1.getAddress(), "The Quay, Waterford");
    assertEquals(doctor1.getContactNumber(), 12345678);
    assertEquals(doctor1.isQualifiedInIreland(), true);

    // invalid name
    assertEquals(invalidDoctor.getName(), "!birth cert needed !");
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.YEAR), 1915);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.MONTH), 11);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 31);
    assertEquals(invalidDoctor.getGender(), "male");
    assertEquals(invalidDoctor.getAddress(), "to be confirmed");
    assertEquals(invalidDoctor.getContactNumber(), 999999999);
    assertEquals(invalidDoctor.isQualifiedInIreland(), false);

    assertEquals(anotherInvalidDoctor.getName(), "This is way too long");
    assertEquals(anotherInvalidDoctor.dateOfBirth.get(GregorianCalendar.YEAR), 1915);
    assertEquals(anotherInvalidDoctor.dateOfBirth.get(GregorianCalendar.MONTH), 11);
    assertEquals(anotherInvalidDoctor.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 31);
    assertEquals(anotherInvalidDoctor.getGender(), "male");
    assertEquals(
        anotherInvalidDoctor.getAddress(),
        "123456789012345678901234567890123456789012345678901234567890");
    assertEquals(anotherInvalidDoctor.getContactNumber(), 999999999);
    assertEquals(anotherInvalidDoctor.isQualifiedInIreland(), false);
  }
Esempio n. 2
0
  /** getters and setters test */
  @Test
  public void testSettersAndGetters() {
    // valid name
    assertEquals(doctor1.getName(), "Bobby Bob");
    doctor1.setName("New valid name");
    assertNotEquals(doctor1.getName(), "Bobby Bob");
    assertEquals(doctor1.getName(), "New valid name");

    // invalid name
    assertEquals(invalidDoctor.getName(), "!birth cert needed !");
    invalidDoctor.setName("AB");
    assertNotEquals(invalidDoctor.getName(), "AB");
    assertEquals(invalidDoctor.getName(), "!birth cert needed !");

    assertEquals(anotherInvalidDoctor.getName(), "This is way too long");
    anotherInvalidDoctor.setName("New tooooooooooo long name");
    assertNotEquals(anotherInvalidDoctor.getName(), "New tooooooooooo long name");
    assertEquals(anotherInvalidDoctor.getName(), "This is way too long");

    // valid dateOfBirth
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.YEAR), 1960);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.MONTH), 5);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 10);
    doctor1.setDateOfBirth(1950, 10, 15);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.YEAR), 1950);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.MONTH), 9);
    assertEquals(doctor1.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 15);
    assertNotEquals(doctor1.dateOfBirth.get(GregorianCalendar.YEAR), 1960);
    assertNotEquals(doctor1.dateOfBirth.get(GregorianCalendar.MONTH), 5);
    assertNotEquals(doctor1.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 10);

    // invalid dateOfBirth
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.YEAR), 1915);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.MONTH), 11);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 31);
    invalidDoctor.setDateOfBirth(1900, 10, 15);
    assertNotEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.YEAR), 1900);
    assertNotEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.MONTH), 9);
    assertNotEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 15);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.YEAR), 1915);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.MONTH), 11);
    assertEquals(invalidDoctor.dateOfBirth.get(GregorianCalendar.DAY_OF_MONTH), 31);

    // valid gender
    assertEquals(doctor1.getGender(), "male");
    doctor1.setGender("female");
    assertNotEquals(doctor1.getGender(), "male");
    assertEquals(doctor1.getGender(), "female");

    // invalid gender
    assertEquals(invalidDoctor.getGender(), "male");
    invalidDoctor.setGender("unknown");
    assertNotEquals(invalidDoctor.getGender(), "unknown");
    assertEquals(invalidDoctor.getGender(), "male");

    // valid address
    assertEquals(doctor1.getAddress(), "The Quay, Waterford");
    doctor1.setAddress("The Quay, Wexford");
    assertNotEquals(doctor1.getAddress(), "The Quay, Waterford");
    assertEquals(doctor1.getAddress(), "The Quay, Wexford");

    // invalid address
    assertEquals(doctor1.getAddress(), "The Quay, Wexford");
    doctor1.setAddress("abc");
    assertNotEquals(doctor1.getAddress(), "abc");
    assertEquals(doctor1.getAddress(), "The Quay, Wexford");

    assertEquals(invalidDoctor.getAddress(), "to be confirmed");
    invalidDoctor.setAddress(
        "1234567890123456789012345678901234567890123456789012345678901234567890");
    assertNotEquals(
        invalidDoctor.getAddress(),
        "1234567890123456789012345678901234567890123456789012345678901234567890");
    assertEquals(invalidDoctor.getAddress(), "to be confirmed");

    // valid contactNumber
    assertEquals(doctor1.getContactNumber(), 12345678);
    doctor1.setContactNumber(123456789);
    assertNotEquals(doctor1.getContactNumber(), 12345678);
    assertEquals(doctor1.getContactNumber(), 123456789);

    // invalid contactNumber
    assertEquals(doctor1.getContactNumber(), 123456789);
    doctor1.setContactNumber(12345);
    assertNotEquals(doctor1.getContactNumber(), 12345);
    assertEquals(doctor1.getContactNumber(), 123456789);

    // qualifiedInIreland
    assertEquals(doctor1.isQualifiedInIreland(), true);
    doctor1.setQualifiedInIreland(false);
    assertNotEquals(doctor1.isQualifiedInIreland(), true);
    assertEquals(doctor1.isQualifiedInIreland(), false);

    assertEquals(invalidDoctor.isQualifiedInIreland(), false);
    invalidDoctor.setQualifiedInIreland(true);
    assertEquals(invalidDoctor.isQualifiedInIreland(), true);
    assertNotEquals(invalidDoctor.isQualifiedInIreland(), false);
  }