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

Completed Lab #12

Open
wants to merge 7 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
11 changes: 10 additions & 1 deletion src/main/java/rocks/zipcodewilmington/animals/Cat.java
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,20 @@
* @author leon on 4/19/18.
*/
public class Cat extends Mammal {


String name;
Integer birthDate;


public Cat(String name, Date birthDate, Integer id) {
super(name, birthDate, id);
}

public String speak() {
return "meow!";
}
}


}

1 change: 1 addition & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Mammal.java
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ public Integer getNumberOfMealsEaten() {

public void eat(Food food) {
eatenMeals.add(food);

}

@Override
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.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;
import rocks.zipcodewilmington.animals.Animal;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Dog;
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)`

@Before
public void setup() {
}

@After
public void tearDown() {
}

@Test
public void testCreateDog() {
Dog dog1 = AnimalFactory.createDog("spot", new Date(1));
String expected1 = "spot";
Date expected2 = new Date(1);
String actual1 = dog1.getName();
Date actual2 = dog1.getBirthDate();
Assert.assertEquals(expected1, actual1);
Assert.assertEquals(expected2, actual2);
}

@Test
public void testCreateCat() {
Cat cat2 = AnimalFactory.createCat("fido", new Date(1));
String expected1 = "fido";
Date expected2 = new Date(1);
String actual1 = cat2.getName();
Date actual2 = cat2.getBirthDate();
Assert.assertEquals(expected1, actual1);
Assert.assertEquals(expected2, actual2);
}





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

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
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.ArrayList;
import java.util.Date;

/**
* @author leon on 4/19/18.
*/
Expand All @@ -9,4 +22,63 @@ 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()`


@Before
public void setUp() {

}

@After
public void tearDown() {
CatHouse.clear();
}

@Test
public void testAddCat() {
Cat cat3 = new Cat("tom", new Date(), 2);
CatHouse.add(cat3);
Cat expected = cat3;
Cat actual = CatHouse.getCatById(2);
Assert.assertEquals(expected, actual);
}


@Test
public void testRemoveCat() {
Cat cat1 = new Cat("Sheila", new Date(), 2);
Cat cat2 = new Cat("Bob", new Date(), 4);
CatHouse.add(cat1);
CatHouse.add(cat2);
CatHouse.remove(cat2);
Integer expected = 1;
Integer actual = CatHouse.getNumberOfCats();
Assert.assertEquals(expected, actual);
}

@Test
public void testGetCatById() {
Cat cat3 = new Cat("simon", new Date(), 4);
CatHouse.add(cat3);
Cat expected = cat3;
Cat actual = CatHouse.getCatById(4);
Assert.assertEquals(expected, actual);
}


}















87 changes: 86 additions & 1 deletion src/test/java/rocks/zipcodewilmington/CatTest.java
Original file line number Diff line number Diff line change
@@ -1,15 +1,97 @@
package rocks.zipcodewilmington;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Animal;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Mammal;

import java.util.ArrayList;
import java.util.Date;

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


@Before
public void setup() {
}

@After
public void tearDown() {
};

@Test
public void testSetName() {
Cat cat = new Cat("Fluffy the Marshmallow", new Date(4), 2);
String expected = "Mr. Cat";
cat.setName(expected);
String actual = cat.getName();
Assert.assertEquals(expected,actual);
}

@Test
public void testSetBirthDate() {
Cat cat = new Cat("Fluffy the Marshmallow", new Date(4), 2);
Date expected = new Date();
cat.setBirthDate(new Date());
Date actual = cat.getBirthDate();
Assert.assertEquals(expected, actual);
}

@Test
public void testSpeak() {
Cat cat = new Cat("Fluffy the Marshmallow", new Date(4), 2);
String expected = "meow!";
String actual = cat.speak();
Assert.assertEquals(expected, actual);
}

@Test
public void testEat() {
Cat cat = new Cat("Fluffy the Marshmallow", new Date(4), 2);
Food kittyChow = new Food();
Integer expected = 1;
cat.eat(kittyChow);
Integer actual = cat.getNumberOfMealsEaten();
Assert.assertEquals(expected, actual);
}

@Test
public void testGetId() {
Cat cat = new Cat("Maira", new Date(4), 1);
int actual = cat.getId();
Assert.assertEquals(1, actual);
}

@Test
public void testIsInstanceOfAnimal() {
Cat cat = new Cat("Maira", new Date(4), 1);
boolean actual = cat instanceof Animal;
Assert.assertEquals(true, actual);
}

@Test
public void testIsInstanceOfMammal() {
Cat cat = new Cat("Maira", new Date(4), 1);
boolean actual = cat instanceof Mammal;
Assert.assertEquals(true, actual);
}




/* @Test
public void testEat() {
Cat cat = new Cat() {
Food expected =
}*/


// 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 +122,7 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}

}

}


77 changes: 65 additions & 12 deletions src/test/java/rocks/zipcodewilmington/DogHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
package rocks.zipcodewilmington;

import org.junit.After;
import org.junit.Assert;
import org.junit.Before;
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.ArrayList;
import java.util.Date;

/**
Expand All @@ -17,18 +23,65 @@ public class DogHouseTest {
// TODO - Create tests for `Dog getDogById(Integer id)`
// TODO - Create tests for `Integer getNumberOfDogs()`

@Before
public void setUp() {

}

@After
public void tearDown() {
DogHouse.clear();
}

@Test
public void testGetNumberOfDogs() {
// Given (some
String name = "Milo";
Date birthDate = new Date();
Dog animal = AnimalFactory.createDog(name, birthDate);
DogHouse.clear();

// When
DogHouse.add(animal);

// Then
DogHouse.getNumberOfDogs();
public void testAddDog() {
DogHouse dogHut = new DogHouse();
Dog cat3 = new Dog("tom", new Date(), 2);
dogHut.add(cat3);
Dog expected = cat3;
Dog actual = dogHut.getDogById(2);
Assert.assertEquals(expected, actual);
}


@Test
public void testRemoveDog() {
DogHouse dogHut = new DogHouse();
Dog dog1 = new Dog("Sheila", new Date(), 2);
Dog dog2 = new Dog("Bob", new Date(), 4);
dogHut.add(dog1);
dogHut.add(dog2);
dogHut.remove(dog2);
Integer expected = 1;
Integer actual = dogHut.getNumberOfDogs();
Assert.assertEquals(expected, actual);
}

@Test
public void testGetDogById() {
DogHouse dogHut = new DogHouse();
Dog dog3 = new Dog("simon", new Date(), 4);
dogHut.add(dog3);
Dog expected = dog3;
Dog actual = dogHut.getDogById(4);
Assert.assertEquals(expected, actual);
}


}
















Loading