diff --git a/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java b/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java index 7522ce3..1546026 100644 --- a/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java +++ b/src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java @@ -1,9 +1,58 @@ 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(){ + // given + String givenName = "Clifford"; + Date givenDob = new Date(); + Dog dog = AnimalFactory.createDog(givenName, givenDob); + + + + + //when + String getNameResult = dog.getName(); + Date getBirthResult = dog.getBirthDate(); + + //Then + Assert.assertEquals(givenName, getNameResult); + Assert.assertEquals(givenDob, getBirthResult); + +} + + @Test + public void createCatTest(){ + //given + String givenName = "Garfield"; + Date givenDob = new Date(); + + + //when + Cat cat = AnimalFactory.createCat(givenName, givenDob); + String getNameResult = cat.getName(); + Date getBirthResult = cat.getBirthDate(); + + //Then + Assert.assertEquals(givenName, getNameResult); + Assert.assertEquals(givenDob, getBirthResult); + } + + } diff --git a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java index f756b34..1e412dc 100644 --- a/src/test/java/rocks/zipcodewilmington/CatHouseTest.java +++ b/src/test/java/rocks/zipcodewilmington/CatHouseTest.java @@ -1,5 +1,13 @@ package rocks.zipcodewilmington; +import org.junit.Assert; +import org.junit.Test; +import rocks.zipcodewilmington.animals.Cat; +import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory; +import rocks.zipcodewilmington.animals.animal_storage.CatHouse; + +import java.util.Date; + /** * @author leon on 4/19/18. */ @@ -9,4 +17,75 @@ 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 addNumberCatTest(){ + //given + String catName = "Scratchy"; + Date birthDay = new Date(); + Cat animal = AnimalFactory.createCat(catName, birthDay); + CatHouse.clear(); + + //when + CatHouse.add(animal); + + //then + CatHouse.getNumberOfCats(); + } + + @Test + public void catRemoveIdTest(){ + //given + String catName = "Scratchy"; + Date birthDay = new Date(); + Cat animal = AnimalFactory.createCat(catName, birthDay); + CatHouse.clear(); + + + //when + + Integer expected = 0; + CatHouse.add(animal); + CatHouse.remove(animal.getId()); + + //then + Assert.assertEquals(expected, CatHouse.getNumberOfCats()); + } + + @Test + public void removeCatTest(){ + //given + String catName = "Scratchy"; + Date birthDay = new Date(); + Cat animal = AnimalFactory.createCat(catName, birthDay); + CatHouse.add(animal); + //when + CatHouse.remove(animal); + + //then + int actNumbCats = CatHouse.getNumberOfCats(); + Assert.assertEquals(0, actNumbCats); + } + + + + @Test + public void getCatIdTest(){ + //given + String catName = "Scratchy"; + Date birthDay = new Date(); + Cat animal = AnimalFactory.createCat(catName,birthDay); + CatHouse.add(animal); + CatHouse.clear(); + + //when + int actual = animal.getId(); + + //then + Assert.assertEquals(0, actual); +; + } + } + diff --git a/src/test/java/rocks/zipcodewilmington/CatTest.java b/src/test/java/rocks/zipcodewilmington/CatTest.java index 4bd465f..0d176a5 100644 --- a/src/test/java/rocks/zipcodewilmington/CatTest.java +++ b/src/test/java/rocks/zipcodewilmington/CatTest.java @@ -1,8 +1,11 @@ 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.Mammal; import java.util.Date; @@ -40,4 +43,121 @@ public void constructorTest() { Assert.assertEquals(givenId, retrievedId); } + + @Test + public void setNameTest() { + //given + String catName = "Zula"; + Date birthDay = new Date(); + Integer givenId = 0; + Cat cat = new Cat(catName, birthDay, 0); + + //when + cat.setName(catName); + + + //then + catName = cat.getName(); + Assert.assertEquals("Zula", catName); + + + } + + + @Test + public void speakTest() { + String catName = "Zula"; + Date birthDay = new Date(); + Integer givenId = 0; + Cat cat = new Cat(catName,birthDay,0); + + //when + String catSpeak = cat.speak(); + + //then + + Assert.assertEquals("meow!", catSpeak); + + } + + @Test + public void setBirthDate(){ + //given + String catName = "Zula"; + Date birthDay = new Date(1993, 8, 2); + Integer givenId = 0; + Cat cat = new Cat(catName,birthDay,0); + + + //when + cat.setBirthDate(birthDay); + + //then + Assert.assertEquals(birthDay, birthDay); + + } + + @Test + public void eatTest(){ + //given + String catName = "Zula"; + Date birthDay = new Date(); + Integer givenId = 0; + Food actualFood = new Food(); + Cat cat = new Cat(catName,birthDay,0); + + //when + cat.eat(actualFood); + int mealsEaten = cat.getNumberOfMealsEaten(); + + //then + Assert.assertEquals(1, mealsEaten); + + } + + @Test + public void getIdTest() { + //given + String catName = "Zula"; + Date birthDay = new Date(); + Integer givenId = 0; + Cat cat = new Cat(catName,birthDay,0); + + //when + int id = cat.getId(); + + //then + Assert.assertEquals(givenId, cat.getId()); + } + + @Test + public void animalInheritanceTest() { + //given + String catName = "Zula"; + Date birthDay = new Date(); + Integer givenId = 0; + + + //when + Cat cat = new Cat(catName,birthDay,0); + + //then + Assert.assertTrue(cat instanceof Animal); + } + + @Test + public void mammalInheritanceTest() { + //given + String catName = "Zula"; + Date birthDay = new Date(); + Integer givenId = 0; + + + //when + Cat cat = new Cat(catName,birthDay,0); + + //then + 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..dd0708b 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,59 @@ public void testGetNumberOfDogs() { // Then DogHouse.getNumberOfDogs(); } + + + @Test + public void dogRemoveIdTest(){ + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Dog animal = AnimalFactory.createDog(dogName, birthDay); + DogHouse.clear(); + + + //when + + Integer expected = 0; + DogHouse.add(animal); + DogHouse.remove(animal.getId()); + + //then + Assert.assertEquals(expected, DogHouse.getNumberOfDogs()); + } + + @Test + public void removeDogTest(){ + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Dog animal = AnimalFactory.createDog(dogName, birthDay); + DogHouse.add(animal); + //when + DogHouse.remove(animal); + + //then + int actNumbDogs = DogHouse.getNumberOfDogs(); + Assert.assertEquals(0, actNumbDogs); + } + + + + @Test + public void getDogIdTest(){ + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Dog animal = AnimalFactory.createDog(dogName,birthDay); + DogHouse.add(animal); + Integer givenId = 0; + DogHouse.clear(); + + //when + int actual = animal.getId(); + + //then + Assert.assertEquals(0, actual); + + } } diff --git a/src/test/java/rocks/zipcodewilmington/DogTest.java b/src/test/java/rocks/zipcodewilmington/DogTest.java index 34a15bd..6091794 100644 --- a/src/test/java/rocks/zipcodewilmington/DogTest.java +++ b/src/test/java/rocks/zipcodewilmington/DogTest.java @@ -2,7 +2,12 @@ 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. @@ -28,4 +33,101 @@ public void setNameTest() { String dogName = dog.getName(); Assert.assertEquals(dogName, givenName); } + + @Test + public void speakTest() { + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Integer givenId = 0; + Dog dog = new Dog(dogName,birthDay,0); + + //when + String dogSpeak = dog.speak(); + + //then + + Assert.assertEquals("bark!", dogSpeak); + + } + + @Test + public void setBirthDate(){ + //given + String dogName = "Milo"; + Date birthDay = new Date(1993, 8, 2); + Integer givenId = 0; + Dog dog = new Dog(dogName,birthDay,0); + + + //when + dog.setBirthDate(birthDay); + + //then + Assert.assertEquals(birthDay, birthDay); + + } + + @Test + public void eatTest(){ + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Integer givenId = 0; + Food actualFood = new Food(); + Dog dog = new Dog(dogName,birthDay,0); + + //when + dog.eat(actualFood); + int mealsEaten = dog.getNumberOfMealsEaten(); + + //then + Assert.assertEquals(1, mealsEaten); + + } + + @Test + public void getIdTest() { + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Integer givenId = 0; + Dog dog = new Dog(dogName,birthDay,0); + + //when + int id = dog.getId(); + + //then + Assert.assertEquals(givenId, dog.getId()); + } + + @Test + public void animalInheritanceTest() { + //given + String dogName = "Milo"; + Date birthDay = new Date(); + Integer givenId = 0; + + + //when + Dog dog = new Dog(dogName,birthDay,0); + + //then + Assert.assertTrue(dog instanceof Animal); + } + + @Test + public void mammalInheritanceTest() { + //given + String dogName = "Mil0"; + Date birthDay = new Date(); + Integer givenId = 0; + + + //when + Dog dog = new Dog(dogName,birthDay,0); + + //then + Assert.assertTrue(dog instanceof Mammal); + } }