-
Notifications
You must be signed in to change notification settings - Fork 45
Expand file tree
/
Copy pathDogTest.java
More file actions
78 lines (66 loc) · 1.74 KB
/
DogTest.java
File metadata and controls
78 lines (66 loc) · 1.74 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
package io.zipcoder.petsTest;
import io.zipcoder.pets.Animal;
import io.zipcoder.pets.Dog;
import io.zipcoder.pets.Pet;
import org.junit.Assert;
import org.junit.Test;
public class DogTest {
@Test
public void dogConstructorTest(){
//Given
String givenName = "Sparky";
Integer givenId = 0;
//When
Dog dog = new Dog(givenName, givenId);
String retrievedName = dog.getName();
Integer retrievedId = dog.getId();
//Then
Assert.assertEquals(givenName, retrievedName);
Assert.assertEquals(givenId, retrievedId);
}
@Test
public void speakTest(){
//given
Dog dog = new Dog("Sparky", 0);
String bark = "Bark!";
//when
String retrievedSpeak = dog.speak();
//then
Assert.assertEquals(bark, retrievedSpeak);
}
@Test
public void getIdTest(){
//given
Integer givenId = 1;
Dog dog = new Dog("Sparky", givenId);
//when
Integer retrievedId = dog.getId();
//then
Assert.assertEquals(givenId, retrievedId);
}
@Test
public void inheritanceOfPetTest(){
//given
Dog dog = new Dog("Sparky", 0);
//then
Assert.assertTrue(dog instanceof Pet);
}
@Test
public void inheritanceOfAnimalTest(){
//given
Dog dog = new Dog("Sparky", 0);
//then
Assert.assertTrue(dog instanceof Animal);
}
@Test
public void setNameTest() {
// Given
Dog dog = new Dog(null, null);
String givenName = "Milo";
// When
dog.setName(givenName);
// Then
String dogName = dog.getName();
Assert.assertEquals(dogName, givenName);
}
}