Skip to content

Commit b7346d1

Browse files
committed
feat: refactor Party and PartyException classes; add unit tests for Party and Vibe
1 parent 4e5de26 commit b7346d1

File tree

6 files changed

+263
-179
lines changed

6 files changed

+263
-179
lines changed

lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/ezranyabuti/Party.java

Lines changed: 0 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -13,11 +13,6 @@ public class Party {
1313
private Vibe vibe;
1414
private ArrayList<String> guestList;
1515

16-
public Party() {
17-
this.guestList = new ArrayList<>();
18-
this.ticketNumber = 10;
19-
}
20-
2116
public Party(
2217
String name,
2318
String location,
@@ -103,12 +98,4 @@ public ArrayList<String> getGuestList() {
10398
public void setGuestList(ArrayList<String> guestList) {
10499
this.guestList = guestList;
105100
}
106-
107-
public void addGuest(String guest) throws PartyException {
108-
if (guestList.size() < ticketNumber) {
109-
guestList.add(guest);
110-
} else {
111-
throw new PartyException("Party is full");
112-
}
113-
}
114101
}
Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,8 +5,6 @@
55
import org.junit.jupiter.api.Test;
66
import org.springframework.boot.test.context.SpringBootTest;
77

8-
import com.codedifferently.lesson16.Lesson16;
9-
108
@SpringBootTest(useMainMethod = SpringBootTest.UseMainMethod.WHEN_AVAILABLE)
119
class Lesson16Test {
1210

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,10 @@
1-
package test.java.com.codedifferently.lesson16.ezranyabuti;
1+
package com.codedifferently.lesson16.ezranyabuti;
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import com.codedifferently.lesson16.ezranyabuti.PartyException;
65
import org.junit.jupiter.api.Test;
76

87
public class PartyExceptionTest {
9-
// Test for the constructor
108
@Test
119
void testConstructor() {
1210
String expectedMessage = "Party is not private";
Lines changed: 261 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,261 @@
1+
package com.codedifferently.lesson16.ezranyabuti;
2+
3+
import static org.assertj.core.api.Assertions.assertThat;
4+
5+
import java.util.ArrayList;
6+
import java.util.Arrays;
7+
import org.junit.jupiter.api.Test;
8+
9+
public class PartyTest {
10+
11+
@Test
12+
void testGetName() {
13+
Party party =
14+
new Party(
15+
"Everyday People",
16+
"Washington D.C.",
17+
"2025-06-012",
18+
false,
19+
50.0,
20+
0,
21+
Vibe.CHILL,
22+
new String[] {});
23+
String expectedName = "Everyday People";
24+
party.setName(expectedName);
25+
String actualName = party.getName();
26+
assertThat(actualName).isEqualTo(expectedName);
27+
}
28+
29+
@Test
30+
void testGetlocalDate() {
31+
Party party =
32+
new Party(
33+
"Everyday People",
34+
"Washington D.C.",
35+
"2025-06-012",
36+
false,
37+
50.0,
38+
0,
39+
Vibe.CHILL,
40+
new String[] {});
41+
String expectedDate = "2025-06-012";
42+
party.setLocalDate(expectedDate);
43+
String actualDate = party.getLocalDate();
44+
assertThat(actualDate).isEqualTo(expectedDate);
45+
}
46+
47+
@Test
48+
void testGetCoverCharge() {
49+
Party party =
50+
new Party(
51+
"Everyday People",
52+
"Washington D.C.",
53+
"2025-06-012",
54+
false,
55+
50.0,
56+
0,
57+
Vibe.CHILL,
58+
new String[] {});
59+
Double expectedCharge = 50.0;
60+
party.setCoverCharge(expectedCharge);
61+
Double actualCharge = party.getCoverCharge();
62+
assertThat(actualCharge).isEqualTo(expectedCharge);
63+
}
64+
65+
@Test
66+
void testGetVibe() {
67+
Party party =
68+
new Party(
69+
"Everyday People",
70+
"Washington D.C.",
71+
"2025-06-012",
72+
false,
73+
50.0,
74+
0,
75+
Vibe.CHILL,
76+
new String[] {});
77+
Vibe expectedVibe = Vibe.CHILL;
78+
party.setVibe(expectedVibe);
79+
Vibe actualVibe = party.getVibe();
80+
assertThat(actualVibe).isEqualTo(expectedVibe);
81+
}
82+
83+
@Test
84+
void testSetVibe() {
85+
Party party =
86+
new Party(
87+
"Everyday People",
88+
"Washington D.C.",
89+
"2025-06-012",
90+
false,
91+
50.0,
92+
0,
93+
Vibe.CHILL,
94+
new String[] {});
95+
}
96+
97+
@Test
98+
void testSetName() {
99+
Party party =
100+
new Party(
101+
"Everyday People",
102+
"Washington D.C.",
103+
"2025-06-012",
104+
false,
105+
50.0,
106+
0,
107+
Vibe.CHILL,
108+
new String[] {});
109+
String expectedName = "Everyday People";
110+
party.setName(expectedName);
111+
String actualName = party.getName();
112+
assertThat(actualName).isEqualTo(expectedName);
113+
}
114+
115+
@Test
116+
void testSetLocation() {
117+
Party party =
118+
new Party(
119+
"Everyday People",
120+
"Washington D.C.",
121+
"2025-06-012",
122+
false,
123+
50.0,
124+
0,
125+
Vibe.CHILL,
126+
new String[] {});
127+
String expectedLocation = "Brooklyn";
128+
party.setLocation(expectedLocation);
129+
String actualLocation = party.getLocation();
130+
assertThat(actualLocation).isEqualTo(expectedLocation);
131+
}
132+
133+
@Test
134+
void testGetLocation() {
135+
Party party =
136+
new Party(
137+
"Everyday People",
138+
"Washington D.C.",
139+
"2025-06-012",
140+
false,
141+
50.0,
142+
0,
143+
Vibe.CHILL,
144+
new String[] {});
145+
String expectedLocation = "Brooklyn";
146+
party.setLocation(expectedLocation);
147+
String actualLocation = party.getLocation();
148+
assertThat(actualLocation).isEqualTo(expectedLocation);
149+
}
150+
151+
@Test
152+
void testGetPrivate() {
153+
Party party =
154+
new Party(
155+
"Everyday People",
156+
"Washington D.C.",
157+
"2025-06-012",
158+
false,
159+
50.0,
160+
0,
161+
Vibe.CHILL,
162+
new String[] {});
163+
Boolean expectedPrivate = false;
164+
party.setIsPrivate(expectedPrivate);
165+
Boolean actualPrivate = party.getIsPrivate();
166+
assertThat(actualPrivate).isEqualTo(expectedPrivate);
167+
}
168+
169+
@Test
170+
void testSetPrivate() {
171+
Party party =
172+
new Party(
173+
"Everyday People",
174+
"Washington D.C.",
175+
"2025-06-012",
176+
false,
177+
50.0,
178+
0,
179+
Vibe.CHILL,
180+
new String[] {});
181+
Boolean expectedPrivate = true;
182+
party.setIsPrivate(expectedPrivate);
183+
Boolean actualPrivate = party.getIsPrivate();
184+
assertThat(actualPrivate).isEqualTo(expectedPrivate);
185+
}
186+
187+
@Test
188+
void testCoverCharge() {
189+
Party party =
190+
new Party(
191+
"Everyday People",
192+
"Washington D.C.",
193+
"2025-06-012",
194+
false,
195+
50.0,
196+
0,
197+
Vibe.CHILL,
198+
new String[] {});
199+
Double expectedCharge = 50.0;
200+
party.setCoverCharge(expectedCharge);
201+
Double actualCharge = party.getCoverCharge();
202+
assertThat(actualCharge).isEqualTo(expectedCharge);
203+
}
204+
205+
@Test
206+
void testGetTicketNum() {
207+
Party party =
208+
new Party(
209+
"Everyday People",
210+
"Washington D.C.",
211+
"2025-06-012",
212+
false,
213+
50.0,
214+
0,
215+
Vibe.CHILL,
216+
new String[] {});
217+
int expectedNum = 10;
218+
party.setTicketNumber(expectedNum);
219+
int actualTicketNumber = party.getTicketNumber();
220+
assertThat(actualTicketNumber).isEqualTo(expectedNum);
221+
}
222+
223+
@Test
224+
void testSetTicketNum() {
225+
Party party =
226+
new Party(
227+
"Everyday People",
228+
"Washington D.C.",
229+
"2025-06-012",
230+
false,
231+
50.0,
232+
0,
233+
Vibe.CHILL,
234+
new String[] {});
235+
int expectedNum = 10;
236+
party.setTicketNumber(expectedNum);
237+
int actualTicketNumber = party.getTicketNumber();
238+
assertThat(actualTicketNumber).isEqualTo(expectedNum);
239+
}
240+
241+
@Test
242+
void testGuestList() {
243+
Party party =
244+
new Party(
245+
"Everyday People",
246+
"Washington D.C.",
247+
"2025-06-012",
248+
false,
249+
50.0,
250+
0,
251+
Vibe.CHILL,
252+
new String[] {});
253+
String[] expectedGuestList = {"Meiko", "Ezra", "Bryana", "Justin"};
254+
255+
ArrayList<String> guestList = new ArrayList<>(Arrays.asList(expectedGuestList));
256+
party.setGuestList(guestList);
257+
258+
ArrayList<String> actualGuestList = party.getGuestList();
259+
assertThat(actualGuestList).isEqualTo(new ArrayList<>(Arrays.asList(expectedGuestList)));
260+
}
261+
}
Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,7 @@
1-
package test.java.com.codedifferently.lesson16.ezranyabuti;
1+
package com.codedifferently.lesson16.ezranyabuti;
22

33
import static org.assertj.core.api.Assertions.assertThat;
44

5-
import com.codedifferently.lesson16.ezranyabuti.Vibe;
65
import org.junit.jupiter.api.Test;
76

87
public class VibeTest {

0 commit comments

Comments
 (0)