Skip to content

Commit 8c9515d

Browse files
committed
feat: add lesson16 custom class MakeupRoutine.java & test cases with exception handling
1 parent e830b23 commit 8c9515d

File tree

5 files changed

+136
-128
lines changed

5 files changed

+136
-128
lines changed
Lines changed: 82 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,82 @@
1+
package com.codedifferently.lesson16.oliviajames;
2+
3+
import java.util.ArrayList;
4+
import java.util.List;
5+
6+
public class MakeupRoutine {
7+
8+
public enum MakeupLook {
9+
DEWY,
10+
NATURAL,
11+
FULL_GLAM,
12+
SOFT_GLAM,
13+
}
14+
15+
// Member Variables
16+
private String name;
17+
private int time;
18+
private final boolean usesPrimer;
19+
private final MakeupLook lookType;
20+
List<String> vanityItems;
21+
22+
// Constructor
23+
public MakeupRoutine(String name, int time, boolean usesPrimer, MakeupLook lookType) {
24+
this.name = name;
25+
this.time = time;
26+
this.usesPrimer = true;
27+
this.lookType = lookType;
28+
}
29+
30+
// Getters/setters
31+
32+
public String getName() {
33+
return name;
34+
}
35+
36+
public void setName(String name) {
37+
this.name = name;
38+
}
39+
40+
public int getTime() {
41+
return time;
42+
}
43+
44+
public void setTime(int time) {
45+
this.time = time;
46+
}
47+
48+
public boolean getUsesPrimer() throws MissingPrimerException {
49+
if (!usesPrimer) {
50+
throw new MissingPrimerException("missing primer");
51+
}
52+
System.out.println("has primer");
53+
return true;
54+
}
55+
56+
public MakeupLook getLookType() {
57+
return lookType;
58+
}
59+
60+
public void MakeupVanity() {
61+
vanityItems = new ArrayList<>();
62+
vanityItems.add("Foundation");
63+
vanityItems.add("Concealer");
64+
vanityItems.add("Setting Powder");
65+
vanityItems.add("Blush");
66+
vanityItems.add("Highlighter");
67+
vanityItems.add("Eyeshadow Palette");
68+
vanityItems.add("Mascara");
69+
vanityItems.add("Eyeliner");
70+
vanityItems.add("Lipstick");
71+
vanityItems.add("Lip Gloss");
72+
vanityItems.add("Setting Spray");
73+
vanityItems.add("Makeup Brushes");
74+
}
75+
76+
public void showVanityItems() {
77+
System.out.println("Items on the vanity:");
78+
for (String item : vanityItems) {
79+
System.out.println("- " + item);
80+
}
81+
}
82+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.codedifferently.lesson16.oliviajames;
2+
3+
public class MissingPrimerException extends Exception {
4+
public MissingPrimerException(String message) {
5+
super(message);
6+
}
7+
}

lesson_16/objects/objects_app/src/main/oliviajames/MakeupRoutine.java

Lines changed: 0 additions & 78 deletions
This file was deleted.

lesson_16/objects/objects_app/src/main/oliviajames/StepMissingException.java

Lines changed: 0 additions & 9 deletions
This file was deleted.
Lines changed: 47 additions & 41 deletions
Original file line numberDiff line numberDiff line change
@@ -1,65 +1,71 @@
1-
package com.codedifferently.lesson16;
1+
package com.codedifferently.lesson16.oliviajames;
22

3+
import static org.assertj.core.api.Assertions.assertThat;
4+
import static org.junit.jupiter.api.Assertions.assertEquals;
5+
import static org.junit.jupiter.api.Assertions.assertFalse;
6+
import static org.junit.jupiter.api.Assertions.assertNotNull;
7+
import static org.junit.jupiter.api.Assertions.assertTrue;
38

9+
import com.codedifferently.lesson16.oliviajames.MakeupRoutine.MakeupLook;
10+
import org.junit.jupiter.api.BeforeEach;
411
import org.junit.jupiter.api.Test;
512

6-
public class MakeupRoutineTest{
13+
public class MakeupRoutineTest {
714

8-
MakeupRoutine makeupRoutine;
15+
MakeupRoutine makeupRoutine;
916

10-
@BeforeEach
11-
void setUp() {
12-
makeupRoutine = new MakeupRoutine("NARS", 60, true, "DEWY")
13-
}
17+
@BeforeEach
18+
void setUp() {
19+
makeupRoutine = new MakeupRoutine("NARS", 60, true, MakeupLook.FULL_GLAM);
20+
}
1421

1522
@Test
1623
void testgetName() {
17-
String actual = makeupRoutine.getName();
18-
19-
assertThat(actual).isEqualTo("NARS");
20-
}
21-
24+
String actual = makeupRoutine.getName();
2225

26+
assertThat(actual).isEqualTo("NARS");
27+
}
2328

29+
@Test
30+
public void testSetName() {
31+
makeupRoutine.setName("Night Out");
32+
assertEquals("Night Out", makeupRoutine.getName());
33+
}
2434

35+
@Test
36+
public void testGetTime() {
37+
assertEquals(60, makeupRoutine.getTime());
38+
}
2539

26-
/*public void testGetLook() {
27-
MakeupRoutine routine =
28-
new MakeupRoutine("Soft Glam", "Foundation", 5, GlamRank.SOFT_GLAM, 120.00);
29-
GlamRank expected = GlamRank.SOFT_GLAM;
30-
assertThat(routine.getRank()).isEqualTo(expected);
40+
@Test
41+
public void testSetTime() {
42+
makeupRoutine.setTime(45);
43+
assertEquals(45, makeupRoutine.getTime());
3144
}
3245

3346
@Test
34-
public void testSetBaseProduct() {
35-
MakeupRoutine routine =
36-
new MakeupRoutine("Natural", "BB Cream", 3, GlamRank.NATURAL_BADDIE, 85.50);
37-
routine.setBaseProduct("Tinted Moisturizer");
38-
String expected = "Tinted Moisturizer";
39-
assertThat(routine.getBaseProduct()).isEqualTo(expected);
47+
public void testGetLookType() {
48+
assertEquals(MakeupRoutine.MakeupLook.FULL_GLAM, makeupRoutine.getLookType());
4049
}
4150

4251
@Test
43-
public void testSetTotalCost() {
44-
MakeupRoutine routine =
45-
new MakeupRoutine("Full Glam", "Full Coverage Foundation", 8, GlamRank.FULL_GLAM, 200.00);
46-
routine.setTotalCost(220.00);
47-
double expected = 220.00;
48-
assertThat(routine.getTotalCost()).isEqualTo(expected);
52+
public void testGetUsesPrimer() {
53+
try {
54+
makeupRoutine.getUsesPrimer();
55+
} catch (MissingPrimerException e) {
56+
System.out.println(e.getMessage());
57+
}
4958
}
5059

5160
@Test
52-
public void testAddStep() {
53-
MakeupRoutine routine =
54-
new MakeupRoutine("Glow", "Light Coverage", 6, GlamRank.FULL_GLAM, 88.00);
55-
String step = "add mascara";
56-
routine.addStep(step);
57-
steps = routine.getSteps();
58-
if (steps.contains(step)) {
59-
System.out.println("Step add mascara is in the list");
61+
public void testShowVanityItems() {
62+
assertNotNull(makeupRoutine); // just to check vanityItems were initialized
63+
}
6064

61-
} else {
62-
System.out.println("Step add mascara is not in the list");
63-
}
64-
}*/
65+
@Test
66+
public void testMakeupVanityHasItems() {
67+
makeupRoutine.MakeupVanity();
68+
assertFalse(makeupRoutine.vanityItems.isEmpty());
69+
assertTrue(makeupRoutine.vanityItems.contains("Foundation"));
70+
}
6571
}

0 commit comments

Comments
 (0)