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
12 changes: 12 additions & 0 deletions src/main/java/rocks/zipcodewilmington/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,4 +4,16 @@
* @author leon on 4/19/18.
*/
public class Food {
private String brand;
private int ounces;
private String typeOfMeat;
private boolean isWet;

public Food(String brand, int ounces, String typeOfMeat, boolean isWet){
this.brand = brand;
this.ounces = ounces;
this.typeOfMeat = typeOfMeat;
this.isWet = isWet;

}
}
5 changes: 5 additions & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Cat.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,11 @@ public Cat(String name, Date birthDate, Integer id) {
super(name, birthDate, id);
}

public Cat(String name) {
super(name);
}


public String speak() {
return "meow!";
}
Expand Down
10 changes: 9 additions & 1 deletion src/main/java/rocks/zipcodewilmington/animals/Mammal.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,14 @@ public abstract class Mammal implements Animal {
private final Integer id;
private ArrayList<Food> eatenMeals;
private String name;
private Date birthDate;
private Date birthDate; //Does this need to be private or protected?

public Mammal(String name){
this.name = name;
this.birthDate = null;
this.id = 0;

}

public Mammal(String name, Date birthDate, Integer id) {
this.name = name;
Expand All @@ -21,6 +28,7 @@ public Mammal(String name, Date birthDate, Integer id) {
this.id = id;
}


public String getName() {
return name;
}
Expand Down
43 changes: 43 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,52 @@
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.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 createAnimalTest(){
//given
String givenName = "Julie";
Date givenBirthDate = new Date();


//when
Animal newCat = AnimalFactory.createCat(givenName, givenBirthDate);
CatHouse.add((Cat) newCat);

//then
int actual = CatHouse.getNumberOfCats();
Assert.assertEquals(1, actual);
}

@Test
public void createAnimalTest2(){
//given
String givenName = "James";
Date givenBirthDate = new Date();


//when
Dog newCat = AnimalFactory.createDog(givenName, givenBirthDate);
DogHouse.add((Dog) newCat); //guess I can name dog newCat if I want

//then
int actual = DogHouse.getNumberOfDogs();
Assert.assertEquals(1, actual);
}
}
83 changes: 83 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.Dog;
import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;
import rocks.zipcodewilmington.animals.animal_storage.CatHouse;
import rocks.zipcodewilmington.animals.animal_storage.DogHouse;

/**
* @author leon on 4/19/18.
*/
Expand All @@ -9,4 +17,79 @@ 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 createdCat = new Cat("Marshall");
CatHouse catHouse = new CatHouse();


//when
CatHouse.add(createdCat);
int actual = CatHouse.getNumberOfCats();

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

}

@Test
public void removeIntegerCatTest(){
//given
Cat createdCat = new Cat("Marshall", null, 0);
Cat createdCat2 = new Cat("Wiggles", null, 2);
Cat createdCat3 = new Cat("Lego", null, 3);
CatHouse catHouse = new CatHouse();
//new instantiation of CatHouse() unnecessary

//when
catHouse.add(createdCat);
catHouse.add(createdCat2);
CatHouse.add(createdCat3);
catHouse.remove(0);

//then
int actual = CatHouse.getNumberOfCats();
Assert.assertEquals(2, actual);


}

@Test
public void getCatIdTest(){
//given
Cat createdCat = new Cat("Marshall", null, 0);
Cat createdCat2 = new Cat("Wiggles", null, 2);
Cat createdCat3 = new Cat("Lego", null, 3);


//when
CatHouse.add(createdCat);
CatHouse.add(createdCat2);
CatHouse.add(createdCat3);
CatHouse.remove(0);

//then
int actual = CatHouse.getNumberOfCats();
Cat actualCat = CatHouse.getCatById(2);
Assert.assertEquals(2, actual);
Assert.assertEquals(createdCat2, actualCat);

}
@Test
public void addCatTest2(){
//given
Cat createdCat = AnimalFactory.createCat("Charzar", null);



//when
CatHouse.add(createdCat);
int actual = CatHouse.getNumberOfCats();

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

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

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;

/**
* @author leon on 4/19/18.
*/
public class CatTest {

@Test
public void getNameTest(){
//given
Cat testCat = new Cat("Charlotte");
String expected = "Charlotte";

//when
String actual = testCat.getName();

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

}


// TODO - Create tests for `void setName(String name)`
// TODO - Create tests for `speak`
// TODO - Create tests for `setBirthDate(Date birthDate)`
Expand Down Expand Up @@ -40,4 +58,125 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}

@Test
public void setNameTest(){
//given
String givenName = "Zulu";
// Date givenBirthDate = new Date();
// Integer givenId = 0;
String expectedName = "Shaq";

//when
Cat test = new Cat(givenName);
test.setName(expectedName);

//then
String actual = test.getName();
Assert.assertEquals(expectedName,actual);

}

@Test
public void setBirthDateTest(){
//given
String givenName = "Zulu";
Date givenBirthDate = new Date();
Integer givenId = 0;
Date expectedDate = new Date(21-1-2019);

//when
Cat test = new Cat(givenName, givenBirthDate, givenId);
test.setBirthDate(expectedDate);

//then
Date actual = test.getBirthDate();
Assert.assertEquals(expectedDate,actual);

}

@Test
public void speakTest(){
//given
String givenName = "McStuffins";
Date givenBirthDate = new Date();
Integer givenId = 0;
String expected = "meow!";


//when
Cat test = new Cat(givenName, givenBirthDate, givenId);
String actual = test.speak();

//then
Assert.assertEquals(expected,actual);
}

@Test
public void eatTest(){
//given
String givenName = "McStuffins";
Date givenBirthDate = new Date();
Integer givenId = 0;
Integer expected = 1;
Food testFood = new Food("Kitty Chow", 4, "chicken", true);


//when
Cat test = new Cat(givenName, givenBirthDate, givenId);
test.eat(testFood);


//then
Integer actual = test.getNumberOfMealsEaten();
Assert.assertEquals(expected,actual);
}

@Test
public void eatTest2(){
//given
String givenName = "McStuffins";
Date givenBirthDate = new Date();
Integer givenId = 0;
Integer expected = 2;
Food testFood = new Food("Kitty Chow", 4, "chicken", true);
Food testFood2 = new Food("Purina", 2, "tuna", false);

//when
Cat test = new Cat(givenName, givenBirthDate, givenId);
test.eat(testFood);
test.eat(testFood2);


//then
Integer actual = test.getNumberOfMealsEaten();
Assert.assertEquals(expected,actual);
}

@Test
public void getIdTest(){
//given
String givenName = "McStuffins";
Date givenBirthDate = new Date();
Integer givenId = 2;
Integer expected = 2;

//when
Cat test = new Cat(givenName, givenBirthDate, givenId);
Integer actual = test.getId();

//then
Assert.assertEquals(expected, actual);
}

@Test
public void testInheritance() {
Mammal cat = new Cat("Sniffles");
Assert.assertTrue(cat instanceof Mammal);
}

@Test
public void testAnimalInheritance(){
Animal cat = new Cat("Pegasus");
Assert.assertTrue(cat instanceof Animal);
}
}
Loading