Skip to content

more test #28

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
3 changes: 3 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,7 @@
* @author leon on 4/19/18.
*/
public class Food {

//private String

}
4 changes: 4 additions & 0 deletions src/main/java/rocks/zipcodewilmington/animals/Cat.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,10 @@ public Cat(String name, Date birthDate, Integer id) {
super(name, birthDate, id);
}

public Cat(String name){
super(name);
}

public String speak() {
return "meow!";
}
Expand Down
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 @@ -20,6 +20,11 @@ public Mammal(String name, Date birthDate, Integer id) {
this.eatenMeals = new ArrayList<>();
this.id = id;
}
public Mammal(String name){
this.name = name;
this.birthDate = null;
this.id = 0;
}

public String getName() {
return name;
Expand Down
42 changes: 42 additions & 0 deletions src/test/java/rocks/zipcodewilmington/AnimalFactoryTest.java
Original file line number Diff line number Diff line change
@@ -1,9 +1,51 @@
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 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)`



@Test
public void createCat(){
//GIVEN
String nombre = "carlos";
Date givenBirthDate = new Date();
Integer id = 0;
DogHouse.clear();
//WHEN
Cat cat = AnimalFactory.createCat(nombre, givenBirthDate);
//THEN
Assert.assertEquals(nombre, cat.getName());
}

@Test
public void creatDog(){
//GIVEN
String nombre = "mikey";
Date givenBirthDate = new Date();
Integer id = 0;
DogHouse.clear();
//WHEN

Dog dog = AnimalFactory.createDog("mikey", null);

//THEN
Assert.assertEquals(nombre, dog.getName());
}


}

113 changes: 109 additions & 4 deletions src/test/java/rocks/zipcodewilmington/CatHouseTest.java
Original file line number Diff line number Diff line change
@@ -1,12 +1,117 @@
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 rocks.zipcodewilmington.animals.animal_storage.DogHouse;

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 `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)`
// TODO - Create tests for `Integer getNumberOfCats()`
// TODO - Create tests for `Integer getNumberOfCats()` //////




@Test
public void catAddTest (){
//GIVEN
CatHouse.clear();

//WHEN
Cat gatito = AnimalFactory.createCat("ggg", null);
CatHouse.add(gatito);
int expected = 1;

int actual = CatHouse.getNumberOfCats();
//THEN
Assert.assertEquals(1 ,actual);


}

@Test
public void catRemoveTest(){
//GIVEN
CatHouse.clear();


//WHEN
Cat noGato = new Cat(null, null, null);
CatHouse.add(noGato);
CatHouse.remove(noGato);

int actual = CatHouse.getNumberOfCats();

//THEN
Assert.assertEquals(0 , actual);

}

@Test
public void removebyId(){
//GIVEN
CatHouse.clear();

//WHEN
Cat cat = new Cat(null, null, 0);
CatHouse.add(cat);
CatHouse.remove(cat.getId());
int actual = cat.getId();
//int expected = 0;
//int actual = CatHouse.getNumberOfCats();

//THEN
Assert.assertEquals(0 , actual);

}

@Test
public void getNumberOfCats (){
//GIVEN
String givenName = "kitty";
Date givenBirthDate = new Date();
Integer givenId = 6;
Cat cat = new Cat("Kitty", null, 6); //tambien works w/ givenName, givenBirthDate...
CatHouse.add(cat);

//WHEN
Cat actual = CatHouse.getCatById(givenId);


//THEN
Assert.assertEquals(cat, actual);

}

/*@Test
public void NumberOfCats(){

//GIVEN
String givenName = "kitty";
Date givenBirthDate = new Date();
Integer givenId = 6;
Cat cat = new Cat("Kitty", null, 6); //tambien works w/ givenName, givenBirthDate...
CatHouse.add(cat);

//WHEN
;


//THEN
Assert.assertEquals(cat, actual);*/

}




120 changes: 120 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,121 @@ public void constructorTest() {
Assert.assertEquals(givenId, retrievedId);
}


@Test
public void setNameTest(){

String expected = "Gatito";

Cat cat = new Cat("Gatito");
//cat.setName(expected);
String actual = cat.getName();

Assert.assertEquals(expected,actual); //actual es el given
}




@Test
public void speakTest() {
String expected = "meow!";

Cat cat = new Cat(null, null, null);
cat.speak();

String actual = cat.speak();
//THEN
Assert.assertEquals(expected, actual);
}

@Test
public void setBirthDate(){
Date expBirthDate = new Date(21-2-2001); // still pass if nada adentro en los parameters.

Cat cat = new Cat("gato", expBirthDate, 0); // still pass if pu null for all 3.
cat.setBirthDate(expBirthDate);

Date actualBirthDate = cat.getBirthDate();
Assert.assertEquals(expBirthDate, actualBirthDate);

}

@Test // es igual q set name test
public void setNamesTest(){
//GIVEN
String givenName = "Zula";
Date givenBirthDate = new Date();
Integer givenId = 0;

//WHEN
String expected = "cheese";
Cat cat = new Cat(null, null,null);
cat.setName(expected);
String actual = cat.getName();

//THEN
Assert.assertEquals(expected, actual);
}

@Test
public void eatTest() {
int expected = 0;


Cat cat = new Cat(null, null, null);
Food food = new Food();
int actual = cat.getNumberOfMealsEaten();
cat.eat(food);

Assert.assertEquals(expected, actual);
}


@Test
public void getId() {
int expected = 0;

Cat cat = new Cat(null, null, 0);
int actual = cat.getId();

Assert.assertEquals(expected, actual);

}


@Test
public void animalInheritanceTest (){
//given
String givenName = "CARROTS";
Date givenBirthDate = new Date();
Integer givenId = 0;

//when
Cat cat = new Cat(null, null, 0);
boolean expected = true;
boolean actual = cat instanceof Animal;
//then
Assert.assertEquals(expected, actual);
}

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

//when
Cat cat = new Cat(null, null, 0);
boolean expected = true;
boolean actual = cat instanceof Mammal;
//then
Assert.assertEquals(expected, actual);
}

}





Loading