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

Lab complete #36

Open
wants to merge 6 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
39 changes: 39 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,48 @@
package rocks.zipcodewilmington;

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.animal_creation.AnimalFactory;

import java.util.Calendar;
import java.util.Date;

/**
* @author leon on 4/19/18.
*/
public class AnimalFactoryTest {
//TODO - Create Test for `Animal createDog(String name, Date birthDate)`
@Test
public void testCreateDog(){
//given
String expectedName = "Samantha";
Date expectedBirthDate = new Date(2000, Calendar.MAY,4);
//should this be type animal?
//when
Dog newDog = AnimalFactory.createDog(expectedName,expectedBirthDate);
String actualName = newDog.getName();
Date actualBirthDate = newDog.getBirthDate();
//then
Assert.assertEquals(expectedBirthDate,actualBirthDate);
Assert.assertEquals(expectedName,actualName);

}
//TODO - Create Test for `Animal createCat(String name, Date birthDate)`
@Test
public void testCreateCat(){
//given
String expectedName = "Rutherford";
Date expectedBirthDate = new Date(2019, Calendar.APRIL,8);
//when
Cat newCat = AnimalFactory.createCat(expectedName,expectedBirthDate);
String actualName = newCat.getName();
Date actualBirthDate = newCat.getBirthDate();
//then
Assert.assertEquals(expectedBirthDate,actualBirthDate);
Assert.assertEquals(expectedName,actualName);

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

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

import java.util.Calendar;
import java.util.Date;

/**
* @author leon on 4/19/18.
*/
public class CatHouseTest {
// TODO - Create tests for `void add(Cat cat)`
@Test
public void testAddCat(){
//given
Cat newCat = new Cat("Mckayla",new Date(2019, Calendar.JANUARY,1),1);
CatHouse.clear();
//when
CatHouse.add(newCat);
Cat actualCat = CatHouse.getCatById(1);
//then
Assert.assertEquals(newCat,actualCat);
}
@Test
public void testAddCat2(){
//given
Cat newCat = new Cat("Ckayla",new Date(209, Calendar.JANUARY,1),8);
CatHouse.clear();
//when
CatHouse.add(newCat);
Cat actualCat = CatHouse.getCatById(8);
//then
Assert.assertEquals(newCat,actualCat);
}
// TODO - Create tests for `void remove(Integer id)`
@Test
public void testRemoveByID(){
//given
Cat newCat = new Cat("Roberto",new Date(2019, Calendar.JANUARY,1),1);
CatHouse.clear();
CatHouse.add(newCat);
Cat expected = null;
//when
CatHouse.remove(1);
Cat actual = CatHouse.getCatById(1);
//then
Assert.assertEquals(expected,actual);
}
@Test
public void testRemoveByID2(){
//given
Cat newCat = new Cat("Oberto",new Date(19, Calendar.JANUARY,9),222);
CatHouse.clear();
CatHouse.add(newCat);
Cat expected = null;
//when
CatHouse.remove(222);
Cat actual = CatHouse.getCatById(222);
//then
Assert.assertEquals(expected,actual);
}
// TODO - Create tests for `void remove(Cat cat)`
@Test
public void testRemoveByCat(){
//given
Cat newCat = new Cat("Elijah",new Date(2019, Calendar.JANUARY,1),1);
CatHouse.clear();
CatHouse.add(newCat);
Cat expected = null;
//when
CatHouse.remove(newCat);
Cat actual = CatHouse.getCatById(1);
//then
Assert.assertEquals(expected,actual);
}
@Test
public void testRemoveByCat2(){
//given
Cat newCat = new Cat("Lijah",new Date(20199, Calendar.JANUARY,3),33);
CatHouse.clear();
CatHouse.add(newCat);
Cat expected = null;
//when
CatHouse.remove(newCat);
Cat actual = CatHouse.getCatById(33);
//then
Assert.assertEquals(expected,actual);
}
// TODO - Create tests for `Cat getCatById(Integer id)`
@Test
public void testGetCatById(){
//given
Cat expected = new Cat("Yolanda",new Date(2019, Calendar.JANUARY,1),1);
CatHouse.clear();
CatHouse.add(expected);
//when
Cat actual = CatHouse.getCatById(1);
//then
Assert.assertEquals(expected,actual);
}
@Test
public void testGetCatById2(){
//given
Cat expected = new Cat("Olanda",new Date(20219, Calendar.JANUARY,12),10923);
CatHouse.clear();
CatHouse.add(expected);
//when
Cat actual = CatHouse.getCatById(10923);
//then
Assert.assertEquals(expected,actual);
}
// TODO - Create tests for `Integer getNumberOfCats()`
@Test
public void testGetNumberOfCats(){
//given
Cat newCat = new Cat("Archimedes",new Date(2019, Calendar.JANUARY,1),1);
CatHouse.clear();
CatHouse.add(newCat);
Integer expected = 1;
//when
Integer actual = CatHouse.getNumberOfCats();
//then
Assert.assertEquals(expected,actual);

}
@Test
public void testGetNumberOfCats2(){
//given
Cat newCat2 = new Cat("Rchimedes",new Date(20139, Calendar.JANUARY,23),53);
CatHouse.clear();
CatHouse.add(newCat2);
Integer expected = 2;
Cat newCat = new Cat("Archimedes",new Date(2019, Calendar.JANUARY,1),1);
CatHouse.add(newCat);
//when
Integer actual = CatHouse.getNumberOfCats();
//then
Assert.assertEquals(expected,actual);

}
}
126 changes: 126 additions & 0 deletions src/test/java/rocks/zipcodewilmington/CatTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -2,21 +2,147 @@

import org.junit.Assert;
import org.junit.Test;
import rocks.zipcodewilmington.animals.Animal;
import rocks.zipcodewilmington.animals.Cat;
import rocks.zipcodewilmington.animals.Mammal;
import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;

import java.util.Calendar;
import java.util.Date;

/**
* @author leon on 4/19/18.
*/
public class CatTest {
// TODO - Create tests for `void setName(String name)`
@Test
public void testSetName(){
//given
Cat originalCat = AnimalFactory.createCat("Benjamin",new Date(2017, Calendar.OCTOBER,4));
String expectedName = "Jonathon";
//when
originalCat.setName("Jonathon");
String actualName = originalCat.getName();
//then
Assert.assertEquals(expectedName, actualName);
}
@Test
public void testSetName2(){
//given
Cat originalCat = AnimalFactory.createCat("Enjamin",new Date(217, Calendar.OCTOBER,4));
String expectedName = "Onathon";
//when
originalCat.setName("Onathon");
String actualName = originalCat.getName();
//then
Assert.assertEquals(expectedName, actualName);
}
// TODO - Create tests for `speak`
@Test
public void testSpeak(){
//given
Cat originalCat = AnimalFactory.createCat("Jeremiah",new Date(2016, Calendar.JUNE,2));
String expectedSound = "meow!";
//when
String actualSound = originalCat.speak();
//then
Assert.assertEquals(expectedSound, actualSound);
}
@Test
public void testSpeak2(){
//given
Cat originalCat = AnimalFactory.createCat("Eremiah",new Date(20, Calendar.JUNE,2));
String expectedSound = "meow!";
//when
String actualSound = originalCat.speak();
//then
Assert.assertEquals(expectedSound, actualSound);
}
// TODO - Create tests for `setBirthDate(Date birthDate)`
@Test
public void testSetBirthDate(){
//given
Cat originalCat = AnimalFactory.createCat("Penelope",new Date(2009, Calendar.FEBRUARY,3));
Date expected = new Date(1919, Calendar.SEPTEMBER,14);
//when
originalCat.setBirthDate(expected);
Date actual = originalCat.getBirthDate();
//then
Assert.assertEquals(expected, actual);
}
@Test
public void testSetBirthDate2(){
//given
Cat originalCat = AnimalFactory.createCat("Enelope",new Date(29, Calendar.FEBRUARY,9));
Date expected = new Date(1800, Calendar.NOVEMBER,29);
//when
originalCat.setBirthDate(expected);
Date actual = originalCat.getBirthDate();
//then
Assert.assertEquals(expected, actual);
}
// TODO - Create tests for `void eat(Food food)`
@Test
public void testEat(){
//given
Cat originalCat = AnimalFactory.createCat("Ichabod",new Date(2005, Calendar.AUGUST,3));
int expected = 1;
//when
originalCat.eat(new Food());
int actual = originalCat.getNumberOfMealsEaten();
//then
Assert.assertEquals(expected, actual);
}
@Test
public void testEat2(){
//given
Cat originalCat = AnimalFactory.createCat("Chabod",new Date(205, Calendar.AUGUST,4));
int expected = 2;
//when
originalCat.eat(new Food());
originalCat.eat(new Food());
int actual = originalCat.getNumberOfMealsEaten();
//then
Assert.assertEquals(expected, actual);
}

// TODO - Create tests for `Integer getId()`
@Test
public void testGetId(){
//given
Cat originalCat = new Cat("Horatio",new Date(1945, Calendar.AUGUST,3),3);
int expected = 3;
//when
int actual = originalCat.getId();
//then
Assert.assertEquals(expected, actual);
}
@Test
public void testGetId2(){
//given
Cat originalCat = new Cat("Oratio",new Date(195, Calendar.AUGUST,3),93);
int expected = 93;
//when
int actual = originalCat.getId();
//then
Assert.assertEquals(expected, actual);
}
// TODO - Create test to check Animal inheritance; google search `java instanceof keyword`
@Test
public void testAnimalInheritance(){
//given //when
Cat originalCat = new Cat("Jameson",new Date(1975, Calendar.AUGUST,3),3);
//then
Assert.assertTrue(originalCat instanceof Animal);
}
// TODO - Create test to check Mammal inheritance; google search `java instanceof keyword`
@Test
public void testMammalInheritance(){
//given //when
Cat originalCat = new Cat("Chrysanthemum",new Date(1975, Calendar.AUGUST,3),3);
//then
Assert.assertTrue(originalCat instanceof Mammal);
}


@Test
Expand Down
Loading