Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
38 changes: 38 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Dog;

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 name = "";
Date birthDate = new Date();
Integer id = 1;

//when
Dog dog = new Dog(name, birthDate, id);

//then
Assert.assertEquals(name, dog.getName());
Assert.assertEquals(birthDate, dog.getBirthDate());
Assert.assertEquals(id, dog.getId());
}
@Test
public void createCatTest(){
//given
String name = "";
Date birthDate = new Date();
Integer id = 1;

//when
Cat cat = new Cat(name, birthDate, id);

//then
Assert.assertEquals(name, cat.getName());
Assert.assertEquals(birthDate, cat.getBirthDate());
Assert.assertEquals(id, cat.getId());
}

}
78 changes: 78 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatHouseTest.java
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -9,4 +16,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 addCatTest(){
//given
Cat cat = new Cat("Kitty", new Date(), 1);

//when
CatHouse.add(cat);
Cat actual = CatHouse.getCatById(cat.getId());

//then
Assert.assertEquals(cat,actual);
}
@Test
public void removeCatTest(){
//given
Cat cat= new Cat("Sylvester", new Date(), 2);

//when
CatHouse.remove(cat);
Cat actual = CatHouse.getCatById(cat.getId());

//then
Assert.assertEquals(null, actual);

}
@Test
public void removeCatIDTest(){
//given
Cat cat = new Cat("Tom", new Date(), 3);

//when
CatHouse.remove(3);
Cat actual = CatHouse.getCatById(cat.getId());

//then
Assert.assertEquals(null, actual);
}
@Test
public void getCatByIdTest(){
//given
Cat cat = new Cat("Cat", new Date(), 4);

//when
Integer actual = cat.getId();

//then
Assert.assertEquals(cat.getId(), actual);
}
@Test
public void getNumberOfCatsTest(){
//given
Cat cat1 = new Cat("cat1", new Date(), 5);
Cat cat2 = new Cat("cat2", new Date(), 6);
Cat cat3 = new Cat("cat3", new Date(), 7);
Cat cat4 = new Cat("cat4", new Date(), 8);
Cat cat5 = new Cat("cat5", new Date(), 9);

//when
CatHouse.add(cat1);
CatHouse.add(cat2);
CatHouse.add(cat3);
CatHouse.add(cat4);
CatHouse.add(cat5);

Integer expected = 5;

//then
Assert.assertEquals(expected, CatHouse.getNumberOfCats());


}
}
88 changes: 88 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,13 @@

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.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
* @author leon on 4/19/18.
Expand Down Expand Up @@ -39,5 +43,89 @@ public void constructorTest() {
Assert.assertEquals(givenBirthDate, retrievedBirthDate);
Assert.assertEquals(givenId, retrievedId);
}
@Test
public void getNameTest(){
//given
String name = "";
Date birthDate = new Date();
Integer id = 1;

//when
Cat cat = new Cat(name,new Date(), id);
cat.setName("Ricky");
String expectedName = cat.getName();
String actual = "Ricky";

//then
Assert.assertEquals(expectedName,actual);
}
@Test
public void speakTest(){
//given
Cat cat = new Cat("Jim",new Date(), 2);
String actual = "meow!";

//when
String expected = cat.speak();

//then
Assert.assertEquals(expected,actual);
}
@Test
public void setBirthDate(){
//given
Cat cat = new Cat("Bob", new Date(), 3);
Date expectedDate = new Date();
//when
cat.setBirthDate(expectedDate);
Date actualDate = cat.getBirthDate();

//then
Assert.assertEquals(expectedDate, actualDate);
}
@Test
public void eatFoodTest(){
//given
Cat cat = new Cat("Jimbob", new Date(), 4);
Food chicken = new Food();
Food fish = new Food();


//when
cat.eat(chicken);
cat.eat(fish);
Integer numberOfTimesEaten = 2;

//then
Assert.assertEquals(numberOfTimesEaten, cat.getNumberOfMealsEaten());
}
@Test
public void getIdTest(){
//given
Cat cat = new Cat("Bobjim", new Date(), 5);


//when
Integer expected = cat.getId();
Integer actual = 5;

//then
Assert.assertEquals(expected,actual);
}
@Test
public void checkAnimalInheritanceTest(){
//given
Cat cat = new Cat("Jimmy", new Date(), 6);

//then
Assert.assertTrue(cat instanceof Animal);
}
@Test
public void checkMammalInheritanceTest(){
//given
Cat cat = new Cat("I ran out of names", new Date(), 7);

//then
Assert.assertTrue(cat instanceof Mammal);
}
}
78 changes: 76 additions & 2 deletions src/test/java/rocks/zipcodewilmington/DogHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,8 +1,12 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import org.omg.CORBA.DoubleHolder;
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;
Expand All @@ -19,16 +23,86 @@ public class DogHouseTest {

@Test
public void testGetNumberOfDogs() {
// Given (some
// Given (
String name = "Milo";
Date birthDate = new Date();
Dog animal = AnimalFactory.createDog(name, birthDate);
DogHouse.clear();

// When
DogHouse.add(animal);
Integer expected = 1;

// Then
DogHouse.getNumberOfDogs();
Assert.assertEquals(expected,DogHouse.getNumberOfDogs());
}
@Test
public void addDogTest(){
//given
Dog dog = new Dog("Astro", new Date(), 1);
// Integer expectedId = dog.getId();
//when
DogHouse.add(dog);
Dog actual = DogHouse.getDogById(dog.getId());

//then
Assert.assertEquals(actual,dog );
}
@Test
public void removeDogTest(){
//given
Dog dog = new Dog("John", new Date(), 2);

//when
DogHouse.remove(dog);
Dog actual = DogHouse.getDogById(dog.getId());
//then
Assert.assertEquals(actual, null);
}
@Test
public void removeDogIdTest(){
//given
Dog dog = new Dog("Billy", new Date(), 3);

//when
DogHouse.remove(3);
Dog actual = DogHouse.getDogById(dog.getId());

//then
Assert.assertEquals(actual, null);
}
@Test
public void getCatByIdTest(){
//given
Dog dog = new Dog("Dog", new Date(), 4);

//when
Integer actual = dog.getId();

//then
Assert.assertEquals(dog.getId(), actual);
}
@Test
public void getNumberOfDogsTest(){
//given
Dog dog1 = new Dog("dog1", new Date(), 5);
Dog dog2 = new Dog("dog2", new Date(), 6);
Dog dog3 = new Dog("dog3", new Date(), 7);
Dog dog4 = new Dog("dog4", new Date(), 8);
Dog dog5 = new Dog("dog5", new Date(), 9);

//when
DogHouse.clear();
DogHouse.add(dog1);
DogHouse.add(dog2);
DogHouse.add(dog3);
DogHouse.add(dog4);
DogHouse.add(dog5);

Integer expected = 5;

//then
Assert.assertEquals(expected, DogHouse.getNumberOfDogs());
}

}
Loading