Skip to content

Commit 72c5d80

Browse files
author
“A1-4U2T1NN”
committed
feat: created framework for PersonTest; added try catch statement to getHairColor to change a null hair color to bald; fix: corrected grammar in getLifeStatus return statement strings;
1 parent 44faa1c commit 72c5d80

File tree

2 files changed

+45
-3
lines changed

2 files changed

+45
-3
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java

Lines changed: 7 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -66,7 +66,11 @@ public void setHeight(double height) {
6666

6767
public ArrayList<String> getHairColor() {
6868
if (hairColor == null) {
69-
throw new IllegalArgumentException("No hair color? This person must be bald!");
69+
try {
70+
throw new IllegalArgumentException("No hair color? This person must be bald!");
71+
} catch (IllegalArgumentException e) {
72+
hairColor.add("Bald");
73+
}
7074
}
7175
return hairColor;
7276
}
@@ -97,9 +101,9 @@ public ArrayList<String> getNaturalHairColor() {
97101

98102
public String getLifeStatus() {
99103
if (alive == true) {
100-
return "alive";
104+
return "Alive";
101105
} else {
102-
return "deceased";
106+
return "Deceased";
103107
}
104108
}
105109

Lines changed: 38 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,38 @@
1+
package com.codedifferently.lesson16;
2+
3+
import static org.junit.jupiter.api.Assertions.assertEquals;
4+
5+
import org.junit.jupiter.api.BeforeEach;
6+
import org.junit.jupiter.api.Test;
7+
8+
public class PersonTest {
9+
10+
Person person;
11+
12+
// Set up
13+
@BeforeEach
14+
void setUp() {
15+
person = new person();
16+
}
17+
18+
@Test
19+
// Method being tested
20+
public void testGet() {
21+
// Execersise
22+
int actual = .get();
23+
24+
int expected = ;
25+
// Assert(Checking the value)
26+
assertEquals(expected, actual);
27+
}
28+
29+
@Test
30+
public void testSet() {
31+
// Arrange
32+
int expectedSet = ;
33+
// Act
34+
person.set(expectedSet);
35+
// Assert
36+
assertEquals(expectedSet, person.get());
37+
}
38+
}

0 commit comments

Comments
 (0)