-
Notifications
You must be signed in to change notification settings - Fork 23
feat: add lesson16 custom class MakeupRoutine.java & test cases with exception handling #544
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Changes from all commits
Commits
Show all changes
3 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
82 changes: 82 additions & 0 deletions
82
...cts/objects_app/src/main/java/com/codedifferently/lesson16/oliviajames/MakeupRoutine.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,82 @@ | ||
package com.codedifferently.lesson16.oliviajames; | ||
|
||
import java.util.ArrayList; | ||
import java.util.List; | ||
|
||
public class MakeupRoutine { | ||
|
||
public enum MakeupLook { | ||
DEWY, | ||
NATURAL, | ||
FULL_GLAM, | ||
SOFT_GLAM, | ||
} | ||
|
||
// Member Variables | ||
private String name; | ||
private int time; | ||
private final boolean usesPrimer; | ||
private final MakeupLook lookType; | ||
List<String> vanityItems; | ||
|
||
// Constructor | ||
public MakeupRoutine(String name, int time, boolean usesPrimer, MakeupLook lookType) { | ||
this.name = name; | ||
this.time = time; | ||
this.usesPrimer = true; | ||
this.lookType = lookType; | ||
} | ||
|
||
// Getters/setters | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public int getTime() { | ||
return time; | ||
} | ||
|
||
public void setTime(int time) { | ||
this.time = time; | ||
} | ||
|
||
public boolean getUsesPrimer() throws MissingPrimerException { | ||
if (!usesPrimer) { | ||
throw new MissingPrimerException("missing primer"); | ||
} | ||
System.out.println("has primer"); | ||
return true; | ||
} | ||
|
||
public MakeupLook getLookType() { | ||
return lookType; | ||
} | ||
|
||
public void MakeupVanity() { | ||
vanityItems = new ArrayList<>(); | ||
vanityItems.add("Foundation"); | ||
vanityItems.add("Concealer"); | ||
vanityItems.add("Setting Powder"); | ||
vanityItems.add("Blush"); | ||
vanityItems.add("Highlighter"); | ||
vanityItems.add("Eyeshadow Palette"); | ||
vanityItems.add("Mascara"); | ||
vanityItems.add("Eyeliner"); | ||
vanityItems.add("Lipstick"); | ||
vanityItems.add("Lip Gloss"); | ||
vanityItems.add("Setting Spray"); | ||
vanityItems.add("Makeup Brushes"); | ||
} | ||
|
||
public void showVanityItems() { | ||
System.out.println("Items on the vanity:"); | ||
for (String item : vanityItems) { | ||
System.out.println("- " + item); | ||
} | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
...ts_app/src/main/java/com/codedifferently/lesson16/oliviajames/MissingPrimerException.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,7 @@ | ||
package com.codedifferently.lesson16.oliviajames; | ||
|
||
public class MissingPrimerException extends Exception { | ||
public MissingPrimerException(String message) { | ||
super(message); | ||
} | ||
} |
71 changes: 71 additions & 0 deletions
71
...objects_app/src/test/java/com/codedifferently/lesson16/oliviajames/MakeupRoutineTest.java
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,71 @@ | ||
package com.codedifferently.lesson16.oliviajames; | ||
|
||
import static org.assertj.core.api.Assertions.assertThat; | ||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
import static org.junit.jupiter.api.Assertions.assertFalse; | ||
import static org.junit.jupiter.api.Assertions.assertNotNull; | ||
import static org.junit.jupiter.api.Assertions.assertTrue; | ||
|
||
import com.codedifferently.lesson16.oliviajames.MakeupRoutine.MakeupLook; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class MakeupRoutineTest { | ||
|
||
MakeupRoutine makeupRoutine; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
makeupRoutine = new MakeupRoutine("NARS", 60, true, MakeupLook.FULL_GLAM); | ||
} | ||
|
||
@Test | ||
void testgetName() { | ||
String actual = makeupRoutine.getName(); | ||
|
||
assertThat(actual).isEqualTo("NARS"); | ||
} | ||
|
||
@Test | ||
public void testSetName() { | ||
makeupRoutine.setName("Night Out"); | ||
assertEquals("Night Out", makeupRoutine.getName()); | ||
} | ||
|
||
@Test | ||
public void testGetTime() { | ||
assertEquals(60, makeupRoutine.getTime()); | ||
} | ||
|
||
@Test | ||
public void testSetTime() { | ||
makeupRoutine.setTime(45); | ||
assertEquals(45, makeupRoutine.getTime()); | ||
} | ||
|
||
@Test | ||
public void testGetLookType() { | ||
assertEquals(MakeupRoutine.MakeupLook.FULL_GLAM, makeupRoutine.getLookType()); | ||
} | ||
|
||
@Test | ||
public void testGetUsesPrimer() { | ||
try { | ||
makeupRoutine.getUsesPrimer(); | ||
} catch (MissingPrimerException e) { | ||
System.out.println(e.getMessage()); | ||
} | ||
} | ||
|
||
@Test | ||
public void testShowVanityItems() { | ||
assertNotNull(makeupRoutine); // just to check vanityItems were initialized | ||
} | ||
|
||
@Test | ||
public void testMakeupVanityHasItems() { | ||
makeupRoutine.MakeupVanity(); | ||
assertFalse(makeupRoutine.vanityItems.isEmpty()); | ||
assertTrue(makeupRoutine.vanityItems.contains("Foundation")); | ||
} | ||
} |
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.