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
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@ public class CatHouse {
private static AnimalWarehouse<Cat> catHouse = new AnimalWarehouse<>();

public static void add(Cat cat) {

catHouse.add(cat);
}

Expand Down
30 changes: 30 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -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");
}
}
57 changes: 57 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,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());
}
}
122 changes: 122 additions & 0 deletions 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 @@ -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);

}
}
44 changes: 44 additions & 0 deletions src/test/java/rocks/zipcodewilmington/DogHouseTest.java
Original file line number Diff line number Diff line change
@@ -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;
Expand Down Expand Up @@ -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()));
}
}
Loading