|
| 1 | +package com.codedifferently.lesson7.kenricksutherland; |
| 2 | + |
| 3 | +import static org.junit.jupiter.api.Assertions.*; |
| 4 | + |
| 5 | +import com.codedifferently.lesson7.kenricksutherland.Person.Gender; |
| 6 | +import com.codedifferently.lesson7.kenricksutherland.Person.InvalidAgeException; |
| 7 | +import org.junit.jupiter.api.Test; |
| 8 | + |
| 9 | +public class PersonsTest { |
| 10 | + |
| 11 | + @Test |
| 12 | + void testPersonInfo() { |
| 13 | + try { |
| 14 | + Person person = new Person("John Doe", 30, Gender.MALE, "Software Engineer", "USA"); |
| 15 | + assertEquals("John Doe", person.getName()); |
| 16 | + assertEquals(30, person.getAge()); |
| 17 | + assertEquals(Gender.MALE, person.getGender()); |
| 18 | + assertEquals("Software Engineer", person.getOccupation()); |
| 19 | + assertEquals("USA", person.getNationality()); |
| 20 | + } catch (Person.InvalidAgeException e) { |
| 21 | + fail("InvalidAgeException should not be thrown in this test."); |
| 22 | + } |
| 23 | + } |
| 24 | + |
| 25 | + @Test |
| 26 | + void testGetGenderPronoun() throws InvalidAgeException { |
| 27 | + Person person1 = new Person("John Doe", 30, Gender.MALE, "Software Engineer", "USA"); |
| 28 | + assertEquals("He", person1.getGenderPronoun()); |
| 29 | + |
| 30 | + Person person2 = new Person("Jane Doe", 25, Gender.FEMALE, "Doctor", "Canada"); |
| 31 | + assertEquals("She", person2.getGenderPronoun()); |
| 32 | + |
| 33 | + Person person3 = new Person("Alex Smith", 40, Gender.OTHER, "Artist", "France"); |
| 34 | + assertEquals("They", person3.getGenderPronoun()); |
| 35 | + } |
| 36 | + |
| 37 | + @Test |
| 38 | + void testGetPersonInfo() { |
| 39 | + try { |
| 40 | + Person person = new Person("John Doe", 30, Gender.MALE, "Software Engineer", "USA"); |
| 41 | + assertEquals(5, person.getPersonInfo().size()); |
| 42 | + } catch (Person.InvalidAgeException e) { |
| 43 | + fail("InvalidAgeException should not be thrown in this test."); |
| 44 | + } |
| 45 | + } |
| 46 | + |
| 47 | + @Test |
| 48 | + void testDisplayPersonInfo() { |
| 49 | + try { |
| 50 | + Person person = new Person("John Doe", 30, Gender.MALE, "Software Engineer", "USA"); |
| 51 | + assertDoesNotThrow(() -> person.displayPersonInfo()); |
| 52 | + } catch (Person.InvalidAgeException e) { |
| 53 | + fail("InvalidAgeException should not be thrown in this test."); |
| 54 | + } |
| 55 | + } |
| 56 | + |
| 57 | + @Test |
| 58 | + void testGetOccupationStatus() { |
| 59 | + try { |
| 60 | + Person employedPerson = new Person("John Doe", 30, Gender.MALE, "Software Engineer", "USA"); |
| 61 | + assertEquals("Employed as a Software Engineer", employedPerson.getOccupationStatus()); |
| 62 | + |
| 63 | + Person unemployedPerson = new Person("Jane Doe", 25, Gender.FEMALE, "", "Canada"); |
| 64 | + assertEquals("Unemployed", unemployedPerson.getOccupationStatus()); |
| 65 | + } catch (Person.InvalidAgeException e) { |
| 66 | + fail("InvalidAgeException should not be thrown in this test."); |
| 67 | + } |
| 68 | + } |
| 69 | +} |
0 commit comments