-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathPetTest.java
More file actions
78 lines (60 loc) · 1.76 KB
/
PetTest.java
File metadata and controls
78 lines (60 loc) · 1.76 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;
import org.junit.Assert;
import org.junit.Test;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.*;
public class PetTest {
@Test
public void setNameTest() {
//Given
Dog dog = new Dog("Molly");
//When
String expected = "Molly";
dog.setPetName(expected);
String actual = dog.getName();
//Then
Assert.assertEquals(expected, actual);
}
@Test
public void compareToTest() {
//Given
ArrayList<Pet> tempList = new ArrayList<>();
Dog bun = new Dog("Bun");
Dog mun = new Dog("Mun");
Cat fun = new Cat("Fun");
Cat hun = new Cat("Hun");
Unicorn run = new Unicorn("Run");
tempList.add(bun);
tempList.add(mun);
tempList.add(fun);
tempList.add(hun);
tempList.add(run);
//When
Pet[] expected = {bun, fun, hun, mun, run};
Collections.sort(tempList);
Pet[] actual = tempList.toArray(new Pet[tempList.size()]);
//When
Assert.assertTrue(Arrays.equals(expected,actual));
}
@Test
public void compareTest(){
//Given
Application app = new Application();
Dog bun = new Dog("Bun");
Cat fun = new Cat("Fun");
Unicorn run = new Unicorn("Run");
Unicorn sun = new Unicorn("Sun");
app.collectionOfPets.add(bun);
app.collectionOfPets.add(fun);
app.collectionOfPets.add(run);
app.collectionOfPets.add(sun);
//When
Collections.sort(app.collectionOfPets,new PetCompare());
Pet[] expected = {bun, fun, run, sun};
Pet[] actual = app.collectionOfPets.toArray(new Pet[app.collectionOfPets.size()]);
//When
Assert.assertTrue(Arrays.equals(expected,actual));
}
}