-
Notifications
You must be signed in to change notification settings - Fork 25
Feat: Created Chigazo's Lesson 16 Custom {Class}, Custom {Class} Exception, and {Class}Test; #520
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
46 commits
Select commit
Hold shift + click to select a range
887b8f0
Merge pull request #1 from code-differently/main
A1-4U2T1NN 05ad627
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5715b6a
Merge branch 'code-differently:main' into main
A1-4U2T1NN 6c909b0
Merge branch 'code-differently:main' into main
A1-4U2T1NN 4c1a3f2
Merge branch 'code-differently:main' into main
A1-4U2T1NN de19403
Merge branch 'code-differently:main' into main
A1-4U2T1NN 56aa83d
Merge branch 'code-differently:main' into main
A1-4U2T1NN 8529105
Merge branch 'code-differently:main' into main
A1-4U2T1NN 4f76813
Merge branch 'code-differently:main' into main
A1-4U2T1NN 48bf962
Merge branch 'code-differently:main' into main
A1-4U2T1NN 1da88b9
Merge branch 'code-differently:main' into main
A1-4U2T1NN 3068765
Merge branch 'code-differently:main' into main
A1-4U2T1NN 712efd6
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5db7413
Merge branch 'code-differently:main' into main
A1-4U2T1NN 5096f8e
Merge branch 'code-differently:main' into main
A1-4U2T1NN 09341aa
Merge branch 'code-differently:main' into main
A1-4U2T1NN a8f634e
Merge branch 'code-differently:main' into main
A1-4U2T1NN b643a4c
feat: created chigazograham.json file
cae2152
Merge branch 'code-differently:main' into main
A1-4U2T1NN 68ccb5f
fix: deleted lesson_09 content from main;
7d4f86f
Merge branch 'code-differently:main' into main
A1-4U2T1NN 473eb98
Merge branch 'code-differently:main' into main
A1-4U2T1NN 1d19106
Merge branch 'code-differently:main' into main
A1-4U2T1NN bba5af5
Merge branch 'code-differently:main' into main
A1-4U2T1NN a51c852
Merge branch 'code-differently:main' into main
A1-4U2T1NN 8a39fcc
Merge branch 'code-differently:main' into main
A1-4U2T1NN ac98745
Merge branch 'code-differently:main' into main
A1-4U2T1NN eade00f
Merge branch 'code-differently:main' into main
A1-4U2T1NN bf252ad
Merge branch 'code-differently:main' into main
A1-4U2T1NN 955b86f
Merge branch 'code-differently:main' into main
A1-4U2T1NN b6f63bd
Merge branch 'code-differently:main' into main
A1-4U2T1NN 22db65b
Merge branch 'code-differently:main' into main
A1-4U2T1NN d5eff9e
Merge branch 'code-differently:main' into main
A1-4U2T1NN 2a09493
Merge branch 'code-differently:main' into main
A1-4U2T1NN 33e9bbc
Merge branch 'code-differently:main' into main
A1-4U2T1NN f6f3267
Merge branch 'code-differently:main' into main
A1-4U2T1NN 44faa1c
feat: added 7 member variables of 5 different types; added Person fun…
72c5d80
feat: created framework for PersonTest; added try catch statement to …
ad7ec4c
Merge branch 'code-differently:main' into lesson_16
A1-4U2T1NN 78efa0f
feat: added .person to the package; added <String> to ArrayList innst…
70a83f0
Merge branch 'code-differently:main' into lesson_16
A1-4U2T1NN 25a65dd
fix: ran ./gradlew spotlessapply to correct formating mistakes;
1c83b51
Merge branch 'lesson_16' of https://github.com/A1-4U2T1NN/code-differ…
6765a0b
fix: ran ./gradlew :objects_app:spotlessApply to correct formating mi…
a2e36d3
fix: changed IllegalArgumentException to custom PersonIsBaldException;
5d47096
fix: ran ./gradlew :objects:spotlessApply to correct formating mistakes;
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
133 changes: 133 additions & 0 deletions
133
lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.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,133 @@ | ||
package com.codedifferently.lesson16.person; | ||
|
||
import java.util.ArrayList; | ||
|
||
public class Person { | ||
|
||
private String name; | ||
private String sex; | ||
private String race; | ||
private int age; | ||
private boolean alive; | ||
private double height; | ||
private ArrayList<String> hairColor; | ||
|
||
public Person( | ||
String name, | ||
String sex, | ||
String race, | ||
int age, | ||
double height, | ||
ArrayList<String> hairColor, | ||
boolean alive) { | ||
this.name = name; | ||
this.sex = sex; | ||
this.race = race; | ||
this.age = age; | ||
this.height = height; | ||
this.hairColor = hairColor; | ||
this.alive = alive; | ||
} | ||
|
||
public String getName() { | ||
return name; | ||
} | ||
|
||
public void setName(String name) { | ||
this.name = name; | ||
} | ||
|
||
public String getSex() { | ||
return sex; | ||
} | ||
|
||
public void setSex(String sex) { | ||
this.sex = sex; | ||
} | ||
|
||
public String getRace() { | ||
return race; | ||
} | ||
|
||
public void setRace(String race) { | ||
this.race = race; | ||
} | ||
|
||
public int getAge() { | ||
return age; | ||
} | ||
|
||
public void setAge(int age) { | ||
this.age = age; | ||
} | ||
|
||
public double getHeight() { | ||
return height; | ||
} | ||
|
||
public void setHeight(double height) { | ||
this.height = height; | ||
} | ||
|
||
public ArrayList<String> getHairColor() throws PersonIsBaldException { | ||
if (hairColor == null || hairColor.isEmpty()) { | ||
this.hairColor = new ArrayList<>(); | ||
hairColor.add("Bald"); | ||
throw new PersonIsBaldException("No hair color? This person must be bald!"); | ||
} | ||
return hairColor; | ||
} | ||
|
||
public void setHairColor(ArrayList<String> hairColor) { | ||
this.hairColor = hairColor; | ||
} | ||
|
||
public ArrayList<String> getNaturalHairColor() { | ||
ArrayList<String> naturalHairColor = new ArrayList<>(); | ||
ArrayList<String> possibleNaturalColor = new ArrayList<>(); | ||
possibleNaturalColor.add("Black"); | ||
possibleNaturalColor.add("Brown"); | ||
possibleNaturalColor.add("Blonde"); | ||
possibleNaturalColor.add("Ginger"); | ||
possibleNaturalColor.add("Auburn"); | ||
possibleNaturalColor.add("Albino"); | ||
possibleNaturalColor.add("Grey"); | ||
|
||
for (String color : hairColor) { | ||
if (possibleNaturalColor.contains(color)) { | ||
naturalHairColor.add(color); | ||
break; | ||
} | ||
} | ||
return naturalHairColor; | ||
} | ||
|
||
public String getLifeStatus() { | ||
if (alive == true) { | ||
return "Alive"; | ||
} else { | ||
return "Deceased"; | ||
} | ||
} | ||
|
||
public void setLifeStatus(boolean alive) { | ||
this.alive = alive; | ||
} | ||
|
||
public String getPersonInfo() { | ||
return "Name: " | ||
+ name | ||
+ "| Gender Identity: " | ||
+ sex | ||
+ "| Race: " | ||
+ race | ||
+ "| Age: " | ||
+ age | ||
+ "| Height(In meters): " | ||
+ height | ||
+ "| Hair Color: " | ||
+ hairColor | ||
+ "| Status: " | ||
+ getLifeStatus(); | ||
} | ||
} |
7 changes: 7 additions & 0 deletions
7
.../objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.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.person; | ||
|
||
class PersonIsBaldException extends Exception { | ||
public PersonIsBaldException(String message) { | ||
super(message); | ||
} | ||
} |
199 changes: 199 additions & 0 deletions
199
..._16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.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,199 @@ | ||
package com.codedifferently.lesson16.person; | ||
|
||
import static org.junit.jupiter.api.Assertions.assertEquals; | ||
|
||
import java.util.ArrayList; | ||
import org.junit.jupiter.api.Assertions; | ||
import org.junit.jupiter.api.BeforeEach; | ||
import org.junit.jupiter.api.Test; | ||
|
||
public class PersonTest { | ||
|
||
Person person; | ||
|
||
@BeforeEach | ||
void setUp() { | ||
ArrayList<String> hairColor = new ArrayList<>(); | ||
hairColor.add("Black"); | ||
hairColor.add("Purple"); | ||
person = new Person("Chigazo", "Male", "African-American", 20, 1.8288, hairColor, true); | ||
} | ||
|
||
@Test | ||
public void testGetName() { | ||
// Act | ||
String actualName = person.getName(); | ||
// Arrange | ||
String expectedName = "Chigazo"; | ||
// Assert | ||
assertEquals(expectedName, actualName); | ||
} | ||
|
||
@Test | ||
public void testSetName() { | ||
// Arrange | ||
String expectedSet = "Austin"; | ||
// Act | ||
person.setName(expectedSet); | ||
// Assert | ||
assertEquals(expectedSet, person.getName()); | ||
} | ||
|
||
@Test | ||
public void testGetSex() { | ||
// Act | ||
String actualSex = person.getSex(); | ||
// Arrange | ||
String expectedSex = "Male"; | ||
// Assert(Checking the value) | ||
assertEquals(expectedSex, actualSex); | ||
} | ||
|
||
@Test | ||
public void testSetSex() { | ||
// Arrange | ||
String expectedSex = "Female"; | ||
// Act | ||
person.setSex(expectedSex); | ||
// Assert | ||
assertEquals(expectedSex, person.getSex()); | ||
} | ||
|
||
@Test | ||
public void testGetRace() { | ||
// Act | ||
String actualRace = person.getRace(); | ||
// Arrange | ||
String expectedRace = "African-American"; | ||
// Assert(Checking the value) | ||
assertEquals(expectedRace, actualRace); | ||
} | ||
|
||
@Test | ||
public void testSetRace() { | ||
// Arrange | ||
String expectedRace = "Asian"; | ||
// Act | ||
person.setRace(expectedRace); | ||
// Assert | ||
assertEquals(expectedRace, person.getRace()); | ||
} | ||
|
||
@Test | ||
public void testGetAge() { | ||
// Act | ||
int actualAge = person.getAge(); | ||
// Arrange | ||
int expectedAge = 20; | ||
// Assert(Checking the value) | ||
assertEquals(expectedAge, actualAge); | ||
} | ||
|
||
@Test | ||
public void testSetAge() { | ||
// Arrange | ||
int expectedAge = 21; | ||
// Act | ||
person.setAge(expectedAge); | ||
// Assert | ||
assertEquals(expectedAge, person.getAge()); | ||
} | ||
|
||
@Test | ||
public void testGetHeight() { | ||
// Act | ||
double actualHeight = person.getHeight(); | ||
// Arrange | ||
double expectedHeight = 1.8288; | ||
// Assert(Checking the value) | ||
assertEquals(expectedHeight, actualHeight); | ||
} | ||
|
||
@Test | ||
public void testSetHeight() { | ||
// Arrange | ||
double expectedHeight = 1.92024; | ||
// Act | ||
person.setHeight(expectedHeight); | ||
// Assert | ||
assertEquals(expectedHeight, person.getHeight()); | ||
} | ||
|
||
@Test | ||
public void testGetHairColor() throws PersonIsBaldException { | ||
// Act | ||
ArrayList<String> actualHairColor = person.getHairColor(); | ||
// Arrange | ||
ArrayList<String> expectedHairColor = new ArrayList<>(); | ||
expectedHairColor.add("Black"); | ||
expectedHairColor.add("Purple"); | ||
// Assert | ||
assertEquals(expectedHairColor, actualHairColor); | ||
} | ||
|
||
@Test | ||
public void testGetHairColor__hairColorDoesNotExist() throws PersonIsBaldException { | ||
// Arrange | ||
Person baldPerson = new Person("John", "Male", "Caucasian", 25, 1.75, null, true); | ||
// Act | ||
Exception exception = | ||
Assertions.assertThrows( | ||
PersonIsBaldException.class, | ||
() -> { | ||
baldPerson.getHairColor(); | ||
}); | ||
// Assert | ||
assertEquals("No hair color? This person must be bald!", exception.getMessage()); | ||
} | ||
|
||
@Test | ||
public void testGetNaturalHairColor() { | ||
ArrayList<String> expectedNaturalHairColor = new ArrayList<>(); | ||
expectedNaturalHairColor.add("Black"); | ||
ArrayList<String> actualNaturalHairColor = person.getNaturalHairColor(); | ||
assertEquals(expectedNaturalHairColor, actualNaturalHairColor); | ||
} | ||
|
||
@Test | ||
public void testSetHairColor() throws PersonIsBaldException { | ||
// Arrange | ||
ArrayList<String> expectedHairColor = new ArrayList<>(); | ||
expectedHairColor.add("Brown"); | ||
// Act | ||
person.setHairColor(expectedHairColor); | ||
// Assert | ||
assertEquals(expectedHairColor, person.getHairColor()); | ||
} | ||
|
||
@Test | ||
public void testGetLifeStatus() { | ||
// Act | ||
String actualLifeStatus = person.getLifeStatus(); | ||
// Arrange | ||
String expectedHairColor = "Alive"; | ||
// Assert | ||
assertEquals(expectedHairColor, actualLifeStatus); | ||
} | ||
|
||
@Test | ||
public void testSetLifeStatus() { | ||
// Arrange | ||
boolean expectedLifeStatus = false; | ||
// Act | ||
person.setLifeStatus(expectedLifeStatus); | ||
// Assert | ||
assertEquals("Deceased", person.getLifeStatus()); | ||
} | ||
|
||
@Test | ||
public void testGetPersonInfo() { | ||
String expectedPersonInfo = | ||
"Name: Chigazo| Gender Identity: Male| Race: African-American| Age: 20| Height(In meters): 1.8288| Hair Color: [Black, Purple]| Status: Alive"; | ||
|
||
// Act | ||
String actualPersonInfo = person.getPersonInfo(); | ||
|
||
// Assert | ||
assertEquals(expectedPersonInfo, actualPersonInfo); | ||
} | ||
} |
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.