From b643a4c488a249f5da91b7765195f404c78c6f28 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Wed, 16 Oct 2024 15:19:05 +0000 Subject: [PATCH 1/9] feat: created chigazograham.json file --- .../main/resources/data/chigazograham.json | 92 +++++++++++++++++++ 1 file changed, 92 insertions(+) create mode 100644 lesson_09/types/types_app/src/main/resources/data/chigazograham.json diff --git a/lesson_09/types/types_app/src/main/resources/data/chigazograham.json b/lesson_09/types/types_app/src/main/resources/data/chigazograham.json new file mode 100644 index 000000000..292620c54 --- /dev/null +++ b/lesson_09/types/types_app/src/main/resources/data/chigazograham.json @@ -0,0 +1,92 @@ +[ + { + "column1": "ms1wuglcnp", + "column2": "true", + "column3": "6463003749233522688", + "column4": "2.7921879E38", + "column5": "8.442422875678673E307", + "column6": "4743", + "column7": "1270272283" + }, + { + "column1": "7awo0gh", + "column2": "false", + "column3": "7752118028902647808", + "column4": "2.6698281E38", + "column5": "5.605056226818231E307", + "column6": "23516", + "column7": "1704066280" + }, + { + "column1": "cserf78x02", + "column2": "false", + "column3": "2540472457630355968", + "column4": "1.5396288E38", + "column5": "1.50417665803363E308", + "column6": "14580", + "column7": "2114160244" + }, + { + "column1": "zgqnjh5", + "column2": "false", + "column3": "953741867660372224", + "column4": "2.2381432E38", + "column5": "2.493477176095576E307", + "column6": "26539", + "column7": "996751379" + }, + { + "column1": "s5iqo80h3c", + "column2": "false", + "column3": "5714943984670955520", + "column4": "1.932927E38", + "column5": "1.705202914715676E308", + "column6": "7442", + "column7": "1112427416" + }, + { + "column1": "wcuo0zxejh", + "column2": "false", + "column3": "2704740152448495104", + "column4": "1.0179288E38", + "column5": "1.393686380125556E308", + "column6": "32762", + "column7": "1881329776" + }, + { + "column1": "cnq9kjd6hiu", + "column2": "true", + "column3": "6206221245541992448", + "column4": "1.3631897E38", + "column5": "1.2956738103127734E308", + "column6": "30578", + "column7": "1147532001" + }, + { + "column1": "8z0bnd", + "column2": "false", + "column3": "4562348053081931776", + "column4": "1.4620677E38", + "column5": "2.044622864892074E307", + "column6": "17197", + "column7": "1094615070" + }, + { + "column1": "0vl9htqrw", + "column2": "false", + "column3": "6077936030977995776", + "column4": "1.7550462E38", + "column5": "4.752956293100593E307", + "column6": "12867", + "column7": "724629435" + }, + { + "column1": "6ur49", + "column2": "true", + "column3": "1339556241029906688", + "column4": "1.944709E38", + "column5": "9.16514287771922E307", + "column6": "20363", + "column7": "562533284" + } +] \ No newline at end of file From 68ccb5fae54e5e7c969f4a4ace4c2947e82813e1 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Wed, 16 Oct 2024 19:01:53 +0000 Subject: [PATCH 2/9] fix: deleted lesson_09 content from main; --- .../main/resources/data/chigazograham.json | 92 ------------------- 1 file changed, 92 deletions(-) delete mode 100644 lesson_09/types/types_app/src/main/resources/data/chigazograham.json diff --git a/lesson_09/types/types_app/src/main/resources/data/chigazograham.json b/lesson_09/types/types_app/src/main/resources/data/chigazograham.json deleted file mode 100644 index 292620c54..000000000 --- a/lesson_09/types/types_app/src/main/resources/data/chigazograham.json +++ /dev/null @@ -1,92 +0,0 @@ -[ - { - "column1": "ms1wuglcnp", - "column2": "true", - "column3": "6463003749233522688", - "column4": "2.7921879E38", - "column5": "8.442422875678673E307", - "column6": "4743", - "column7": "1270272283" - }, - { - "column1": "7awo0gh", - "column2": "false", - "column3": "7752118028902647808", - "column4": "2.6698281E38", - "column5": "5.605056226818231E307", - "column6": "23516", - "column7": "1704066280" - }, - { - "column1": "cserf78x02", - "column2": "false", - "column3": "2540472457630355968", - "column4": "1.5396288E38", - "column5": "1.50417665803363E308", - "column6": "14580", - "column7": "2114160244" - }, - { - "column1": "zgqnjh5", - "column2": "false", - "column3": "953741867660372224", - "column4": "2.2381432E38", - "column5": "2.493477176095576E307", - "column6": "26539", - "column7": "996751379" - }, - { - "column1": "s5iqo80h3c", - "column2": "false", - "column3": "5714943984670955520", - "column4": "1.932927E38", - "column5": "1.705202914715676E308", - "column6": "7442", - "column7": "1112427416" - }, - { - "column1": "wcuo0zxejh", - "column2": "false", - "column3": "2704740152448495104", - "column4": "1.0179288E38", - "column5": "1.393686380125556E308", - "column6": "32762", - "column7": "1881329776" - }, - { - "column1": "cnq9kjd6hiu", - "column2": "true", - "column3": "6206221245541992448", - "column4": "1.3631897E38", - "column5": "1.2956738103127734E308", - "column6": "30578", - "column7": "1147532001" - }, - { - "column1": "8z0bnd", - "column2": "false", - "column3": "4562348053081931776", - "column4": "1.4620677E38", - "column5": "2.044622864892074E307", - "column6": "17197", - "column7": "1094615070" - }, - { - "column1": "0vl9htqrw", - "column2": "false", - "column3": "6077936030977995776", - "column4": "1.7550462E38", - "column5": "4.752956293100593E307", - "column6": "12867", - "column7": "724629435" - }, - { - "column1": "6ur49", - "column2": "true", - "column3": "1339556241029906688", - "column4": "1.944709E38", - "column5": "9.16514287771922E307", - "column6": "20363", - "column7": "562533284" - } -] \ No newline at end of file From 44faa1c775afc406aef52b2aaac339b59f049744 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Thu, 31 Oct 2024 14:34:56 +0000 Subject: [PATCH 3/9] feat: added 7 member variables of 5 different types; added Person function; added 'get' function for each member variable; added set function for each variable; added throw arguement to getHairColor to distinguish if person is bald; added getNaturalHairColor function with loop to distinguish original hair color from dyed; added getPersonInfo function that returns the information of the person; --- .../lesson16/Person/Person.java | 119 ++++++++++++++++++ 1 file changed, 119 insertions(+) create mode 100644 lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java new file mode 100644 index 000000000..1c0e46081 --- /dev/null +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java @@ -0,0 +1,119 @@ +package com.codedifferently.lesson16; + +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 hairColor; + + + + public Person(String name, String sex, String race, int age, double height, ArrayList 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 getHairColor() { + if (hairColor == null) { + throw new IllegalArgumentException("No hair color? This person must be bald!"); + } + return hairColor; + } + + public void setHairColor(ArrayList hairColor) { + this.hairColor = hairColor; + } + + public ArrayList getNaturalHairColor() { + ArrayList naturalHairColor = new ArrayList<>(); + ArrayList 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(); + } +} From 72c5d806f12153e286d21894ed6170194038bdd2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Thu, 31 Oct 2024 15:03:41 +0000 Subject: [PATCH 4/9] feat: created framework for PersonTest; added try catch statement to getHairColor to change a null hair color to bald; fix: corrected grammar in getLifeStatus return statement strings; --- .../lesson16/Person/Person.java | 10 +++-- .../src/test/java/Person/PersonTest.java | 38 +++++++++++++++++++ 2 files changed, 45 insertions(+), 3 deletions(-) create mode 100644 lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java index 1c0e46081..e3dd4a49d 100644 --- a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java @@ -66,7 +66,11 @@ public void setHeight(double height) { public ArrayList getHairColor() { if (hairColor == null) { - throw new IllegalArgumentException("No hair color? This person must be bald!"); + try { + throw new IllegalArgumentException("No hair color? This person must be bald!"); + } catch (IllegalArgumentException e) { + hairColor.add("Bald"); + } } return hairColor; } @@ -97,9 +101,9 @@ public ArrayList getNaturalHairColor() { public String getLifeStatus() { if (alive == true) { - return "alive"; + return "Alive"; } else { - return "deceased"; + return "Deceased"; } } diff --git a/lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java b/lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java new file mode 100644 index 000000000..b2ab2d883 --- /dev/null +++ b/lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java @@ -0,0 +1,38 @@ +package com.codedifferently.lesson16; + +import static org.junit.jupiter.api.Assertions.assertEquals; + +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class PersonTest { + + Person person; + + // Set up + @BeforeEach + void setUp() { + person = new person(); + } + + @Test + // Method being tested + public void testGet() { + // Execersise + int actual = .get(); + + int expected = ; + // Assert(Checking the value) + assertEquals(expected, actual); + } + + @Test + public void testSet() { + // Arrange + int expectedSet = ; + // Act + person.set(expectedSet); + // Assert + assertEquals(expectedSet, person.get()); + } +} From 78efa0f3df242ad2284f4c3fa1d2bacd0bedd6a8 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Fri, 1 Nov 2024 14:48:41 +0000 Subject: [PATCH 5/9] feat: added .person to the package; added to ArrayList innstances; added isEmpty to .getHairColor function to check for null and empty arrays and change the hair color to bald; added '|' to seperate information in .getPersonInfo function; created PersonTest, imported nessesary data, and added PersonTest set up; added tests for all .get and .set functions; added exception testing for .getHairColor; --- .../lesson16/Person/Person.java | 237 +++++++++--------- .../src/test/java/Person/PersonTest.java | 38 --- .../lesson16/person/PersonTest.java | 195 ++++++++++++++ 3 files changed, 315 insertions(+), 155 deletions(-) delete mode 100644 lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java create mode 100644 lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java index e3dd4a49d..c00094bc5 100644 --- a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java @@ -1,123 +1,126 @@ -package com.codedifferently.lesson16; +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 hairColor; - - - - public Person(String name, String sex, String race, int age, double height, ArrayList 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 getHairColor() { - if (hairColor == null) { - try { - throw new IllegalArgumentException("No hair color? This person must be bald!"); - } catch (IllegalArgumentException e) { - hairColor.add("Bald"); - } - } - return hairColor; - } - - public void setHairColor(ArrayList hairColor) { - this.hairColor = hairColor; - } - - public ArrayList getNaturalHairColor() { - ArrayList naturalHairColor = new ArrayList<>(); - ArrayList 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(); - } + private String name; + private String sex; + private String race; + private int age; + private boolean alive; + private double height; + private ArrayList hairColor; + + public Person(String name, String sex, String race, int age, double height, ArrayList 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 getHairColor() { + if (hairColor == null || hairColor.isEmpty()) { + this.hairColor = new ArrayList<>(); + hairColor.add("Bald"); + throw new IllegalArgumentException("No hair color? This person must be bald!"); + } + return hairColor; + } + + public void setHairColor(ArrayList hairColor) { + this.hairColor = hairColor; + } + + public ArrayList getNaturalHairColor() { + ArrayList naturalHairColor = new ArrayList<>(); + ArrayList 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(); + } } diff --git a/lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java b/lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java deleted file mode 100644 index b2ab2d883..000000000 --- a/lesson_16/objects/objects_app/src/test/java/Person/PersonTest.java +++ /dev/null @@ -1,38 +0,0 @@ -package com.codedifferently.lesson16; - -import static org.junit.jupiter.api.Assertions.assertEquals; - -import org.junit.jupiter.api.BeforeEach; -import org.junit.jupiter.api.Test; - -public class PersonTest { - - Person person; - - // Set up - @BeforeEach - void setUp() { - person = new person(); - } - - @Test - // Method being tested - public void testGet() { - // Execersise - int actual = .get(); - - int expected = ; - // Assert(Checking the value) - assertEquals(expected, actual); - } - - @Test - public void testSet() { - // Arrange - int expectedSet = ; - // Act - person.set(expectedSet); - // Assert - assertEquals(expectedSet, person.get()); - } -} diff --git a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java new file mode 100644 index 000000000..198e99ab2 --- /dev/null +++ b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java @@ -0,0 +1,195 @@ +package com.codedifferently.lesson16.person; + +import java.util.ArrayList; + +import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; +import org.junit.jupiter.api.BeforeEach; +import org.junit.jupiter.api.Test; + +public class PersonTest { + + Person person; + + @BeforeEach + void setUp() { + ArrayList 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() { + // Act + ArrayList actualHairColor = person.getHairColor(); + // Arrange + ArrayList expectedHairColor = new ArrayList<>(); + expectedHairColor.add("Black"); + expectedHairColor.add("Purple"); + // Assert + assertEquals(expectedHairColor, actualHairColor); + } + + @Test + public void testGetHairColor__hairColorDoesNotExist() { + // Arrange + Person baldPerson = new Person("John", "Male", "Caucasian", 25, 1.75, null, true); + // Act + Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { + baldPerson.getHairColor(); + }); + // Assert + assertEquals("No hair color? This person must be bald!", exception.getMessage()); + } + + @Test + public void testGetNaturalHairColor() { + ArrayList expectedNaturalHairColor = new ArrayList<>(); + expectedNaturalHairColor.add("Black"); + ArrayList actualNaturalHairColor = person.getNaturalHairColor(); + assertEquals(expectedNaturalHairColor, actualNaturalHairColor); + } + + @Test + public void testSetHairColor() { + // Arrange + ArrayList 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); + } +} From 25a65dd5d8aa9a9a8bcb3849b323479be2eedb57 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Fri, 1 Nov 2024 14:54:45 +0000 Subject: [PATCH 6/9] fix: ran ./gradlew spotlessapply to correct formating mistakes; --- .../java/com/codedifferently/lesson16/Person/Person.java | 9 ++++++++- 1 file changed, 8 insertions(+), 1 deletion(-) diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java index c00094bc5..4fb64b85b 100644 --- a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java @@ -12,7 +12,14 @@ public class Person { private double height; private ArrayList hairColor; - public Person(String name, String sex, String race, int age, double height, ArrayList hairColor, boolean alive) { + public Person( + String name, + String sex, + String race, + int age, + double height, + ArrayList hairColor, + boolean alive) { this.name = name; this.sex = sex; this.race = race; From 6765a0bcefe07434a2536a19b19df37e2f5948c3 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Fri, 1 Nov 2024 14:59:22 +0000 Subject: [PATCH 7/9] fix: ran ./gradlew :objects_app:spotlessApply to correct formating mistakes; --- .../lesson16/person/PersonTest.java | 322 +++++++++--------- 1 file changed, 163 insertions(+), 159 deletions(-) diff --git a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java index 198e99ab2..b39d11606 100644 --- a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java +++ b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java @@ -1,168 +1,171 @@ package com.codedifferently.lesson16.person; -import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.ArrayList; import org.junit.jupiter.api.Assertions; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; public class PersonTest { - Person person; - - @BeforeEach - void setUp() { - ArrayList 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() { - // Act - ArrayList actualHairColor = person.getHairColor(); - // Arrange - ArrayList expectedHairColor = new ArrayList<>(); - expectedHairColor.add("Black"); - expectedHairColor.add("Purple"); - // Assert - assertEquals(expectedHairColor, actualHairColor); - } - - @Test - public void testGetHairColor__hairColorDoesNotExist() { - // Arrange - Person baldPerson = new Person("John", "Male", "Caucasian", 25, 1.75, null, true); - // Act - Exception exception = Assertions.assertThrows(IllegalArgumentException.class, () -> { - baldPerson.getHairColor(); - }); - // Assert - assertEquals("No hair color? This person must be bald!", exception.getMessage()); - } - - @Test - public void testGetNaturalHairColor() { - ArrayList expectedNaturalHairColor = new ArrayList<>(); - expectedNaturalHairColor.add("Black"); - ArrayList actualNaturalHairColor = person.getNaturalHairColor(); - assertEquals(expectedNaturalHairColor, actualNaturalHairColor); - } - - @Test - public void testSetHairColor() { - // Arrange - ArrayList expectedHairColor = new ArrayList<>(); - expectedHairColor.add("Brown"); - // Act - person.setHairColor(expectedHairColor); - // Assert - assertEquals(expectedHairColor, person.getHairColor()); - } - - @Test + Person person; + + @BeforeEach + void setUp() { + ArrayList 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() { + // Act + ArrayList actualHairColor = person.getHairColor(); + // Arrange + ArrayList expectedHairColor = new ArrayList<>(); + expectedHairColor.add("Black"); + expectedHairColor.add("Purple"); + // Assert + assertEquals(expectedHairColor, actualHairColor); + } + + @Test + public void testGetHairColor__hairColorDoesNotExist() { + // Arrange + Person baldPerson = new Person("John", "Male", "Caucasian", 25, 1.75, null, true); + // Act + Exception exception = + Assertions.assertThrows( + IllegalArgumentException.class, + () -> { + baldPerson.getHairColor(); + }); + // Assert + assertEquals("No hair color? This person must be bald!", exception.getMessage()); + } + + @Test + public void testGetNaturalHairColor() { + ArrayList expectedNaturalHairColor = new ArrayList<>(); + expectedNaturalHairColor.add("Black"); + ArrayList actualNaturalHairColor = person.getNaturalHairColor(); + assertEquals(expectedNaturalHairColor, actualNaturalHairColor); + } + + @Test + public void testSetHairColor() { + // Arrange + ArrayList expectedHairColor = new ArrayList<>(); + expectedHairColor.add("Brown"); + // Act + person.setHairColor(expectedHairColor); + // Assert + assertEquals(expectedHairColor, person.getHairColor()); + } + + @Test public void testGetLifeStatus() { // Act String actualLifeStatus = person.getLifeStatus(); @@ -184,12 +187,13 @@ public void testSetLifeStatus() { @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"; - + 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 + // Assert assertEquals(expectedPersonInfo, actualPersonInfo); } } From a2e36d3d515cb8e0c644af15bf4774282e6f8d46 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Fri, 1 Nov 2024 18:37:05 +0000 Subject: [PATCH 8/9] fix: changed IllegalArgumentException to custom PersonIsBaldException; --- .../com/codedifferently/lesson16/Person/Person.java | 4 ++-- .../lesson16/Person/PersonIsBaldException.java | 7 +++++++ .../codedifferently/lesson16/person/PersonTest.java | 12 ++++++------ 3 files changed, 15 insertions(+), 8 deletions(-) create mode 100644 lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java index 4fb64b85b..e5329172f 100644 --- a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/Person.java @@ -69,11 +69,11 @@ public void setHeight(double height) { this.height = height; } - public ArrayList getHairColor() { + public ArrayList getHairColor() throws PersonIsBaldException { if (hairColor == null || hairColor.isEmpty()) { this.hairColor = new ArrayList<>(); hairColor.add("Bald"); - throw new IllegalArgumentException("No hair color? This person must be bald!"); + throw new PersonIsBaldException("No hair color? This person must be bald!"); } return hairColor; } diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java new file mode 100644 index 000000000..a29cc2b19 --- /dev/null +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java @@ -0,0 +1,7 @@ +package com.codedifferently.lesson16.person; + +class PersonIsBaldException extends Exception { + public PersonIsBaldException(String message) { + super(message); + } +} \ No newline at end of file diff --git a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java index b39d11606..d46004dd8 100644 --- a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java +++ b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java @@ -1,9 +1,9 @@ package com.codedifferently.lesson16.person; -import static org.junit.jupiter.api.Assertions.assertEquals; - import java.util.ArrayList; + import org.junit.jupiter.api.Assertions; +import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test; @@ -120,7 +120,7 @@ public void testSetHeight() { } @Test - public void testGetHairColor() { + public void testGetHairColor() throws PersonIsBaldException { // Act ArrayList actualHairColor = person.getHairColor(); // Arrange @@ -132,13 +132,13 @@ public void testGetHairColor() { } @Test - public void testGetHairColor__hairColorDoesNotExist() { + public void testGetHairColor__hairColorDoesNotExist() throws PersonIsBaldException { // Arrange Person baldPerson = new Person("John", "Male", "Caucasian", 25, 1.75, null, true); // Act Exception exception = Assertions.assertThrows( - IllegalArgumentException.class, + PersonIsBaldException.class, () -> { baldPerson.getHairColor(); }); @@ -155,7 +155,7 @@ public void testGetNaturalHairColor() { } @Test - public void testSetHairColor() { + public void testSetHairColor() throws PersonIsBaldException { // Arrange ArrayList expectedHairColor = new ArrayList<>(); expectedHairColor.add("Brown"); From 5d47096b1964d28b9364f5f1b66996495fa2ff56 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E2=80=9CA1-4U2T1NN=E2=80=9D?= <“a1.austinn19@gmail.com”> Date: Fri, 1 Nov 2024 18:40:42 +0000 Subject: [PATCH 9/9] fix: ran ./gradlew :objects:spotlessApply to correct formating mistakes; --- .../lesson16/Person/PersonIsBaldException.java | 2 +- .../java/com/codedifferently/lesson16/person/PersonTest.java | 4 ++-- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java index a29cc2b19..dbbe7c70f 100644 --- a/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java +++ b/lesson_16/objects/objects_app/src/main/java/com/codedifferently/lesson16/Person/PersonIsBaldException.java @@ -4,4 +4,4 @@ class PersonIsBaldException extends Exception { public PersonIsBaldException(String message) { super(message); } -} \ No newline at end of file +} diff --git a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java index d46004dd8..92c7260a1 100644 --- a/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java +++ b/lesson_16/objects/objects_app/src/test/java/com/codedifferently/lesson16/person/PersonTest.java @@ -1,9 +1,9 @@ package com.codedifferently.lesson16.person; -import java.util.ArrayList; +import static org.junit.jupiter.api.Assertions.assertEquals; +import java.util.ArrayList; import org.junit.jupiter.api.Assertions; -import static org.junit.jupiter.api.Assertions.assertEquals; import org.junit.jupiter.api.BeforeEach; import org.junit.jupiter.api.Test;