1
1
package com .codedifferently .lesson16 .person ;
2
2
3
- import java . util . ArrayList ;
3
+ import static org . junit . jupiter . api . Assertions . assertEquals ;
4
4
5
+ import java .util .ArrayList ;
5
6
import org .junit .jupiter .api .Assertions ;
6
- import static org .junit .jupiter .api .Assertions .assertEquals ;
7
7
import org .junit .jupiter .api .BeforeEach ;
8
8
import org .junit .jupiter .api .Test ;
9
9
10
10
public class PersonTest {
11
11
12
- Person person ;
13
-
14
- @ BeforeEach
15
- void setUp () {
16
- ArrayList <String > hairColor = new ArrayList <>();
17
- hairColor .add ("Black" );
18
- hairColor .add ("Purple" );
19
- person = new Person ("Chigazo" , "Male" , "African-American" , 20 , 1.8288 , hairColor , true );
20
- }
21
-
22
- @ Test
23
- public void testGetName () {
24
- // Act
25
- String actualName = person .getName ();
26
- // Arrange
27
- String expectedName = "Chigazo" ;
28
- // Assert
29
- assertEquals (expectedName , actualName );
30
- }
31
-
32
- @ Test
33
- public void testSetName () {
34
- // Arrange
35
- String expectedSet = "Austin" ;
36
- // Act
37
- person .setName (expectedSet );
38
- // Assert
39
- assertEquals (expectedSet , person .getName ());
40
- }
41
-
42
- @ Test
43
- public void testGetSex () {
44
- // Act
45
- String actualSex = person .getSex ();
46
- // Arrange
47
- String expectedSex = "Male" ;
48
- // Assert(Checking the value)
49
- assertEquals (expectedSex , actualSex );
50
- }
51
-
52
- @ Test
53
- public void testSetSex () {
54
- // Arrange
55
- String expectedSex = "Female" ;
56
- // Act
57
- person .setSex (expectedSex );
58
- // Assert
59
- assertEquals (expectedSex , person .getSex ());
60
- }
61
-
62
- @ Test
63
- public void testGetRace () {
64
- // Act
65
- String actualRace = person .getRace ();
66
- // Arrange
67
- String expectedRace = "African-American" ;
68
- // Assert(Checking the value)
69
- assertEquals (expectedRace , actualRace );
70
- }
71
-
72
- @ Test
73
- public void testSetRace () {
74
- // Arrange
75
- String expectedRace = "Asian" ;
76
- // Act
77
- person .setRace (expectedRace );
78
- // Assert
79
- assertEquals (expectedRace , person .getRace ());
80
- }
81
-
82
- @ Test
83
- public void testGetAge () {
84
- // Act
85
- int actualAge = person .getAge ();
86
- // Arrange
87
- int expectedAge = 20 ;
88
- // Assert(Checking the value)
89
- assertEquals (expectedAge , actualAge );
90
- }
91
-
92
- @ Test
93
- public void testSetAge () {
94
- // Arrange
95
- int expectedAge = 21 ;
96
- // Act
97
- person .setAge (expectedAge );
98
- // Assert
99
- assertEquals (expectedAge , person .getAge ());
100
- }
101
-
102
- @ Test
103
- public void testGetHeight () {
104
- // Act
105
- double actualHeight = person .getHeight ();
106
- // Arrange
107
- double expectedHeight = 1.8288 ;
108
- // Assert(Checking the value)
109
- assertEquals (expectedHeight , actualHeight );
110
- }
111
-
112
- @ Test
113
- public void testSetHeight () {
114
- // Arrange
115
- double expectedHeight = 1.92024 ;
116
- // Act
117
- person .setHeight (expectedHeight );
118
- // Assert
119
- assertEquals (expectedHeight , person .getHeight ());
120
- }
121
-
122
- @ Test
123
- public void testGetHairColor () {
124
- // Act
125
- ArrayList <String > actualHairColor = person .getHairColor ();
126
- // Arrange
127
- ArrayList <String > expectedHairColor = new ArrayList <>();
128
- expectedHairColor .add ("Black" );
129
- expectedHairColor .add ("Purple" );
130
- // Assert
131
- assertEquals (expectedHairColor , actualHairColor );
132
- }
133
-
134
- @ Test
135
- public void testGetHairColor__hairColorDoesNotExist () {
136
- // Arrange
137
- Person baldPerson = new Person ("John" , "Male" , "Caucasian" , 25 , 1.75 , null , true );
138
- // Act
139
- Exception exception = Assertions .assertThrows (IllegalArgumentException .class , () -> {
140
- baldPerson .getHairColor ();
141
- });
142
- // Assert
143
- assertEquals ("No hair color? This person must be bald!" , exception .getMessage ());
144
- }
145
-
146
- @ Test
147
- public void testGetNaturalHairColor () {
148
- ArrayList <String > expectedNaturalHairColor = new ArrayList <>();
149
- expectedNaturalHairColor .add ("Black" );
150
- ArrayList <String > actualNaturalHairColor = person .getNaturalHairColor ();
151
- assertEquals (expectedNaturalHairColor , actualNaturalHairColor );
152
- }
153
-
154
- @ Test
155
- public void testSetHairColor () {
156
- // Arrange
157
- ArrayList <String > expectedHairColor = new ArrayList <>();
158
- expectedHairColor .add ("Brown" );
159
- // Act
160
- person .setHairColor (expectedHairColor );
161
- // Assert
162
- assertEquals (expectedHairColor , person .getHairColor ());
163
- }
164
-
165
- @ Test
12
+ Person person ;
13
+
14
+ @ BeforeEach
15
+ void setUp () {
16
+ ArrayList <String > hairColor = new ArrayList <>();
17
+ hairColor .add ("Black" );
18
+ hairColor .add ("Purple" );
19
+ person = new Person ("Chigazo" , "Male" , "African-American" , 20 , 1.8288 , hairColor , true );
20
+ }
21
+
22
+ @ Test
23
+ public void testGetName () {
24
+ // Act
25
+ String actualName = person .getName ();
26
+ // Arrange
27
+ String expectedName = "Chigazo" ;
28
+ // Assert
29
+ assertEquals (expectedName , actualName );
30
+ }
31
+
32
+ @ Test
33
+ public void testSetName () {
34
+ // Arrange
35
+ String expectedSet = "Austin" ;
36
+ // Act
37
+ person .setName (expectedSet );
38
+ // Assert
39
+ assertEquals (expectedSet , person .getName ());
40
+ }
41
+
42
+ @ Test
43
+ public void testGetSex () {
44
+ // Act
45
+ String actualSex = person .getSex ();
46
+ // Arrange
47
+ String expectedSex = "Male" ;
48
+ // Assert(Checking the value)
49
+ assertEquals (expectedSex , actualSex );
50
+ }
51
+
52
+ @ Test
53
+ public void testSetSex () {
54
+ // Arrange
55
+ String expectedSex = "Female" ;
56
+ // Act
57
+ person .setSex (expectedSex );
58
+ // Assert
59
+ assertEquals (expectedSex , person .getSex ());
60
+ }
61
+
62
+ @ Test
63
+ public void testGetRace () {
64
+ // Act
65
+ String actualRace = person .getRace ();
66
+ // Arrange
67
+ String expectedRace = "African-American" ;
68
+ // Assert(Checking the value)
69
+ assertEquals (expectedRace , actualRace );
70
+ }
71
+
72
+ @ Test
73
+ public void testSetRace () {
74
+ // Arrange
75
+ String expectedRace = "Asian" ;
76
+ // Act
77
+ person .setRace (expectedRace );
78
+ // Assert
79
+ assertEquals (expectedRace , person .getRace ());
80
+ }
81
+
82
+ @ Test
83
+ public void testGetAge () {
84
+ // Act
85
+ int actualAge = person .getAge ();
86
+ // Arrange
87
+ int expectedAge = 20 ;
88
+ // Assert(Checking the value)
89
+ assertEquals (expectedAge , actualAge );
90
+ }
91
+
92
+ @ Test
93
+ public void testSetAge () {
94
+ // Arrange
95
+ int expectedAge = 21 ;
96
+ // Act
97
+ person .setAge (expectedAge );
98
+ // Assert
99
+ assertEquals (expectedAge , person .getAge ());
100
+ }
101
+
102
+ @ Test
103
+ public void testGetHeight () {
104
+ // Act
105
+ double actualHeight = person .getHeight ();
106
+ // Arrange
107
+ double expectedHeight = 1.8288 ;
108
+ // Assert(Checking the value)
109
+ assertEquals (expectedHeight , actualHeight );
110
+ }
111
+
112
+ @ Test
113
+ public void testSetHeight () {
114
+ // Arrange
115
+ double expectedHeight = 1.92024 ;
116
+ // Act
117
+ person .setHeight (expectedHeight );
118
+ // Assert
119
+ assertEquals (expectedHeight , person .getHeight ());
120
+ }
121
+
122
+ @ Test
123
+ public void testGetHairColor () {
124
+ // Act
125
+ ArrayList <String > actualHairColor = person .getHairColor ();
126
+ // Arrange
127
+ ArrayList <String > expectedHairColor = new ArrayList <>();
128
+ expectedHairColor .add ("Black" );
129
+ expectedHairColor .add ("Purple" );
130
+ // Assert
131
+ assertEquals (expectedHairColor , actualHairColor );
132
+ }
133
+
134
+ @ Test
135
+ public void testGetHairColor__hairColorDoesNotExist () {
136
+ // Arrange
137
+ Person baldPerson = new Person ("John" , "Male" , "Caucasian" , 25 , 1.75 , null , true );
138
+ // Act
139
+ Exception exception =
140
+ Assertions .assertThrows (
141
+ IllegalArgumentException .class ,
142
+ () -> {
143
+ baldPerson .getHairColor ();
144
+ });
145
+ // Assert
146
+ assertEquals ("No hair color? This person must be bald!" , exception .getMessage ());
147
+ }
148
+
149
+ @ Test
150
+ public void testGetNaturalHairColor () {
151
+ ArrayList <String > expectedNaturalHairColor = new ArrayList <>();
152
+ expectedNaturalHairColor .add ("Black" );
153
+ ArrayList <String > actualNaturalHairColor = person .getNaturalHairColor ();
154
+ assertEquals (expectedNaturalHairColor , actualNaturalHairColor );
155
+ }
156
+
157
+ @ Test
158
+ public void testSetHairColor () {
159
+ // Arrange
160
+ ArrayList <String > expectedHairColor = new ArrayList <>();
161
+ expectedHairColor .add ("Brown" );
162
+ // Act
163
+ person .setHairColor (expectedHairColor );
164
+ // Assert
165
+ assertEquals (expectedHairColor , person .getHairColor ());
166
+ }
167
+
168
+ @ Test
166
169
public void testGetLifeStatus () {
167
170
// Act
168
171
String actualLifeStatus = person .getLifeStatus ();
@@ -184,12 +187,13 @@ public void testSetLifeStatus() {
184
187
185
188
@ Test
186
189
public void testGetPersonInfo () {
187
- String expectedPersonInfo = "Name: Chigazo| Gender Identity: Male| Race: African-American| Age: 20| Height(In meters): 1.8288| Hair Color: [Black, Purple]| Status: Alive" ;
188
-
190
+ String expectedPersonInfo =
191
+ "Name: Chigazo| Gender Identity: Male| Race: African-American| Age: 20| Height(In meters): 1.8288| Hair Color: [Black, Purple]| Status: Alive" ;
192
+
189
193
// Act
190
194
String actualPersonInfo = person .getPersonInfo ();
191
195
192
- //Assert
196
+ // Assert
193
197
assertEquals (expectedPersonInfo , actualPersonInfo );
194
198
}
195
199
}
0 commit comments