Skip to content

Manny finished TDD Animal Factory #27

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
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
11 changes: 10 additions & 1 deletion src/main/java/rocks/zipcodewilmington/Food.java
Original file line number Diff line number Diff line change
Expand Up @@ -3,5 +3,14 @@
/**
* @author leon on 4/19/18.
*/
public class Food {
public class Food { // we need to make up the Food variables
private String brand;
private int ounces;
private boolean isCanned;

public Food (String brand, int ounces, boolean isCanned) {
this.brand = brand;
this.ounces = ounces;
this.isCanned = isCanned;
}
}
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
4 changes: 4 additions & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Dog.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public Dog(String name, Date birthDate, Integer id) {
super(name, birthDate, id);
}

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

public String speak() {
return "bark!";
}
Expand Down
11 changes: 11 additions & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Mammal.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,13 +14,24 @@ public abstract class Mammal implements Animal {
private String name;
private Date birthDate;





public Mammal(String name, Date birthDate, Integer id) {
this.name = name;
this.birthDate = birthDate;
this.eatenMeals = new ArrayList<>();
this.id = id;
}

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

}

public String getName() {
return name;
}
Expand Down
48 changes: 48 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,57 @@
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;

/**
* @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 = "Mochi";
Date givenBirthDate = new Date();
Integer givenId = 0;

// When
DogHouse.clear();
Dog dog = AnimalFactory.createDog(givenName, givenBirthDate);


// Then
Assert.assertEquals(givenName, dog.getName());


}


@Test
public void createCatTest(){
// Given
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 0;

// When
CatHouse.clear();
Cat cat = AnimalFactory.createCat(givenName, givenBirthDate);


// Then
Assert.assertEquals(givenName, cat.getName());


}

}
104 changes: 104 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,101 @@ 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
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 0;
CatHouse.clear();

// When
Cat cat = new Cat(givenName, givenBirthDate, givenId);
CatHouse.add(cat);
int actual = CatHouse.getNumberOfCats();

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

}

@Test
public void removeCatByIdTest() {
// Given
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 0;
CatHouse.clear();

// When
Cat cat = new Cat(givenName, givenBirthDate, givenId);
CatHouse.remove(0);


int actual = CatHouse.getNumberOfCats();

// Then
Assert.assertEquals(0, actual);
Assert.assertNull(CatHouse.getCatById(0));

}

@Test
public void removeCatTest() {
// Given
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 0;
CatHouse.clear();

// When
Cat cat = new Cat(givenName, givenBirthDate, givenId);
CatHouse.remove(cat);

int actual = CatHouse.getNumberOfCats();

// Then
Assert.assertEquals(0, actual);
}

@Test
public void getCatByIdTest() {
// Given
CatHouse.clear();
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 2;
Cat cat = new Cat(givenName, givenBirthDate, givenId);
CatHouse.add(cat);


// When
Cat actual = CatHouse.getCatById(givenId);


// Then
Assert.assertEquals(cat, actual);

}

@Test
public void getNumberOfCatsTest () {
// Given
CatHouse.clear();
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 2;
Cat cat = new Cat(givenName, givenBirthDate, givenId);
CatHouse.add(cat);

// When
int actual = CatHouse.getNumberOfCats();

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

}


}
93 changes: 93 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 @@ -40,4 +42,95 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}

@Test
public void setNameTest() {
// Given
String givenName = "Charlie";
//Date givenBirthDate = new Date();
//Integer givenId = 0;
String expectedName = "Garfield";

// When
Cat test = new Cat(givenName, null, null);
test.setName(expectedName);

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

@Test
public void speakTest() {
// Given
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 0;
String expectedSpeak = "meow!";

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

// Then
Assert.assertEquals(expectedSpeak,actual);
}

@Test
public void setBirthDateTest() {
// Given
Date givenBirthDate = new Date();
Date expectedBirthDate = new Date(19-7-1978);

// When
Cat test = new Cat(null, givenBirthDate, null);
test.setBirthDate(expectedBirthDate);

// Then
Date actual = test.getBirthDate();
Assert.assertEquals(expectedBirthDate, actual);
}

@Test
public void eatTest() {
// Given
Integer expectedNumOfMeals = 1; // ate food 1 times
Food eatFood = new Food("Fancy Feast", 3, true);

// When
Cat test = new Cat(null, null, null);
test.eat(eatFood); // ate food 1 times

// Then
Integer actual = test.getNumberOfMealsEaten();
Assert.assertEquals(expectedNumOfMeals, actual);
}

@Test
public void getIdTest() {
// Given
String givenName = "Garfield";
Date givenBirthDate = new Date();
Integer givenId = 0;
// String expectedSpeak = "meow!";

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

// Then
Assert.assertEquals(givenId,actual);
}

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

@Test
public void testInheritanceAnimal() {
Animal cat = new Cat("Garfield Junior");
Assert.assertTrue(cat instanceof Animal);

}
}
Loading