-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathCatTest.java
More file actions
112 lines (87 loc) · 3.13 KB
/
CatTest.java
File metadata and controls
112 lines (87 loc) · 3.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
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.Mammal;
import rocks.zipcodewilmington.animals.animal_creation.AnimalFactory;
import java.util.Date;
/**
* @author leon on 4/19/18.
*/
public class CatTest {
// TODO - Create tests for `void setName(String name)`
@Test
public void setNameTest() {
Cat cat = AnimalFactory.createCat("Ayy", new Date());
String expected = "Ayy";
String actual = cat.getName();
Assert.assertEquals(expected, actual);
}
// TODO - Create tests for `speak`
@Test
public void speakTest() {
Cat cat = AnimalFactory.createCat("Bee", new Date());
Cat catdog = new Cat("Cee", new Date(), 3);
catdog.speak();
String expected = "meow!";
String actual = catdog.speak();
Assert.assertEquals(expected, actual);
}
// TODO - Create tests for `setBirthDate(Date birthDate)`
@Test
public void setBirthDateTest() {
Cat cat = AnimalFactory.createCat("Dee", new Date(01-1-2001));
Date actual = cat.getBirthDate();
Date expected = new Date(01-1-2001);
Assert.assertEquals(expected, actual);
}
// TODO - Create tests for `void eat(Food food)`
@Test
public void eatTest() {
Cat cat = new Cat("Eee", new Date(), 9);
Food food = new Food();
cat.eat(food);
Integer actual = cat.getNumberOfMealsEaten();
Integer expected = 1;
Assert.assertEquals(expected, actual);
}
// TODO - Create tests for `Integer getId()`
@Test
public void getIdTest() {
Cat cat = new Cat("Eff", new Date(), 5);
Integer expected = 5;
Integer actual = cat.getId();
Assert.assertEquals(expected, actual);
}
// TODO - Create test to check Animal inheritance; google search `java instanceof keyword`
@Test
public void animalInheritanceTest() {
Cat cat = new Cat("Gee", new Date(), 13);
Assert.assertTrue(cat instanceof Animal);
}
// TODO - Create test to check Mammal inheritance; google search `java instanceof keyword`
@Test
public void mammalInheritanceTest() {
Cat mammalCat = AnimalFactory.createCat("Ayche", new Date());
Assert.assertTrue(mammalCat instanceof Mammal);
}
@Test
public void constructorTest() {
// Given (cat data)
String givenName = "Zula";
Date givenBirthDate = new Date();
Integer givenId = 0;
// When (a cat is constructed)
Cat cat = new Cat(givenName, givenBirthDate, givenId);
// When (we retrieve data from the cat)
String retrievedName = cat.getName();
Date retrievedBirthDate = cat.getBirthDate();
Integer retrievedId = cat.getId();
// Then (we expect the given data, to match the retrieved data)
Assert.assertEquals(givenName, retrievedName);
Assert.assertEquals(givenBirthDate, retrievedBirthDate);
Assert.assertEquals(givenId, retrievedId);
}
}