|
@@ -0,0 +1,251 @@
|
|
1
|
+/*
|
|
2
|
+ * Copyright (c) 2006-2014 DMDirc Developers
|
|
3
|
+ *
|
|
4
|
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
5
|
+ * of this software and associated documentation files (the "Software"), to deal
|
|
6
|
+ * in the Software without restriction, including without limitation the rights
|
|
7
|
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
8
|
+ * copies of the Software, and to permit persons to whom the Software is
|
|
9
|
+ * furnished to do so, subject to the following conditions:
|
|
10
|
+ *
|
|
11
|
+ * The above copyright notice and this permission notice shall be included in
|
|
12
|
+ * all copies or substantial portions of the Software.
|
|
13
|
+ *
|
|
14
|
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
15
|
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
16
|
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
17
|
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
18
|
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
19
|
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
|
20
|
+ * THE SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+package com.dmdirc.actions.wrappers;
|
|
23
|
+
|
|
24
|
+import com.dmdirc.actions.wrappers.Profile;
|
|
25
|
+import com.dmdirc.interfaces.config.ConfigProvider;
|
|
26
|
+import com.dmdirc.interfaces.config.IdentityFactory;
|
|
27
|
+
|
|
28
|
+import java.util.ArrayList;
|
|
29
|
+import java.util.Arrays;
|
|
30
|
+import java.util.List;
|
|
31
|
+
|
|
32
|
+import org.junit.Test;
|
|
33
|
+import org.junit.runner.RunWith;
|
|
34
|
+import org.mockito.Mock;
|
|
35
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
36
|
+
|
|
37
|
+import static org.junit.Assert.assertEquals;
|
|
38
|
+import static org.junit.Assert.assertTrue;
|
|
39
|
+import static org.mockito.Mockito.mock;
|
|
40
|
+import static org.mockito.Mockito.verify;
|
|
41
|
+import static org.mockito.Mockito.when;
|
|
42
|
+
|
|
43
|
+/**
|
|
44
|
+ * Test profile class.
|
|
45
|
+ */
|
|
46
|
+@RunWith(MockitoJUnitRunner.class)
|
|
47
|
+public class ProfileTest {
|
|
48
|
+
|
|
49
|
+ @Mock private IdentityFactory identityFactory;
|
|
50
|
+
|
|
51
|
+ private Profile createProfile() {
|
|
52
|
+ final List<String> nicknames = new ArrayList<>();
|
|
53
|
+ nicknames.add("nickname1");
|
|
54
|
+ nicknames.add("nickname2");
|
|
55
|
+ final ConfigProvider configProvider = mock(ConfigProvider.class);
|
|
56
|
+ when(configProvider.getName()).thenReturn("profile");
|
|
57
|
+ when(configProvider.getOption("identity", "name")).thenReturn("profile");
|
|
58
|
+ when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
|
|
59
|
+ when(configProvider.getOption("profile", "realname")).thenReturn("realname");
|
|
60
|
+ when(configProvider.getOption("profile", "ident")).thenReturn("ident");
|
|
61
|
+
|
|
62
|
+ return new Profile(identityFactory, configProvider);
|
|
63
|
+ }
|
|
64
|
+
|
|
65
|
+ /**
|
|
66
|
+ * Test null profile constructor.
|
|
67
|
+ */
|
|
68
|
+ @Test
|
|
69
|
+ public void testEmptyConstructor() {
|
|
70
|
+ Profile instance = new Profile("New Profile", identityFactory);
|
|
71
|
+ assertEquals("", instance.getIdent());
|
|
72
|
+ assertEquals("New Profile", instance.getName());
|
|
73
|
+ assertEquals(new ArrayList<>(Arrays.asList("NewProfile")), instance.getNicknames());
|
|
74
|
+ assertEquals("New Profile", instance.getRealname());
|
|
75
|
+ }
|
|
76
|
+
|
|
77
|
+ /**
|
|
78
|
+ * Test null profile constructor.
|
|
79
|
+ */
|
|
80
|
+ @Test
|
|
81
|
+ public void testIdentityConstructor() {
|
|
82
|
+ Profile instance = createProfile();
|
|
83
|
+ assertEquals("ident", instance.getIdent());
|
|
84
|
+ assertEquals("profile", instance.getName());
|
|
85
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname2", })
|
|
86
|
+ .equals(instance.getNicknames()));
|
|
87
|
+ assertEquals("realname", instance.getRealname());
|
|
88
|
+ }
|
|
89
|
+
|
|
90
|
+ /**
|
|
91
|
+ * Test of addNickname method, of class Profile.
|
|
92
|
+ */
|
|
93
|
+ @Test
|
|
94
|
+ public void testAddNickname_String() {
|
|
95
|
+ Profile instance = createProfile();
|
|
96
|
+ instance.addNickname("nickname3");
|
|
97
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname2",
|
|
98
|
+ "nickname3"}).equals(instance.getNicknames()));
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ /**
|
|
102
|
+ * Test of addNickname method, of class Profile.
|
|
103
|
+ */
|
|
104
|
+ @Test
|
|
105
|
+ public void testAddNickname_String_Contains() {
|
|
106
|
+ Profile instance = createProfile();
|
|
107
|
+ instance.addNickname("nickname2");
|
|
108
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname2"})
|
|
109
|
+ .equals(instance.getNicknames()));
|
|
110
|
+ }
|
|
111
|
+
|
|
112
|
+ /**
|
|
113
|
+ * Test of addNickname method, of class Profile.
|
|
114
|
+ */
|
|
115
|
+ @Test
|
|
116
|
+ public void testAddNickname_String_int() {
|
|
117
|
+ Profile instance = createProfile();
|
|
118
|
+ instance.addNickname("nickname3", 0);
|
|
119
|
+ assertTrue(Arrays.asList(new String[]{"nickname3", "nickname1",
|
|
120
|
+ "nickname2"}).equals(instance.getNicknames()));
|
|
121
|
+ }
|
|
122
|
+
|
|
123
|
+ /**
|
|
124
|
+ * Test of addNickname method, of class Profile.
|
|
125
|
+ */
|
|
126
|
+ @Test
|
|
127
|
+ public void testAddNickname_String_int_Contains() {
|
|
128
|
+ Profile instance = createProfile();
|
|
129
|
+ instance.addNickname("nickname2", 0);
|
|
130
|
+ assertTrue(Arrays.asList(new String[]{"nickname1","nickname2"})
|
|
131
|
+ .equals(instance.getNicknames()));
|
|
132
|
+ }
|
|
133
|
+
|
|
134
|
+ /**
|
|
135
|
+ * Test of delNickname method, of class Profile.
|
|
136
|
+ */
|
|
137
|
+ @Test
|
|
138
|
+ public void testDelNickname() {
|
|
139
|
+ Profile instance = createProfile();
|
|
140
|
+ instance.delNickname("nickname2");
|
|
141
|
+ assertTrue(Arrays.asList(new String[]{"nickname1"})
|
|
142
|
+ .equals(instance.getNicknames()));
|
|
143
|
+ }
|
|
144
|
+
|
|
145
|
+ /**
|
|
146
|
+ * Test of save method, of class Profile.
|
|
147
|
+ */
|
|
148
|
+ @Test
|
|
149
|
+ public void testSave() {
|
|
150
|
+ final List<String> nicknames = new ArrayList<>();
|
|
151
|
+ nicknames.add("nickname1");
|
|
152
|
+ nicknames.add("nickname2");
|
|
153
|
+ final ConfigProvider configProvider = mock(ConfigProvider.class);
|
|
154
|
+ when(configProvider.getName()).thenReturn("profile");
|
|
155
|
+ when(configProvider.getOption("identity", "name")).thenReturn("profile");
|
|
156
|
+ when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
|
|
157
|
+ when(configProvider.getOption("profile", "realname")).thenReturn("realname");
|
|
158
|
+ when(configProvider.getOption("profile", "ident")).thenReturn("ident");
|
|
159
|
+
|
|
160
|
+ Profile instance = new Profile(identityFactory, configProvider);
|
|
161
|
+ instance.save();
|
|
162
|
+ verify(configProvider).setOption("identity", "name", "profile");
|
|
163
|
+ verify(configProvider).setOption("profile", "nicknames", nicknames);
|
|
164
|
+ verify(configProvider).setOption("profile", "realname", "realname");
|
|
165
|
+ verify(configProvider).setOption("profile", "ident", "ident");
|
|
166
|
+ }
|
|
167
|
+
|
|
168
|
+ @Test
|
|
169
|
+ public void testSaveNoConfig() {
|
|
170
|
+ final ConfigProvider configProvider = mock(ConfigProvider.class);
|
|
171
|
+
|
|
172
|
+ when(identityFactory.createProfileConfig("New Profile")).thenReturn(configProvider);
|
|
173
|
+
|
|
174
|
+ Profile instance = new Profile("New Profile", identityFactory);
|
|
175
|
+ instance.save();
|
|
176
|
+ verify(identityFactory).createProfileConfig("New Profile");
|
|
177
|
+ }
|
|
178
|
+
|
|
179
|
+ /**
|
|
180
|
+ * Test of editNickname method, of class Profile.
|
|
181
|
+ */
|
|
182
|
+ @Test
|
|
183
|
+ public void testEditNicknameOldEmpty() {
|
|
184
|
+ Profile instance = createProfile();
|
|
185
|
+ instance.editNickname("", "nickname3");
|
|
186
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname2"})
|
|
187
|
+ .equals(instance.getNicknames()));
|
|
188
|
+ }
|
|
189
|
+
|
|
190
|
+ /**
|
|
191
|
+ * Test of editNickname method, of class Profile.
|
|
192
|
+ */
|
|
193
|
+ @Test
|
|
194
|
+ public void testEditNicknameNewEmpty() {
|
|
195
|
+ Profile instance = createProfile();
|
|
196
|
+ instance.editNickname("nickname2", "");
|
|
197
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname2"})
|
|
198
|
+ .equals(instance.getNicknames()));
|
|
199
|
+ }
|
|
200
|
+
|
|
201
|
+ /**
|
|
202
|
+ * Test of editNickname method, of class Profile.
|
|
203
|
+ */
|
|
204
|
+ @Test
|
|
205
|
+ public void testEditNicknameSame() {
|
|
206
|
+ Profile instance = createProfile();
|
|
207
|
+ instance.editNickname("nickname2", "nickname2");
|
|
208
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname2"})
|
|
209
|
+ .equals(instance.getNicknames()));
|
|
210
|
+ }
|
|
211
|
+
|
|
212
|
+ /**
|
|
213
|
+ * Test of editNickname method, of class Profile.
|
|
214
|
+ */
|
|
215
|
+ @Test
|
|
216
|
+ public void testEditNickname() {
|
|
217
|
+ Profile instance = createProfile();
|
|
218
|
+ instance.editNickname("nickname2", "nickname3");
|
|
219
|
+ assertTrue(Arrays.asList(new String[]{"nickname1", "nickname3"})
|
|
220
|
+ .equals(instance.getNicknames()));
|
|
221
|
+ }
|
|
222
|
+
|
|
223
|
+ /**
|
|
224
|
+ * Test of delete method, of class Profile.
|
|
225
|
+ */
|
|
226
|
+ @Test
|
|
227
|
+ public void testDelete() {
|
|
228
|
+ final List<String> nicknames = new ArrayList<>();
|
|
229
|
+ nicknames.add("nickname1");
|
|
230
|
+ nicknames.add("nickname2");
|
|
231
|
+ final ConfigProvider configProvider = mock(ConfigProvider.class);
|
|
232
|
+ when(configProvider.getName()).thenReturn("profile");
|
|
233
|
+ when(configProvider.getOption("identity", "name")).thenReturn("profile");
|
|
234
|
+ when(configProvider.getOptionList("profile", "nicknames")).thenReturn(nicknames);
|
|
235
|
+ when(configProvider.getOption("profile", "realname")).thenReturn("realname");
|
|
236
|
+ when(configProvider.getOption("profile", "ident")).thenReturn("ident");
|
|
237
|
+
|
|
238
|
+ Profile instance = new Profile(identityFactory, configProvider);
|
|
239
|
+ instance.delete();
|
|
240
|
+ verify(configProvider).delete();
|
|
241
|
+ }
|
|
242
|
+
|
|
243
|
+ /**
|
|
244
|
+ * Test of delete method, of class Profile.
|
|
245
|
+ */
|
|
246
|
+ @Test
|
|
247
|
+ public void testDeleteNullIdentity() {
|
|
248
|
+ Profile instance = new Profile("New Profile", null);
|
|
249
|
+ instance.delete();
|
|
250
|
+ }
|
|
251
|
+}
|