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
6 changes: 6 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,10 @@
* @author leon on 4/19/18.
*/
public class Food {
private String name;
private Boolean isGross;
public Food(String name, boolean isGross){
this.name = name;
this.isGross = isGross;
}
}
47 changes: 47 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,56 @@
package rocks.zipcodewilmington;

import org.junit.Assert;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Dog;

import java.util.Date;

/**
* @author leon on 4/19/18.
*/

public class AnimalFactoryTest {

@Test
public void testCreateDog(){
Date date = new Date();
int id = 1;
String name = "Jeff";

Dog dog = new Dog(name, date, id);

Date expectedDate = dog.getBirthDate();
int expectedId = dog.getId();
String expectedName = dog.getName();

Assert.assertEquals(date, expectedDate);
Assert.assertEquals(id, expectedId);
Assert.assertEquals(name, expectedName);

}

@Test
public void createCat(){
Date date = new Date();
int id = 1;
String name = "Biggs";

Cat cat = new Cat(name, date, id);

Date expectedDate = cat.getBirthDate();
int expectedId = cat.getId();
String expectedName = cat.getName();

Assert.assertEquals(date, expectedDate);
Assert.assertEquals(id, expectedId);
Assert.assertEquals(name, expectedName);
}
//TODO - Create Test for `Animal createDog(String name, Date birthDate)`
//TODO - Create Test for `Animal createCat(String name, Date birthDate)`

}



65 changes: 61 additions & 4 deletions src/test/java/rocks/zipcodewilmington/CatHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,69 @@
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.
*/
public class CatHouseTest {
// TODO - Create tests for `void add(Cat cat)`
// TODO - Create tests for `void remove(Integer id)`
// TODO - Create tests for `void remove(Cat cat)`
// TODO - Create tests for `Cat getCatById(Integer id)`
@Test
public void addTest(){
Cat cat = new Cat("Bart", new Date(), 1);
CatHouse.add(cat);
Cat actual = CatHouse.getCatById(cat.getId());

Assert.assertEquals(cat, actual);
}

@Test
public void removeTestById(){
Cat cat = new Cat("Joseph", new Date(), 1);
CatHouse.add(cat);
CatHouse.remove(cat.getId());

Object actual = CatHouse.getCatById(cat.getId());

Assert.assertNull(actual);
}

@Test
public void removeTest(){
Cat cat = new Cat("Joseph", new Date(), 1);
CatHouse.add(cat);
CatHouse.remove(cat);

Object actual = CatHouse.getCatById(cat.getId());

Assert.assertNull(actual);
}

@Test
public void getCatByIdTest(){
Cat expected = new Cat("Joseph", new Date(), 1);
CatHouse.add(expected);

Object actual = CatHouse.getCatById(expected.getId());

Assert.assertEquals(actual, expected);
}

@Test
public void getNumberOfCatsTests(){
Cat catA = new Cat("Joseph", new Date(), 1);
Cat catB = new Cat("Bella", new Date(), 2);
CatHouse.add(catA);
CatHouse.add(catB);

int expected = 2;
int actual = CatHouse.getNumberOfCats();

Assert.assertEquals(actual, expected);
}
// TODO - Create tests for `Integer getNumberOfCats()`
}

87 changes: 81 additions & 6 deletions src/test/java/rocks/zipcodewilmington/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,22 +2,97 @@

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.Calendar;
import java.util.Date;
import java.util.GregorianCalendar;

/**
* @author leon on 4/19/18.
*/
public class CatTest {
// TODO - Create tests for `void setName(String name)`
// TODO - Create tests for `speak`
// TODO - Create tests for `setBirthDate(Date birthDate)`
// TODO - Create tests for `void eat(Food food)`
// TODO - Create tests for `Integer getId()`
// TODO - Create test to check Animal inheritance; google search `java instanceof keyword`

// TODO - Create test to check Mammal inheritance; google search `java instanceof keyword`
@Test
public void checkMammalInheritance(){
Cat cat = new Cat("Joe", new Date(), 7);

Boolean actual = cat instanceof Mammal;

Boolean expected = true;
Assert.assertEquals(actual, expected);
}

@Test
public void checkAnimalInheritance(){
Cat cat = new Cat("Vivian", new Date(), 6);

Boolean actual = cat instanceof Animal;

Boolean expected = true;
Assert.assertEquals(actual, expected);
}

@Test
public void getIdTest(){
Cat cat = new Cat("Borscht", new Date(), 5);

int expected = 5;
int actual = cat.getId();

Assert.assertEquals(expected, actual);
}

@Test
public void eatTest(){
Cat cat = new Cat("Sadie", new Date(), 4);
Food food = new Food("Spaghetti", true);

cat.eat(food);
int actual = cat.getNumberOfMealsEaten();
int expected = 1;

Assert.assertEquals(actual, expected);
}

@Test
public void speakTest(){
Cat cat = new Cat("Marvin", new Date(), 3);

String actual = cat.speak();
String expected = "meow";

Assert.assertEquals(actual, expected);
}


@Test
public void setBirthDate(){
Cat cat = new Cat("Johnny", new Date(), 1);

Date expected = new GregorianCalendar(2011, Calendar.MARCH, 11).getTime();

cat.setBirthDate(expected);

Date actual = cat.getBirthDate();

Assert.assertEquals(actual, expected);
}

@Test
public void setNameTest(){
Cat cat = new Cat("Tess", new Date(), 2);

cat.setName("Beff");

String actual = cat.getName();
String expected = "Beff";

Assert.assertEquals(actual, expected);
}

@Test
public void constructorTest() {
Expand Down
53 changes: 53 additions & 0 deletions 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 @@ -17,6 +18,58 @@ public class DogHouseTest {
// TODO - Create tests for `Dog getDogById(Integer id)`
// TODO - Create tests for `Integer getNumberOfDogs()`

@Test
public void getNumberOfDogs(){
Dog animal = new Dog("Aldo", new Date(), 5);
DogHouse.add(animal);
Integer actual = DogHouse.getNumberOfDogs();
Integer expected = 1;

Assert.assertEquals(actual, expected);
}


@Test
public void getDogByIdTest(){
Dog animal = new Dog("Miff", new Date(), 1);
Integer actual = animal.getId();
Integer expected = 1;

Assert.assertEquals(actual, expected);
}

@Test
public void removeTest2(){
Dog animal = new Dog("Bean", new Date(), 2);
DogHouse.add(animal);
DogHouse.remove(animal);
Integer expected = 3;
Integer actual = DogHouse.getNumberOfDogs();

Assert.assertEquals(expected, actual);
}

@Test
public void removeTest(){
Dog animal = new Dog("George", new Date(), 3);
DogHouse.add(animal);
DogHouse.remove(animal.getId());
Integer expected = 0;
Integer actual = DogHouse.getNumberOfDogs();

Assert.assertEquals(expected, actual);
}

@Test
public void testAddDog(){
Dog animal = new Dog("Brandon", new Date(), 4);
DogHouse.add(animal);
Integer expected = 1;
Integer actual = DogHouse.getNumberOfDogs();

Assert.assertEquals(expected, actual);
}

@Test
public void testGetNumberOfDogs() {
// Given (some
Expand Down
Loading