diff --git a/src/main/java/rocks/zipcodewilmington/animals/animal_storage/CatHouse.java b/src/main/java/rocks/zipcodewilmington/animals/animal_storage/CatHouse.java index 10e191d..633ec6b 100644 --- a/src/main/java/rocks/zipcodewilmington/animals/animal_storage/CatHouse.java +++ b/src/main/java/rocks/zipcodewilmington/animals/animal_storage/CatHouse.java @@ -10,6 +10,7 @@ public class CatHouse { private static AnimalWarehouse catHouse = new AnimalWarehouse<>(); public static void add(Cat cat) { + catHouse.add(cat); } diff --git a/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java b/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java index 7522ce3..a6d72e5 100644 --- a/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java +++ b/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java @@ -1,9 +1,39 @@ 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 java.util.Date; + /** * @author leon on 4/19/18. */ public class AnimalFactoryTest { //TODO - Create Test for `Animal createDog(String name, Date birthDate)` //TODO - Create Test for `Animal createCat(String name, Date birthDate)` + + @Test + public void createDogTest(){ + // Creates new Dog + Date birthDate = new Date(); + Dog dog = AnimalFactory.createDog("Pancho",birthDate); + + // test + Assert.assertEquals(dog.getBirthDate(),birthDate); + Assert.assertEquals(dog.getName(),"Pancho"); + } + + @Test + public void createCatTest() { + // Creates new Dog + Date birthDate = new Date(); + Cat cat = AnimalFactory.createCat("Nina", birthDate); + + // test + Assert.assertEquals(cat.getBirthDate(), birthDate); + Assert.assertEquals(cat.getName(), "Nina"); + } } diff --git a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java index f756b34..330216b 100644 --- a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java +++ b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java @@ -1,5 +1,12 @@ 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. */ @@ -9,4 +16,54 @@ public class CatHouseTest { // TODO - Create tests for `void remove(Cat cat)` // TODO - Create tests for `Cat getCatById(Integer id)` // TODO - Create tests for `Integer getNumberOfCats()` + + @Test + public void addCatTest(){ + CatHouse.add(new Cat("Nina", new Date(),0)); + Integer catsBefore = CatHouse.getNumberOfCats() + 1; + CatHouse.add(new Cat("Mini", new Date(),1)); + + Assert.assertEquals(catsBefore, CatHouse.getNumberOfCats()); + } + + @Test + public void removeIdTest(){ + CatHouse.add(new Cat("Nina", new Date(),0)); + CatHouse.add(new Cat("Mini", new Date(),1)); + + Integer catsBefore = CatHouse.getNumberOfCats() - 1; + CatHouse.remove(0); + Assert.assertEquals(catsBefore, CatHouse.getNumberOfCats()); + } + + @Test + public void removeCatTest(){ + Cat newCat = new Cat("kitten", new Date(),2); + CatHouse.add(new Cat("Nina", new Date(),0)); + CatHouse.add(new Cat("Mini", new Date(),1)); + CatHouse.add(newCat); + + Integer catsBefore = CatHouse.getNumberOfCats() - 1; + CatHouse.remove(newCat); + Assert.assertEquals(catsBefore, CatHouse.getNumberOfCats()); + } + + @Test + public void getCatByIdTest(){ + Cat newCat = new Cat("kitten", new Date(),2); + CatHouse.add(new Cat("Nina", new Date(),0)); + CatHouse.add(new Cat("Mini", new Date(),1)); + CatHouse.add(newCat); + + Assert.assertEquals(newCat, CatHouse.getCatById(newCat.getId())); + } + + @Test + public void getNumeberOfCatsTest() { + CatHouse.add(new Cat("Nina", new Date(), 0)); + Integer catsBefore = CatHouse.getNumberOfCats() + 1; + CatHouse.add(new Cat("Mini", new Date(), 1)); + + Assert.assertEquals(catsBefore, CatHouse.getNumberOfCats()); + } } diff --git a/src/test/java/rocks/zipcodewilmington/CatTest.java b/src/test/java/rocks/zipcodewilmington/CatTest.java index 4bd465f..1884bb7 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; @@ -39,5 +41,125 @@ public void constructorTest() { Assert.assertEquals(givenBirthDate, retrievedBirthDate); Assert.assertEquals(givenId, retrievedId); } + @Test + public void testSetName(){ + //Given name + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + // When (a cat is constructed) + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + // new name + String newName = "Nina"; + + // change name + cat.setName(newName); + + // Then (we expect the given data, to match the retrieved data) + Assert.assertEquals(newName, cat.getName()); + } + @Test + public void testSetBirthDate(){ + //Given date + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + // When new cat is constructed + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + // new birthDate + Date newDate = new Date(1993,11,2); + + // changes birthDate + cat.setBirthDate(newDate); + + // Then (Given data is to match retrieved data + Assert.assertEquals(newDate, cat.getBirthDate()); + } + + @Test + public void testSpeak(){ + //Given name birthDate and Id + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When new cat is constructed + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + //expected + String expected = "meow!"; + + //Then (Given data is to match retrieved data + Assert.assertEquals(expected, cat.speak()); + } + + @Test + public void testEat(){ + //Given name birthDate and Id + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When new cat is constructed + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + //expected + Integer expected = cat.getNumberOfMealsEaten() + 1; + + //action + cat.eat(new Food()); + + //Then (Given data is to match retrieved data + Assert.assertEquals(expected, cat.getNumberOfMealsEaten()); + } + + @Test + public void testGetId(){ + //Given name birthDate and Id + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + // when a cat is constructed + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + // expected + Integer expected = givenId; + + //Then (Given data is to match retrieved data + Assert.assertEquals(expected, cat.getId()); + } + + @Test + public void testInstanceOfAnimal(){ + //Given name birthDate and Id + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + // when a cat is constructed + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + //Then (Given data is to match retrieved data + Assert.assertTrue(cat instanceof Animal); + } + + @Test + public void testInstanceOfMammal(){ + //Given name birthDate and Id + String givenName = "Zula"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + // when a cat is constructed + Cat cat = new Cat(givenName, givenBirthDate, givenId); + + //Then (Given data is to match retrieved data + Assert.assertTrue(cat instanceof Mammal); + + } } diff --git a/src/test/java/rocks/zipcodewilmington/DogHouseTest.java b/src/test/java/rocks/zipcodewilmington/DogHouseTest.java index b88b30b..7996180 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; @@ -31,4 +34,45 @@ public void testGetNumberOfDogs() { // Then DogHouse.getNumberOfDogs(); } + + @Test + public void addDogTest(){ + DogHouse.add(new Dog("Milo", new Date(),0)); + Integer dogsBefore = DogHouse.getNumberOfDogs(); + CatHouse.add(new Cat("Pancho", new Date(),1)); + + Assert.assertEquals(dogsBefore, DogHouse.getNumberOfDogs()); + } + + @Test + public void removeIdTest(){ + DogHouse.add(new Dog("Milo", new Date(),0)); + DogHouse.add(new Dog("Pancho", new Date(),1)); + + Integer dogsBefore = DogHouse.getNumberOfDogs() - 1; + DogHouse.remove(0); + Assert.assertEquals(dogsBefore, DogHouse.getNumberOfDogs()); + } + + @Test + public void removeDogTest(){ + Dog newDog = new Dog("kitten", new Date(),2); + DogHouse.add(new Dog("Nina", new Date(),0)); + DogHouse.add(new Dog("Mini", new Date(),1)); + DogHouse.add(newDog); + + Integer dogsBefore = DogHouse.getNumberOfDogs() - 1; + DogHouse.remove(newDog); + Assert.assertEquals(dogsBefore, DogHouse.getNumberOfDogs()); + } + + @Test + public void getCatByIdTest(){ + Dog newDog = new Dog("kitten", new Date(),2); + DogHouse.add(new Dog("Nina", new Date(),0)); + DogHouse.add(new Dog("Mini", new Date(),1)); + DogHouse.add(newDog); + + Assert.assertEquals(newDog, DogHouse.getDogById(newDog.getId())); + } } diff --git a/src/test/java/rocks/zipcodewilmington/DogTest.java b/src/test/java/rocks/zipcodewilmington/DogTest.java index 34a15bd..28a97c9 100644 --- a/src/test/java/rocks/zipcodewilmington/DogTest.java +++ b/src/test/java/rocks/zipcodewilmington/DogTest.java @@ -2,7 +2,11 @@ import org.junit.Assert; import org.junit.Test; +import rocks.zipcodewilmington.animals.Animal; import rocks.zipcodewilmington.animals.Dog; +import rocks.zipcodewilmington.animals.Mammal; + +import java.util.Date; /** * @author leon on 4/19/18. @@ -28,4 +32,98 @@ public void setNameTest() { String dogName = dog.getName(); Assert.assertEquals(dogName, givenName); } + + @Test + public void testBirthDate(){ + // Given name, birthDate, Id + String givenName = "Pancho"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When Dog is created + Dog dog = new Dog(givenName, givenBirthDate, givenId); + + // Then expect to get birthDate given to dog + Date dogBirthDate = dog.getBirthDate(); + Assert.assertEquals(dogBirthDate, givenBirthDate); + } + + @Test + public void speakTest(){ + // Given name, birthDate, Id + String givenName = "Pancho"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When Dog is created + Dog dog = new Dog(givenName, givenBirthDate, givenId); + + // Then expect to get birthDate given to dog + String expected = dog.speak(); + Assert.assertEquals(expected, dog.speak()); + } + + @Test + public void eatTest(){ + // Given name, birthDate, Id + String givenName = "Pancho"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When Dog is created + Dog dog = new Dog(givenName, givenBirthDate, givenId); + + // Action + dog.eat(new Food()); + + // Then expect to get birthDate given to dog + Integer expected = dog.getNumberOfMealsEaten(); + Assert.assertEquals(expected, dog.getNumberOfMealsEaten()); + } + + @Test + public void getIdTest(){ + // Given name, birthDate, Id + String givenName = "Pancho"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When Dog is created + Dog dog = new Dog(givenName, givenBirthDate, givenId); + + + // Then expect to get birthDate given to dog + Integer expected = dog.getId(); + Assert.assertEquals(expected, dog.getId()); + } + + @Test + public void dogInstanceOfAnimal(){ + // Given name, birthDate, Id + String givenName = "Pancho"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When Dog is created + Dog dog = new Dog(givenName, givenBirthDate, givenId); + + + // Then expect to get birthDate given to dog + Assert.assertTrue(dog instanceof Animal); + } + + @Test + public void dogInstanceOfMammal(){ + // Given name, birthDate, Id + String givenName = "Pancho"; + Date givenBirthDate = new Date(); + Integer givenId = 0; + + //When Dog is created + Dog dog = new Dog(givenName, givenBirthDate, givenId); + + + // Then expect to get birthDate given to dog + Assert.assertTrue(dog instanceof Mammal); + } }