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
49 changes: 49 additions & 0 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 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);
}


}
79 changes: 79 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatHouseTest.java
Original file line number Diff line number Diff line change
@@ -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.
*/
Expand All @@ -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);
;
}

}

120 changes: 120 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatTest.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.Animal;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Mammal;

import java.util.Date;

Expand Down Expand Up @@ -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);
}

}
58 changes: 58 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,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);

}
}
Loading