-
Notifications
You must be signed in to change notification settings - Fork 51
Expand file tree
/
Copy pathCatTest.java
More file actions
169 lines (159 loc) · 5.47 KB
/
CatTest.java
File metadata and controls
169 lines (159 loc) · 5.47 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
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
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.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
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);
}
}