Skip to content
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

Animal Factory Test Lab #21

Open
wants to merge 2 commits 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
1 change: 1 addition & 0 deletions src/main/java/rocks/zipcodewilmington/MainApplication.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 MainApplication {

}
Original file line number Diff line number Diff line change
Expand Up @@ -22,4 +22,6 @@ public static Cat createCat(String name, Date birthDate) {
Integer newId = CatHouse.getNumberOfCats();
return new Cat(name, birthDate, newId);
}


}
Original file line number Diff line number Diff line change
Expand Up @@ -10,22 +10,27 @@ public class CatHouse {
private static AnimalWarehouse<Cat> catHouse = new AnimalWarehouse<>();

public static void add(Cat cat) {

catHouse.add(cat);
}

public static void remove(Integer id) {

catHouse.removeAnimalById(id);
}

public static void remove(Cat cat) {

catHouse.removeAnimal(cat);
}

public static Cat getCatById(Integer id) {

return catHouse.getAnimalById(id);
}

public static Integer getNumberOfCats() {

return catHouse.getNumberOfAnimals();
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@ public class DogHouse {
private static AnimalWarehouse<Dog> dogHouse = new AnimalWarehouse<>();

public static void add(Dog dog) {

dogHouse.add(dog);
}

Expand All @@ -17,14 +18,17 @@ public static void remove(Integer id) {
}

public static void remove(Dog dog) {

dogHouse.removeAnimal(dog);
}

public static Dog getDogById(Integer id) {

return dogHouse.getAnimalById(id);
}

public static Integer getNumberOfDogs() {

return dogHouse.getNumberOfAnimals();
}

Expand Down
38 changes: 38 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,47 @@
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.text.ParseException;
import java.text.SimpleDateFormat;
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 testCreateDog() throws ParseException {
//given

AnimalFactory animalFactory = new AnimalFactory();
String expected ="karadi";
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = dateFormat.parse("02/01/2010");
//when
Dog dog = animalFactory.createDog(expected ,date);
//Then
Assert.assertEquals(expected,dog.getName());
}

@Test
public void testCreateCat() throws ParseException {
AnimalFactory animalFactory = new AnimalFactory();
String expected ="gundus";
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date date = dateFormat.parse("02/01/2010");
//when
Cat cat = animalFactory.createCat(expected, date);
//Then
Assert.assertEquals(expected,cat.getName());
}



}
54 changes: 54 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,10 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.animal_storage.CatHouse;

/**
* @author leon on 4/19/18.
*/
Expand All @@ -9,4 +14,53 @@ 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 testAddCat(){
CatHouse catHouse=new CatHouse();
String expected="marble";
Cat cat= new Cat(expected,null,null);
catHouse.add(cat);
Assert.assertEquals(expected,cat.getName());
}

@Test
public void testGetIntegerId(){
CatHouse catHouse =new CatHouse();
Integer expectedId=1;
Cat cat =new Cat(null,null,expectedId);
catHouse.add(cat);
Assert.assertEquals(cat,catHouse.getCatById(expectedId));
}

@Test
public void testRemoveIntegerId() {
CatHouse catHouse = new CatHouse();
Integer id = 1;
Cat cat =new Cat(null,null,id);
catHouse.add(cat);
catHouse.remove(id);
Assert.assertEquals(null, catHouse.getCatById(id));

}

@Test
public void testRemoveCat() {
CatHouse catHouse = new CatHouse();
Integer id = 1;
Cat cat =new Cat("cora",null,id);
catHouse.add(cat);
catHouse.remove(cat);
// catHouse.remove(id);
Assert.assertEquals(null,catHouse.getCatById(id));

}
@Test
public void testGetNumberOfCats(){
Integer expectedNumber=2;
CatHouse catHouse=new CatHouse();
Cat cat=new Cat(null,null,null);
catHouse.add(cat);
catHouse.add(cat);
Assert.assertEquals(expectedNumber,catHouse.getNumberOfCats());
}
}
82 changes: 82 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,14 @@

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.Mammal;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Date;

/**
Expand Down Expand Up @@ -40,4 +46,80 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}

@Test
public void setNameTest() {
//Given
String expected = "Cora";
Date date = new Date();
//When
Cat cat = new Cat(expected, date, 1);
cat.setName(expected);
//Then
Assert.assertEquals(expected,cat.getName());


}
@Test
public void speakTest(){
//Given
String expected = "meow!";
//When
Cat cat = new Cat(null, null , null);
//Then
Assert.assertEquals(expected, cat.speak());
}

@Test
public void testSetBirthDate() throws ParseException {
//given
SimpleDateFormat dateFormat = new SimpleDateFormat("MM/dd/yyyy");
Date expected = dateFormat.parse("02/01/2010");

//when
Cat cat=new Cat(null,null,null);
cat.setBirthDate(expected);

//then
Assert.assertEquals(expected,cat.getBirthDate());
}

@Test
public void testEat(){
ArrayList<Food> eatenMeals = new ArrayList<>();
Integer expected = 2;
Food food = new Food();
Cat cat= new Cat(null,null,null);
cat.eat(food);
cat.eat(food);

Assert.assertEquals(expected,cat.getNumberOfMealsEaten());

}

@Test
public void testIntegerGetId(){
//given
Cat cat = new Cat(null,null,null);
Integer expectedId = 1;

//when

//then
Assert.assertEquals(expectedId,cat.getId());
}

@Test
public void animalInheritanceTest(){
Cat cat = new Cat(null,null,null);
Assert.assertTrue(cat instanceof Animal);
}

@Test
public void mammalInheritanceTest(){
Cat cat = new Cat(null,null,null);
Assert.assertTrue(cat instanceof Mammal);
}

}


40 changes: 40 additions & 0 deletions src/test/java/rocks/zipcodewilmington/DogHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,6 +1,8 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import org.omg.CORBA.PUBLIC_MEMBER;
import rocks.zipcodewilmington.animals.Dog;
import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;
import rocks.zipcodewilmington.animals.animal_storage.DogHouse;
Expand Down Expand Up @@ -31,4 +33,42 @@ public void testGetNumberOfDogs() {
// Then
DogHouse.getNumberOfDogs();
}
@Test
public void testAddDog(){
DogHouse dogHouse=new DogHouse();
String expected="bear";
Dog dog =new Dog(expected,null,null);
dogHouse.add(dog);
Assert.assertEquals(expected,dog.getName());

}
@Test
public void testGetDogById(){
DogHouse dogHouse=new DogHouse();
Integer id=1;
Dog dog=new Dog(null,null,id);
dogHouse.add(dog);
Assert.assertEquals(dog,dogHouse.getDogById(id));

}
@Test
public void testRemoveIntegerId() {
DogHouse dogHouse = new DogHouse();
Integer id = 1;
Dog dog = new Dog(null, null, id);
dogHouse.add(dog);
dogHouse.remove(id);
Assert.assertEquals(null, dogHouse.getDogById(1));
}

@Test
public void testRemoveDog(){
DogHouse dogHouse=new DogHouse();
String expectedName="appukutts";
Integer id=1;
Dog dog=new Dog(expectedName,null,1);
dogHouse.add(dog);
dogHouse.remove(dog);
Assert.assertEquals(null,dogHouse.getDogById(1));
}
}
Loading