-
Notifications
You must be signed in to change notification settings - Fork 64
Expand file tree
/
Copy pathApplicationTest.java
More file actions
74 lines (66 loc) · 2.38 KB
/
ApplicationTest.java
File metadata and controls
74 lines (66 loc) · 2.38 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
package io.zipcoder.pets;
import org.junit.Test;
import org.junit.Assert;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
public class ApplicationTest {
@Test
public void testCreatePetList(){
Application app = new Application();
Pets dog = PetFactory.createPets("dog", "Sandy");
String expected = "Sandy";
ArrayList<Pets> pets = new ArrayList<>(Arrays.asList(dog));
app.setPetList(pets);
String actual = app.getPetList().get(0).getName();
Assert.assertEquals(expected, actual);
}
@Test
public void testPetsToString(){
Application app = new Application();
String expected = "My name is Sandy and I say Woof. ";
Pets dog = PetFactory.createPets("dog", "Sandy");
ArrayList<Pets> pets = new ArrayList<>(Arrays.asList(dog));
app.setPetList(pets);
String actual = app.toString();
Assert.assertEquals(expected, actual);
}
@Test
public void testCompareByName(){
//Given
Application app = new Application();
Pets dog = new Dog("Sandy");
Pets dog1 = new Dog("Molly");
Pets cat = new Cat("Sandy");
Pets cat1 = new Cat("Andy");
Pets parrot = new Parrot("Id");
ArrayList<Pets> pets = new ArrayList<>(Arrays.asList(dog, dog1, cat, cat1, parrot));
ArrayList<Pets> expected = new ArrayList<>(Arrays.asList(cat1, parrot, dog1, cat, dog));
app.setPetList(pets);
//When
app.sortPetsByName();
//Then
ArrayList<Pets> actual = app.getPetList();
Assert.assertEquals(expected, actual);
}
@Test
public void testCompareByType() {
//Given
Application app = new Application();
Pets dog1 = new Dog("Sandy");
Pets dog2 = new Dog("Molly");
Pets dog3 = new Dog("Ally");
Pets cat = new Cat("Sandy");
Pets cat1 = new Cat("Andy");
Pets parrot = new Parrot("Id");
ArrayList<Pets> pets = new ArrayList<>(Arrays.asList(dog1, dog2, dog3, cat, cat1, parrot));
ArrayList<Pets> expected = new ArrayList<>(Arrays.asList(cat1, cat, dog3, dog2, dog1, parrot));
app.setPetList(pets);
//When
app.sortPetsByType();
ArrayList<Pets> actual = app.getPetList();
//Then
Assert.assertEquals(expected, actual);
}
}