|
4 | 4 | import static org.junit.jupiter.api.Assertions.assertFalse;
|
5 | 5 | import static org.junit.jupiter.api.Assertions.assertTrue;
|
6 | 6 | import static org.junit.jupiter.api.Assertions.fail;
|
7 |
| -import org.junit.jupiter.api.Test; |
8 | 7 |
|
9 | 8 | import com.codedifferently.lesson16.HummadTanweer.Person.Gender;
|
| 9 | +import com.codedifferently.lesson16.HummadTanweer.Person.HobbyLimitExceededException; |
| 10 | +import org.junit.jupiter.api.Test; |
10 | 11 |
|
11 | 12 | public class PersonTest {
|
12 | 13 | @Test
|
13 | 14 | void testIsAdult() {
|
14 | 15 | Person adult = new Person( "xyz", 29, Gender. MALE, "[email protected]");
|
15 | 16 | assertTrue(adult.isAdult(), "True for 29");
|
16 |
| - |
17 | 17 | Person minor = new Person( "abc", 15, Gender. FEMALE, "[email protected]");
|
18 | 18 | assertFalse(minor.isAdult(), "False for 15");
|
19 | 19 | }
|
20 | 20 |
|
21 |
| - @Test |
22 |
| - void testAddHobby() throws HobbyLimitExceededException { |
23 |
| - Person person = new Person( "xyz", 29, Gender. MALE, "[email protected]"); |
24 |
| - |
25 |
| - person.addHobby("Football"); |
26 |
| - person.addHobby("Pickleball"); |
27 |
| - |
28 |
| - assertEquals(2, person.getHobbies().size()); |
29 |
| - assertTrue(person.getHobbies().contains("Football")); |
30 |
| - assertTrue(person.getHobbies().contains("Pickleball")); |
31 |
| - } |
| 21 | + @Test |
| 22 | + void testAddHobby() throws HobbyLimitExceededException { |
| 23 | + Person person = new Person( "xyz", 29, Gender. MALE, "[email protected]"); |
32 | 24 |
|
33 |
| - @Test |
34 |
| - void testAddHobbyExceedsLimit() throws HobbyLimitExceededException { |
35 |
| - Person person = new Person( "xyz", 29, Gender. MALE, "[email protected]"); |
36 |
| - |
37 |
| - try { |
38 |
| - person.addHobby("Football"); |
39 |
| - person.addHobby("Pickleball"); |
40 |
| - person.addHobby("Basketball"); |
41 |
| - fail("Expected HobbyLimitExceededException to be thrown"); |
42 |
| - } catch (HobbyLimitExceededException e) { |
43 |
| - assertEquals("Cannot add more than 2 hobbies.", e.getMessage()); |
44 |
| - } |
| 25 | + person.addHobby("Football"); |
| 26 | + person.addHobby("Pickleball"); |
| 27 | + |
| 28 | + assertEquals(2, person.getHobbies().size()); |
| 29 | + assertTrue(person.getHobbies().contains("Football")); |
| 30 | + assertTrue(person.getHobbies().contains("Pickleball")); |
| 31 | + } |
| 32 | + |
| 33 | + @Test |
| 34 | + public void testGetName() { |
| 35 | + Person person = new Person( "xyz", 29, Gender. MALE, "[email protected]"); |
| 36 | + assertEquals("xyz", person.getName()); |
| 37 | + } |
| 38 | + |
| 39 | + @Test |
| 40 | + public void getEmail() { |
| 41 | + Person person = new Person( "xyz", 29, Gender. MALE, "[email protected]"); |
| 42 | + assertEquals( "[email protected]", person. getEmail()); |
| 43 | + } |
| 44 | + |
| 45 | + @Test |
| 46 | + void testAddHobbyExceedsLimit() throws HobbyLimitExceededException { |
| 47 | + Person person = new Person( "xyz", 29, Gender. MALE, "[email protected]"); |
| 48 | + |
| 49 | + try { |
| 50 | + person.addHobby("Football"); |
| 51 | + person.addHobby("Pickleball"); |
| 52 | + person.addHobby("Basketball"); |
| 53 | + fail("Expected HobbyLimitExceededException to be thrown"); |
| 54 | + } catch (HobbyLimitExceededException e) { |
| 55 | + assertEquals("Cannot add more than 2 hobbies.", e.getMessage()); |
45 | 56 | }
|
| 57 | + } |
46 | 58 | }
|
0 commit comments