-
Notifications
You must be signed in to change notification settings - Fork 0
/
TagManagerTest.java
158 lines (140 loc) · 5.29 KB
/
TagManagerTest.java
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
package photo_renamer;
import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import java.io.File;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import static org.junit.Assert.assertEquals;
/** A class for testing TagManager. */
public class TagManagerTest {
/** The TagManager being tested. */
private TagManager tagManager;
/** The path where the tested TagManager database is stored. */
private String path = System.getProperty("user.dir") + "/TagManagerTest.txt";
@Before
/* Set up a new TagManager for testing. */
public void setUp() throws Exception {
tagManager = new TagManager(path);
}
@Test
/* Test retrieving the list of managed Tags from a new, empty TagManager. */
public void testEmpty() throws Exception {
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>();
assertEquals(expected, result);
}
@Test
/* Test adding a single new Tag to the TagManager. */
public void testAddOne() throws Exception {
Tag red = new Tag("red");
tagManager.addTag(red);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>(Collections.singletonList(red));
assertEquals(expected, result);
}
@Test
/* Test adding a multiple new Tags to the TagManager. */
public void testAddMultiple() throws Exception {
Tag blue = new Tag("blue");
Tag green = new Tag("green");
tagManager.addTag(blue);
tagManager.addTag(green);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>(Arrays.asList(blue, green));
assertEquals(expected, result);
}
@Test
/* Test adding an identical Tag object in the TagManager twice. */
public void testAddExactDuplicate() throws Exception {
Tag pink = new Tag("pink");
tagManager.addTag(pink);
tagManager.addTag(pink);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>(Collections.singletonList(pink));
assertEquals(expected, result);
}
@Test
/* Test adding two different Tags with the same name attribute in the TagManager. */
public void testAddNameDuplicate() throws Exception {
Tag blue = new Tag("blue");
Tag bleu = new Tag("blue");
tagManager.addTag(blue);
tagManager.addTag(bleu);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>(Collections.singletonList(blue));
assertEquals(expected, result);
}
@Test
/* Test adding Tags with the same name, but different cases. */
public void testAddCasingDuplicate() throws Exception {
Tag orange = new Tag("orange");
Tag redYellow = new Tag("Orange");
tagManager.addTag(orange);
tagManager.addTag(redYellow);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>(Collections.singletonList(orange));
assertEquals(expected, result);
}
@Test
/* Test removing a Tag from an empty TagManager. */
public void testRemoveNonexistent() throws Exception {
Tag cat = new Tag("cat");
tagManager.removeTag(cat);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>();
assertEquals(expected, result);
}
@Test
/* Test removing a Tag that exists within the TagManager. */
public void testRemoveExistent() throws Exception {
Tag cat = new Tag("cat");
tagManager.addTag(cat);
tagManager.removeTag(cat);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>();
assertEquals(expected, result);
}
@Test
/* Test removing a Tag that exists with alternate casing within the TagManager. */
public void testRemoveExistentCasing() throws Exception {
Tag cat = new Tag("cat");
Tag bulldozer = new Tag("CAT");
tagManager.addTag(cat);
tagManager.removeTag(bulldozer);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>();
assertEquals(expected, result);
}
@Test
/* Test Tag removal with other Tags remaining within the TagManager. */
public void testRemoveSingle() throws Exception {
Tag cat = new Tag("cat");
Tag dog = new Tag("dog");
tagManager.addTag(cat);
tagManager.addTag(dog);
tagManager.removeTag(cat);
Object result = tagManager.tags;
ArrayList<Tag> expected = new ArrayList<>(Collections.singletonList(dog));
assertEquals(expected, result);
}
@Test
/* Test writing to and reading from a TagManager database file. */
public void testWriteRead() throws Exception {
Tag cat = new Tag("cat");
Tag dog = new Tag("dog");
tagManager.addTag(cat);
tagManager.addTag(dog);
TagManager tagBoss = new TagManager(path);
Object result = tagBoss.tags;
ArrayList<Tag> expected = new ArrayList<>(Arrays.asList(cat, dog));
assertEquals(expected, result);
}
@After
/* Delete system artifacts generated by TagManager testing. */
public void tearDown() throws Exception {
File database = new File(path);
database.delete();
}
}