Skip to content

Completed all tests for the lab #33

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
5 changes: 5 additions & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Mammal.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,4 +50,9 @@ public void eat(Food food) {
public Integer getId() {
return id;
}

public Food getLastMealEaten() {
int lastIndex = eatenMeals.size() - 1;
return eatenMeals.get(lastIndex);
}
}
34 changes: 34 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,43 @@
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() {
String givenName = "Jafn";
Date givenDate = new Date();

Dog animal = AnimalFactory.createDog("Jafn", new Date());
String actualName = animal.getName();
Date actualDate = animal.getBirthDate();

Assert.assertEquals(actualName, givenName);
Assert.assertEquals(actualDate, givenDate);
}

@Test
public void createCatTest() {
String givenName = "Jacob";
Date givenDate = new Date();

Cat animal = AnimalFactory.createCat("Jacob", new Date());
String actualName = animal.getName();
Date actualDate = animal.getBirthDate();

Assert.assertEquals(actualName, givenName);
Assert.assertEquals(actualDate, givenDate);
}

}
59 changes: 59 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.Dog;
import rocks.zipcodewilmington.animals.animal_storage.CatHouse;
import rocks.zipcodewilmington.animals.animal_storage.DogHouse;

/**
* @author leon on 4/19/18.
*/
Expand All @@ -9,4 +16,56 @@ 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 addTest() {
CatHouse.clear();
Cat cat = new Cat(null, null, null);
CatHouse.add(cat);
Integer expected = 1;
Integer actual = CatHouse.getNumberOfCats();
Assert.assertEquals(actual, expected);
}

@Test
public void removeTestById() {
CatHouse.clear();
Cat cat = new Cat(null, null, 555);
CatHouse.add(cat);
CatHouse.remove(555);
Integer expected = 0;
Integer actual = CatHouse.getNumberOfCats();
Assert.assertEquals(actual, expected);
}

@Test
public void removeTestByCat() {
CatHouse.clear();
Cat cat = new Cat(null, null, 554);
CatHouse.add(cat);
CatHouse.remove(cat);
Integer expected = 0;
Integer actual = CatHouse.getNumberOfCats();
Assert.assertEquals(actual, expected);
}

@Test
public void getCatIdTest() {
CatHouse.clear();
Cat cat = new Cat(null, null, 54);
CatHouse.add(cat);
Cat actual = CatHouse.getCatById(54);
Assert.assertEquals(cat, actual);
}

@Test
public void getNumberOfCatsTest() {
CatHouse.clear();
Cat cat = new Cat(null, null, 51);
CatHouse.add(cat);
Integer expected = 1;
Integer actual = CatHouse.getNumberOfCats();
Assert.assertEquals(expected, actual);
}
}
// include the .clear() jawn
62 changes: 62 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,10 @@

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.util.Date;

Expand Down Expand Up @@ -40,4 +43,63 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}

@Test
public void setNameTest() {
// Given (a name exists and a dog exists)
Cat cat = new Cat(null, null, null);
String givenName = "Milo";

// When (a dog's name is set to the given name)
cat.setName(givenName);

// Then (we expect to get the given name from the dog)
String catName = cat.getName();
Assert.assertEquals(catName, givenName);
}

@Test
public void speakTest () {
String speakTest = "meow!";
Cat cat = new Cat(null, null, null);

Assert.assertEquals(speakTest, cat.speak());
}

@Test
public void setBirthDateTest () {
Date birthDate = new Date();
Cat cat = new Cat(null, birthDate, null);
Date actualBirthDate = cat.getBirthDate();

Assert.assertEquals(birthDate, actualBirthDate);
}

@Test
public void eatTest() {
Food food = new Food();
Cat cat = new Cat(null,null,null);
cat.eat(food);

Food lastMealEaten = cat.getLastMealEaten();
Assert.assertEquals(lastMealEaten, food);
}

@Test
public void getIdTest () {
Cat cat = new Cat(null, new Date(), 10);
Integer actualId = cat.getId();
Assert.assertEquals(actualId, 10, 0);
}

@Test
public void checkInheritanceAnimal () {
Cat cat = new Cat("Nathanial", new Date(), 13);
Assert.assertTrue(cat instanceof Animal);
}

@Test
public void checkInheritanceMammal () {
Cat cat = new Cat("Trash", new Date(), 69);
Assert.assertTrue(cat instanceof Mammal);
}
}
55 changes: 54 additions & 1 deletion src/test/java/rocks/zipcodewilmington/DogHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Dog;
import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;
Expand All @@ -23,12 +24,64 @@ public void testGetNumberOfDogs() {
String name = "Milo";
Date birthDate = new Date();
Dog animal = AnimalFactory.createDog(name, birthDate);
DogHouse.clear();
DogHouse.clear(); // include this on each test case!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!

// When
DogHouse.add(animal);

// Then
DogHouse.getNumberOfDogs();
}

@Test
public void addTest() {
DogHouse.clear();
Dog dog = new Dog(null, null,null);
DogHouse.add(dog);
Integer actual = 1;
Integer expected = DogHouse.getNumberOfDogs();
Assert.assertEquals(expected, actual);
}

@Test
public void removeByIdTest() {
DogHouse.clear();
Dog dog = new Dog(null, null,14);
DogHouse.add(dog);
DogHouse.remove(14);
Integer expected = 0;
Integer actual = DogHouse.getNumberOfDogs();
Assert.assertEquals(expected, actual);
}

@Test
public void removeByDogTest() {
DogHouse.clear();
Dog dog = new Dog(null, null,null);
DogHouse.add(dog);
DogHouse.remove(dog);
Integer actual = DogHouse.getNumberOfDogs();
Integer expected = 0;
Assert.assertEquals(actual, expected);
}

@Test
public void getDogByIdTest() {
DogHouse.clear();
Dog dog = new Dog(null, null,69);
DogHouse.add(dog);
Dog expected = DogHouse.getDogById(69);
Dog actual = dog;
Assert.assertEquals(actual, expected);
}

@Test
public void getNumberOfDogs() {
DogHouse.clear();
Dog dog = new Dog(null, null,null);
DogHouse.add(dog);
Integer actual = DogHouse.getNumberOfDogs();
Integer expected = 1;
Assert.assertEquals(expected, actual);
}
}
69 changes: 69 additions & 0 deletions src/test/java/rocks/zipcodewilmington/DogTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,11 @@

import org.junit.Assert;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Animal;
import rocks.zipcodewilmington.animals.Dog;
import rocks.zipcodewilmington.animals.Mammal;

import java.util.Date;

/**
* @author leon on 4/19/18.
Expand All @@ -28,4 +32,69 @@ public void setNameTest() {
String dogName = dog.getName();
Assert.assertEquals(dogName, givenName);
}

@Test
public void newDogTest() {
String givenName = "Chad";
Date givenBirthDate = new Date();
Integer givenId = 0;

Dog dog = new Dog (givenName, givenBirthDate, givenId);
String actualDogName = dog.getName();
Date actualDate = dog.getBirthDate();
Integer actualId = dog.getId();

Assert.assertEquals(givenName, actualDogName);
Assert.assertEquals(givenBirthDate, actualDate);
Assert.assertEquals(givenId, actualId);
}

@Test
public void speakTest() {
String speakTest = "bark!";
Dog dog = new Dog ("Spanky", new Date(), 5);

Assert.assertEquals(speakTest, dog.speak());
}

@Test
public void setBirthDateTest() {
Date birthDate = new Date();
Dog dog = new Dog("Alice" , birthDate, 24 );
Date actualBirthDate = dog.getBirthDate();

Assert.assertEquals(birthDate, actualBirthDate);
}

@Test
public void eatTest() {
Food food = new Food();
Dog dog = new Dog ("Edwin", new Date(), 15);
dog.eat(food);

Food lastMealEaten = dog.getLastMealEaten();

Assert.assertEquals(lastMealEaten, food);
}

@Test
public void getIdTest() {

Dog dog = new Dog ("Nathan", new Date(), 10);
Integer theNewId = dog.getId();

Assert.assertEquals(theNewId, 10,0);
}

@Test
public void checkInheritanceAnimal () {
Dog dog = new Dog("Nathanial", new Date(), 13);
Assert.assertTrue(dog instanceof Animal);
}

@Test
public void checkInheritanceMammal () {
Dog dog = new Dog("Trash", new Date(), 69);
Assert.assertTrue(dog instanceof Mammal);
}
}