From f1a98a59b67963fbec4733956fb87ac30baf0d5a Mon Sep 17 00:00:00 2001 From: jgiroso Date: Sat, 10 Jul 2021 10:16:02 -0400 Subject: [PATCH 1/3] part1 mostly complete --- .../java/rocks/zipcodewilmington/Food.java | 11 +++ .../rocks/zipcodewilmington/animals/Cat.java | 8 +++ .../rocks/zipcodewilmington/animals/Dog.java | 9 ++- .../zipcodewilmington/animals/Mammal.java | 13 +++- .../rocks/zipcodewilmington/CatHouseTest.java | 11 +++ .../java/rocks/zipcodewilmington/CatTest.java | 69 +++++++++++++++++- .../java/rocks/zipcodewilmington/DogTest.java | 70 +++++++++++++++++++ 7 files changed, 186 insertions(+), 5 deletions(-) diff --git a/src/main/java/rocks/zipcodewilmington/Food.java b/src/main/java/rocks/zipcodewilmington/Food.java index 2e5056b..1336b92 100644 --- a/src/main/java/rocks/zipcodewilmington/Food.java +++ b/src/main/java/rocks/zipcodewilmington/Food.java @@ -4,4 +4,15 @@ * @author leon on 4/19/18. */ public class Food { + + private String brand; + private String meat; + private boolean isWet; + + public Food(String brand, String meat, boolean isWet){ + + this.brand = brand; + this.meat = meat; + this.isWet = isWet; + } } diff --git a/src/main/java/rocks/zipcodewilmington/animals/Cat.java b/src/main/java/rocks/zipcodewilmington/animals/Cat.java index e703c36..b709ac2 100644 --- a/src/main/java/rocks/zipcodewilmington/animals/Cat.java +++ b/src/main/java/rocks/zipcodewilmington/animals/Cat.java @@ -6,11 +6,19 @@ * @author leon on 4/19/18. */ public class Cat extends Mammal { + public Cat(String name, Date birthDate, Integer id) { super(name, birthDate, id); } + public Cat (String name) { super(name); } + + public Cat(Date birthDate) { + super(birthDate); + } + public String speak() { return "meow!"; } + } diff --git a/src/main/java/rocks/zipcodewilmington/animals/Dog.java b/src/main/java/rocks/zipcodewilmington/animals/Dog.java index 7ed6dc0..17e50b0 100644 --- a/src/main/java/rocks/zipcodewilmington/animals/Dog.java +++ b/src/main/java/rocks/zipcodewilmington/animals/Dog.java @@ -6,9 +6,12 @@ * @author leon on 4/19/18. */ public class Dog extends Mammal { - public Dog(String name, Date birthDate, Integer id) { - super(name, birthDate, id); - } + + public Dog(String name, Date birthDate, Integer id) { super(name, birthDate, id); } + + public Dog(String name) { super(name); } + + public Dog(Date birthdate) { super(birthDate); } public String speak() { return "bark!"; diff --git a/src/main/java/rocks/zipcodewilmington/animals/Mammal.java b/src/main/java/rocks/zipcodewilmington/animals/Mammal.java index eec2aaa..0dc6a1d 100644 --- a/src/main/java/rocks/zipcodewilmington/animals/Mammal.java +++ b/src/main/java/rocks/zipcodewilmington/animals/Mammal.java @@ -21,6 +21,18 @@ public Mammal(String name, Date birthDate, Integer id) { this.id = id; } + public Mammal(String name) { + this.name = name; + this.birthDate = null; + this.id = 0; + } + + public Mammal(Date birthDate) { + this.name = ""; + this.birthDate = birthDate; + this.id = 0; + } + public String getName() { return name; } @@ -37,7 +49,6 @@ public void setBirthDate(Date birthDate) { this.birthDate = birthDate; } - public Integer getNumberOfMealsEaten() { return eatenMeals.size(); } diff --git a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java index f756b34..3d1ccea 100644 --- a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java +++ b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java @@ -1,10 +1,21 @@ package rocks.zipcodewilmington; +import org.junit.Test; + /** * @author leon on 4/19/18. */ public class CatHouseTest { // TODO - Create tests for `void add(Cat cat)` +// @Test +// public void catAddTest() { +// //given +// String givenName = "Kevin"; +// Date giveBirthDate = new Date(); +// Integer givenId = 0; +// //when +// Cat cat = new Cat(given) +// } // TODO - Create tests for `void remove(Integer id)` // TODO - Create tests for `void remove(Cat cat)` // TODO - Create tests for `Cat getCatById(Integer id)` diff --git a/src/test/java/rocks/zipcodewilmington/CatTest.java b/src/test/java/rocks/zipcodewilmington/CatTest.java index 4bd465f..801f5b1 100644 --- a/src/test/java/rocks/zipcodewilmington/CatTest.java +++ b/src/test/java/rocks/zipcodewilmington/CatTest.java @@ -2,7 +2,9 @@ import org.junit.Assert; import org.junit.Test; +import rocks.zipcodewilmington.animals.Animal; import rocks.zipcodewilmington.animals.Cat; +import rocks.zipcodewilmington.animals.Mammal; import java.util.Date; @@ -11,13 +13,78 @@ */ public class CatTest { // TODO - Create tests for `void setName(String name)` + @Test + public void testSetName() { + //given + String expectedName = "Ony"; + //when + Cat newCat = new Cat(expectedName); + String actual = newCat.getName(); + //then + Assert.assertEquals(expectedName, actual); + } // TODO - Create tests for `speak` + @Test + public void testSpeak() { + //given + String expectedSpeak = "meow!"; + //when + Cat newCat = new Cat(expectedSpeak); + String actual = newCat.speak(); + //then + Assert.assertEquals(expectedSpeak, actual); + } // TODO - Create tests for `setBirthDate(Date birthDate)` + @Test + public void setBirthDateTest() { + //given + Date expectedBirthDate = new Date(2019-03-15); + //when + Cat newCat = new Cat(expectedBirthDate); + Date actual = newCat.getBirthDate(); + //then + Assert.assertEquals(expectedBirthDate, actual); + } // TODO - Create tests for `void eat(Food food)` + @Test + public void testEat() { + //given + Integer expectedValue = 1; + Date givenBirthDate = new Date(2020-01-22); + Cat newCat = new Cat("Tipsy", givenBirthDate, 5); + //when + Food newFood = new Food("Blue Buffalo", "tuna", false); + newCat.eat(newFood); + //then + Integer actualValue = newCat.getNumberOfMealsEaten(); + Assert.assertEquals(expectedValue, actualValue); + + } // TODO - Create tests for `Integer getId()` + @Test + public void testGetId() { + //given + Integer expectedValue = 4; + Date givenBirthDate = new Date(2018-07-04); + Cat newCat = new Cat("Felix", givenBirthDate, 4); + //when + Integer actualValue = newCat.getId(); + //then + Assert.assertEquals(expectedValue, actualValue); + } // TODO - Create test to check Animal inheritance; google search `java instanceof keyword` - // TODO - Create test to check Mammal inheritance; google search `java instanceof keyword` + @Test + public void testAnimalInheritance() { + Cat newCat = new Cat("Frederick-Sama", null, null); + Assert.assertTrue(newCat instanceof Animal); + } + // TODO - Create test to check Mammal inheritance; google search `java instanceof keyword` + @Test + public void testMammalInheritance() { + Cat newCat = new Cat("Binks", null, null); + Assert.assertTrue(newCat instanceof Mammal); + } @Test public void constructorTest() { diff --git a/src/test/java/rocks/zipcodewilmington/DogTest.java b/src/test/java/rocks/zipcodewilmington/DogTest.java index 34a15bd..0a7e2ce 100644 --- a/src/test/java/rocks/zipcodewilmington/DogTest.java +++ b/src/test/java/rocks/zipcodewilmington/DogTest.java @@ -2,20 +2,90 @@ import org.junit.Assert; import org.junit.Test; +import rocks.zipcodewilmington.animals.Animal; +import rocks.zipcodewilmington.animals.Cat; import rocks.zipcodewilmington.animals.Dog; +import rocks.zipcodewilmington.animals.Mammal; + +import java.util.Date; /** * @author leon on 4/19/18. */ public class DogTest { // TODO - Create tests for `new Dog(String name, Date birthDate, Integer id)` + @Test + public void testSetName() { + //given + String expectedName = "Bo"; + //when + Dog newDog = new Dog(expectedName); + String actual = newDog.getName(); + //then + Assert.assertEquals(expectedName, actual); + } // TODO - Create tests for `speak` + @Test + public void testSpeak() { + //given + String expectedSpeak = "bark!"; + //when + Dog newDog = new Dog(expectedSpeak); + String actual = newDog.speak(); + //then + Assert.assertEquals(expectedSpeak, actual); + } // TODO - Create tests for `setBirthDate(Date birthDate)` + @Test + public void setBirthDateTest() { + //given + Date expectedBirthDate = new Date(2019-03-15); + //when + Dog newDog = new Dog(expectedBirthDate); + Date actual = newDog.getBirthDate(); + //then + Assert.assertEquals(expectedBirthDate, actual); + } // TODO - Create tests for `void eat(Food food)` + @Test + public void testEat() { + //given + Integer expectedValue = 1; + Date givenBirthDate = new Date(2018-06-11); + Dog newDog = new Dog("Penelope", givenBirthDate, 3); + //when + Food newFood = new Food("Blue Buffalo", "chicken", false); + newDog.eat(newFood); + //then + Integer actualValue = newDog.getNumberOfMealsEaten(); + Assert.assertEquals(expectedValue, actualValue); + + } // TODO - Create tests for `Integer getId()` + @Test + public void testGetId() { + //given + Integer expectedValue = 4; + Date givenBirthDate = new Date(2019-07-04); + Dog newDog = new Dog("Turtle", givenBirthDate, 8); + //when + Integer actualValue = newDog.getId(); + //then + Assert.assertEquals(expectedValue, actualValue); + } // TODO - Create test to check Animal inheritance; google search `java instanceof keyword` + @Test + public void testAnimalInheritance() { + Dog newDog = new Dog("Rin", null, null); + Assert.assertTrue(newDog instanceof Animal); + } // TODO - Create test to check Mammal inheritance; google search `java instanceof keyword` @Test + public void testMammalInheritance() { + Dog newDog = new Dog("Haru", null, null); + Assert.assertTrue(newDog instanceof Mammal); + } + @Test public void setNameTest() { // Given (a name exists and a dog exists) Dog dog = new Dog(null, null, null); From fcb22441bc858aaef57bb2ee738f1bb2c480c25a Mon Sep 17 00:00:00 2001 From: jgiroso Date: Sat, 10 Jul 2021 17:40:47 -0400 Subject: [PATCH 2/3] AnimalFactory Tests Complete --- .../rocks/zipcodewilmington/animals/Dog.java | 2 +- .../zipcodewilmington/AnimalFactoryTest.java | 41 +++++++++++++++++++ 2 files changed, 42 insertions(+), 1 deletion(-) diff --git a/src/main/java/rocks/zipcodewilmington/animals/Dog.java b/src/main/java/rocks/zipcodewilmington/animals/Dog.java index 17e50b0..b885cdf 100644 --- a/src/main/java/rocks/zipcodewilmington/animals/Dog.java +++ b/src/main/java/rocks/zipcodewilmington/animals/Dog.java @@ -11,7 +11,7 @@ public class Dog extends Mammal { public Dog(String name) { super(name); } - public Dog(Date birthdate) { super(birthDate); } + public Dog(Date birthDate) { super(birthDate); } public String speak() { return "bark!"; diff --git a/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java b/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java index 7522ce3..b10cad1 100644 --- a/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java +++ b/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java @@ -1,9 +1,50 @@ package rocks.zipcodewilmington; +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcodewilmington.animals.Animal; +import rocks.zipcodewilmington.animals.Cat; +import rocks.zipcodewilmington.animals.Dog; +import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory; + +import java.util.Date; + /** * @author leon on 4/19/18. */ public class AnimalFactoryTest { //TODO - Create Test for `Animal createDog(String name, Date birthDate)` + @Test + public void testCreateDog() { + //given + String expectedName = "Clover"; + Date expectedBirthDate = new Date(2016-05-12); + int expectedId = 0; + //when + Dog testDog = AnimalFactory.createDog(expectedName, expectedBirthDate); + String actualName = testDog.getName(); + Date actualBirthDate = testDog.getBirthDate(); + int actualId = testDog.getId(); + //then + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedBirthDate, actualBirthDate); + } //TODO - Create Test for `Animal createCat(String name, Date birthDate)` + @Test + public void testCreateCat() { + //given + String expectedName = "Jelly"; + Date expectedBirthDate = new Date(2014-04-14); + int expectedId = 0; + //when + Cat testCat = AnimalFactory.createCat(expectedName, expectedBirthDate); + String actualName = testCat.getName(); + Date actualBirthDate = testCat.getBirthDate(); + int actualId = testCat.getId(); + //then + Assert.assertEquals(expectedId, actualId); + Assert.assertEquals(expectedName, actualName); + Assert.assertEquals(expectedBirthDate, actualBirthDate); + } } From 9dd3a000721d46cd8e03b16294905ae37c59f598 Mon Sep 17 00:00:00 2001 From: jgiroso Date: Sat, 10 Jul 2021 19:16:25 -0400 Subject: [PATCH 3/3] Lab Complete --- .../rocks/zipcodewilmington/CatHouseTest.java | 83 +++++++++++++++++-- .../rocks/zipcodewilmington/DogHouseTest.java | 57 +++++++++++++ 2 files changed, 131 insertions(+), 9 deletions(-) diff --git a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java index 3d1ccea..07790a0 100644 --- a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java +++ b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java @@ -1,23 +1,88 @@ package rocks.zipcodewilmington; +import org.junit.Assert; import org.junit.Test; +import rocks.zipcodewilmington.animals.Cat; +import rocks.zipcodewilmington.animals.animal_storage.CatHouse; + +import java.util.Date; /** * @author leon on 4/19/18. */ public class CatHouseTest { // TODO - Create tests for `void add(Cat cat)` -// @Test -// public void catAddTest() { -// //given -// String givenName = "Kevin"; -// Date giveBirthDate = new Date(); -// Integer givenId = 0; -// //when -// Cat cat = new Cat(given) -// } + @Test + public void catAddTest() { + //given + String givenName = "Kevin"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Cat expectedCat = new Cat(givenName, giveBirthDate, givenId); + //when + CatHouse.add(expectedCat); + Cat actual = CatHouse.getCatById(givenId); + //then + Assert.assertEquals(expectedCat, actual); + } // TODO - Create tests for `void remove(Integer id)` + @Test + public void testCatRemoveByID() { + //given + String givenName = "Kyo"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Cat givenCat = new Cat(givenName, giveBirthDate, givenId); + //when + CatHouse.add(givenCat); + CatHouse.remove(givenId); + Cat actual = CatHouse.getCatById(givenId); + //then + Assert.assertEquals(null, actual); + } // TODO - Create tests for `void remove(Cat cat)` + @Test + public void testRemoveCat() { + //given + String givenName = "Kyo"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Cat givenCat = new Cat(givenName, giveBirthDate, givenId); + //when + CatHouse.add(givenCat); + CatHouse.remove(givenCat); + Cat actual = CatHouse.getCatById(givenId); + //then + Assert.assertEquals(null, actual); + } // TODO - Create tests for `Cat getCatById(Integer id)` + @Test + public void testGetCatById () { + //given + String givenName = "Ruby"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Cat expectedCat = new Cat(givenName, giveBirthDate, givenId); + //when + CatHouse.add(expectedCat); + Cat actual = CatHouse.getCatById(givenId); + //then + Assert.assertEquals(expectedCat, actual); + } // TODO - Create tests for `Integer getNumberOfCats()` + @Test + public void testGetNumberOfCats() { + //given + Integer expected = 2; + Date givenBirthDate1 = new Date(2021-02-01); + Date givenBirthDate2 = new Date(2020-05-15); + Cat cat1 = new Cat("Totoro", givenBirthDate1, 0); + Cat cat2 = new Cat("Cocoa", givenBirthDate2, 1); + //when + CatHouse.add(cat1); + CatHouse.add(cat2); + Integer actual = CatHouse.getNumberOfCats(); + //then + Assert.assertEquals(expected, actual); + } } diff --git a/src/test/java/rocks/zipcodewilmington/DogHouseTest.java b/src/test/java/rocks/zipcodewilmington/DogHouseTest.java index b88b30b..bfd9ced 100644 --- a/src/test/java/rocks/zipcodewilmington/DogHouseTest.java +++ b/src/test/java/rocks/zipcodewilmington/DogHouseTest.java @@ -1,8 +1,11 @@ package rocks.zipcodewilmington; +import org.junit.Assert; import org.junit.Test; +import rocks.zipcodewilmington.animals.Cat; import rocks.zipcodewilmington.animals.Dog; import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory; +import rocks.zipcodewilmington.animals.animal_storage.CatHouse; import rocks.zipcodewilmington.animals.animal_storage.DogHouse; import java.util.Date; @@ -12,9 +15,63 @@ */ public class DogHouseTest { // TODO - Create tests for `void add(Dog dog)` + @Test + public void testAddDogs() { + //given + String givenName = "Shigure"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Dog expectedDog = new Dog(givenName, giveBirthDate, givenId); + //when + DogHouse.add(expectedDog); + Dog actual = DogHouse.getDogById(givenId); + //then + Assert.assertEquals(expectedDog, actual); + } // TODO - Create tests for `void remove(Integer id)` + @Test + public void testCatRemoveByID() { + //given + String givenName = "Cyan"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Dog givenDog = new Dog(givenName, giveBirthDate, givenId); + //when + DogHouse.add(givenDog); + DogHouse.remove(givenId); + Dog actual = DogHouse.getDogById(givenId); + //then + Assert.assertEquals(null, actual); + } // TODO - Create tests for `void remove(Dog dog)` + @Test + public void testRemoveCat() { + //given + String givenName = "Loki"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Dog givenDog = new Dog(givenName, giveBirthDate, givenId); + //when + DogHouse.add(givenDog); + DogHouse.remove(givenDog); + Dog actual = DogHouse.getDogById(givenId); + //then + Assert.assertEquals(null, actual); + } // TODO - Create tests for `Dog getDogById(Integer id)` + @Test + public void testGetCatById () { + //given + String givenName = "Armin"; + Date giveBirthDate = new Date(2020-01-19); + Integer givenId = 0; + Dog expectedDog = new Dog(givenName, giveBirthDate, givenId); + //when + DogHouse.add(expectedDog); + Dog actual = DogHouse.getDogById(givenId); + //then + Assert.assertEquals(expectedDog, actual); + } // TODO - Create tests for `Integer getNumberOfDogs()` @Test