-
Notifications
You must be signed in to change notification settings - Fork 113
Expand file tree
/
Copy pathPersonTest.java
More file actions
49 lines (38 loc) · 1.36 KB
/
PersonTest.java
File metadata and controls
49 lines (38 loc) · 1.36 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
import com.ironhack.Person;
import com.ironhack.PersonsList;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.*;
public class PersonTest {
@Test
void testSetAgeThrowsException() {
Person person = new Person(1, "Test Name", 25, "Engineer");
assertThrows(IllegalArgumentException.class, () -> {
person.setAge(-5);
});
}
@Test
void testFindByNameSuccess() {
PersonsList list = new PersonsList();
Person person = new Person(1, "Test Name", 30, "Doctor");
list.addPerson(person);
Person found = list.findByName("Test Name");
assertEquals(person, found);
}
@Test
void testFindByNameInvalidFormat() {
PersonsList list = new PersonsList();
assertThrows(IllegalArgumentException.class, () -> {
list.findByName("TestName");
});
}
@Test
void testCloneCreatesNewPersonWithDifferentId() {
PersonsList list = new PersonsList();
Person original = new Person(1, "Test Name", 28, "Lawyer");
Person cloned = list.clone(original);
assertNotEquals(original.getId(), cloned.getId());
assertEquals(original.getName(), cloned.getName());
assertEquals(original.getAge(), cloned.getAge());
assertEquals(original.getOccupation(), cloned.getOccupation());
}
}