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
1 change: 1 addition & 0 deletions src/main/java/rocks/zipcodewilmington/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,5 @@
* @author leon on 4/19/18.
*/
public class Food {

}
5 changes: 5 additions & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Mammal.java
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,11 @@ public void setBirthDate(Date birthDate) {
}


@Override
public String speak() {
return null;
}

public Integer getNumberOfMealsEaten() {
return eatenMeals.size();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@
import rocks.zipcodewilmington.animals.Animal;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Dog;
import rocks.zipcodewilmington.animals.Mammal;
import rocks.zipcodewilmington.animals.animal_storage.CatHouse;
import rocks.zipcodewilmington.animals.animal_storage.DogHouse;

Expand Down
53 changes: 51 additions & 2 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,58 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import org.junit.runner.RunWith;
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;

/**
* @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 testDog_name_cesar_id_0() {

String dogName = "cesar";
Dog cesar = AnimalFactory.createDog(dogName, new Date());
DogHouse.add(cesar);
Assert.assertEquals(cesar.getName(), dogName);
Assert.assertEquals(cesar.getId(), new Integer(0));
}

@Test
public void testDog_name_tommy_id_1() {

String dogName = "tommy";
Dog tommy = AnimalFactory.createDog(dogName, new Date());
DogHouse.add(tommy);
Assert.assertEquals(tommy.getName(), dogName);
Assert.assertEquals(tommy.getId(), new Integer(1));
}

@Test
public void testCat_name_x_id_0() {

String dogName = "xcat";
Cat xcat = AnimalFactory.createCat(dogName, new Date());
CatHouse.add(xcat);
Assert.assertEquals(xcat.getName(), dogName);
Assert.assertEquals(xcat.getId(), new Integer(0));
}

@Test
public void testCat_name_y_id_1() {

String dogName = "ycat";
Cat ycat = AnimalFactory.createCat(dogName, new Date());
CatHouse.add(ycat);
Assert.assertEquals(ycat.getName(), dogName);
Assert.assertEquals(ycat.getId(), new Integer(1));
}
}
127 changes: 127 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,14 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Before;
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.
*/
Expand All @@ -9,4 +18,122 @@ 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()`

@Before
public void setup() {
CatHouse.clear();
}

@Test
public void testAdd_add_lilly_cat() {

Cat lillyCat = AnimalFactory.createCat("Lilly", new Date());
CatHouse.add(lillyCat);

Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(1));
Assert.assertEquals(lillyCat, CatHouse.getCatById(0));
}

@Test
public void testAdd_add_millo_cat() {

Cat milloCat = AnimalFactory.createCat("millo", new Date());
CatHouse.add(milloCat);

Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(1));
Assert.assertEquals(milloCat, CatHouse.getCatById(0));
}

@Test
public void testAdd_remove_by_id_lilly_cat() {

// Given Lilly Cat exists in CatHouse
CatHouse.add(AnimalFactory.createCat("Lilly", new Date()));
Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(1));

// When Lilly cat removed from Cat House
CatHouse.remove(0);

// Then No cat lives in CatHouse
Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(0));
}

@Test
public void testAdd_remove_by_id_milo_cat() {

// Given Lilly Cat exists in CatHouse
CatHouse.add(AnimalFactory.createCat("Lilly", new Date()));
CatHouse.add(AnimalFactory.createCat("Millo", new Date()));
Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(2));

// When Lilly cat removed from Cat House
CatHouse.remove(1);

// Then No cat lives in CatHouse
Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(1));
Assert.assertEquals(CatHouse.getCatById(0).getName(), "Lilly");
}

@Test
public void testAdd_remove_by_object_millo_cat() {

Cat milo = AnimalFactory.createCat("Milo>", new Date());
CatHouse.add(milo);

CatHouse.remove(milo);

Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(0));
}

@Test
public void testAdd_remove_by_object_lilly_cat() {

Cat lilly = AnimalFactory.createCat("Lilly", new Date());
CatHouse.add(lilly);
CatHouse.add(AnimalFactory.createCat("Milo", new Date()));

CatHouse.remove(lilly);

Assert.assertEquals(CatHouse.getNumberOfCats(), Integer.valueOf(1));
}

@Test
public void testNumberOfCats_three_cats_in_house() {

// Given Lilly Cat exists in CatHouse
CatHouse.add(AnimalFactory.createCat("Lilly", new Date()));
CatHouse.add(AnimalFactory.createCat("Millo", new Date()));
CatHouse.add(AnimalFactory.createCat("Oliver", new Date()));

// When Lilly cat removed from Cat House
int numberOfCats = CatHouse.getNumberOfCats();

// Then No cat lives in CatHouse
Assert.assertEquals(numberOfCats, 3);
}

@Test
public void testNumberOfCats_no_cat_in_house() {

// Given No Cats are added

// When Lilly cat removed from Cat House
int numberOfCats = CatHouse.getNumberOfCats();

// Then No cat lives in CatHouse
Assert.assertEquals(numberOfCats, 0);
}

@Test
public void testGteById_add_three_cats_get_id_1() {

CatHouse.add(AnimalFactory.createCat("Milo", new Date()));
Cat expectedCat = AnimalFactory.createCat("Lilly", new Date());
CatHouse.add(expectedCat);
CatHouse.add(AnimalFactory.createCat("Oliver", new Date()));

Cat actualCat = CatHouse.getCatById(1);

Assert.assertEquals(expectedCat, actualCat);
}
}
77 changes: 76 additions & 1 deletion src/test/java/rocks/zipcodewilmington/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;

Expand Down Expand Up @@ -40,4 +42,77 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}

}

@Test
public void setNameTest() {
// Given Cat object with name chopper
Cat c = new Cat("Kitty", new Date(), 1);
// When I change the name to gimme
c.setName("gimme");
// Then name should be changed to gimmy
Assert.assertEquals("gimme", c.getName());
}

@Test
public void speakTest() {
//given
Cat c = new Cat("cuper", new Date(), 1);
//when
String s = c.speak();
//then
Assert.assertEquals("meow!",s);

}


@Test
public void setBirthDateTest() {
//given
Cat c = new Cat("sweety", new Date(),3);
//when
Date d = new Date();
c.setBirthDate(d);
//Then
Assert.assertEquals(d,c.getBirthDate());


}

@Test
public void eatTest() {
Cat c = new Cat("rocky", new Date(),3);
Food f = new Food();
c.eat(f);
Assert.assertEquals(new Integer(1),c.getNumberOfMealsEaten());

}


@Test public void getIDTest() {
//Given
Cat c = new Cat("rocky", new Date(),4);
//When
c.getId();
//Then
Assert.assertEquals(4, c.getId().intValue());

}


@Test
public void animalTest() {

Cat d = new Cat("rocky", new Date(),4);

Assert.assertEquals(true, d instanceof Animal);
}


@Test
public void animalInstance() {
Cat ca = new Cat("rocky", new Date(),4);
Assert.assertEquals(true, ca instanceof Mammal);
}


}
53 changes: 52 additions & 1 deletion src/test/java/rocks/zipcodewilmington/DogHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,12 @@
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.DogHouse;
import rocks.zipcodewilmington.animals.animal_storage.DogHouse;

import java.util.Date;

Expand All @@ -20,7 +23,7 @@ public class DogHouseTest {
@Test
public void testGetNumberOfDogs() {
// Given (some
String name = "Milo";
String name = "jimmy";
Date birthDate = new Date();
Dog animal = AnimalFactory.createDog(name, birthDate);
DogHouse.clear();
Expand All @@ -31,4 +34,52 @@ public void testGetNumberOfDogs() {
// Then
DogHouse.getNumberOfDogs();
}


// TODO - Create tests for `void add(Dog dog)`
@Test
public void addTest() {
Dog dog = new Dog("jimmy", new Date(), 1);
DogHouse.add(dog);
Dog d = DogHouse.getDogById(1);
Assert.assertEquals(dog, d);

}


// TODO - Create tests for `void remove(Integer id)`
@Test
public void removeTestID() {
DogHouse.clear();
Dog d = new Dog("jimmy", new Date(), 1);
DogHouse.add(d);
Dog e = DogHouse.getDogById(1);
Assert.assertEquals(d, e);


}

// TODO - Create tests for `void remove(Dog dog)`
@Test
public void removeTest() {
DogHouse.clear();
Dog dog = new Dog("jimmy", new Date(), 1);
DogHouse.add(dog);
Dog dog2 = new Dog("ceasar", new Date(), 1);
DogHouse.add(dog2);
DogHouse.remove(dog);
DogHouse.getDogById(1);
Assert.assertEquals(1, DogHouse.getNumberOfDogs().intValue());
}

// TODO - Create tests for `Dog getDogById(Integer id)`
@Test
public void getDogByIdTest() {
DogHouse.clear();
Dog dog = new Dog("jimmy", new Date(), 1);
DogHouse.add(dog);
Dog dv = DogHouse.getDogById(1);
Assert.assertEquals(dog, dv);
}

}
Loading