|
@@ -56,27 +56,28 @@ public class CoreProfilesDialogModelTest {
|
56
|
56
|
private MutableProfile mutableProfile1;
|
57
|
57
|
private MutableProfile mutableProfile2;
|
58
|
58
|
private MutableProfile mutableProfile3;
|
|
59
|
+ private MutableProfile mutableProfile4;
|
59
|
60
|
private List<MutableProfile> mutableProfiles;
|
60
|
61
|
private CoreProfilesDialogModel instance;
|
61
|
|
- private Profile profile1;
|
62
|
|
- private Profile profile2;
|
63
|
|
- private Profile profile3;
|
64
|
62
|
|
65
|
63
|
@Before
|
66
|
64
|
public void setupMocks() {
|
67
|
|
- profile1 = getProfile(1);
|
68
|
|
- profile2 = getProfile(2);
|
69
|
|
- profile3 = getProfile(3);
|
|
65
|
+ final Profile profile1 = getProfile(1);
|
|
66
|
+ final Profile profile2 = getProfile(2);
|
|
67
|
+ final Profile profile3 = getProfile(3);
|
|
68
|
+ final Profile profile4 = getProfile(4);
|
70
|
69
|
final List<Profile> profiles = Lists.newArrayList(profile3, profile1, profile2);
|
71
|
70
|
Collections.sort(profiles, comparing(Profile::getName));
|
72
|
71
|
mutableProfile1 = new MutableProfile(profile1);
|
73
|
72
|
mutableProfile2 = new MutableProfile(profile2);
|
74
|
73
|
mutableProfile3 = new MutableProfile(profile3);
|
|
74
|
+ mutableProfile4 = new MutableProfile(profile4);
|
75
|
75
|
mutableProfiles = Lists.newArrayList(mutableProfile1, mutableProfile2, mutableProfile3);
|
76
|
76
|
Collections.sort(mutableProfiles, comparing(MutableProfile::getName));
|
77
|
77
|
when(profileManager.getProfiles()).thenReturn(profiles);
|
78
|
78
|
instance = new CoreProfilesDialogModel(profileManager);
|
79
|
79
|
instance.loadModel();
|
|
80
|
+ instance.addListener(listener);
|
80
|
81
|
}
|
81
|
82
|
|
82
|
83
|
private Profile getProfile(final int name) {
|
|
@@ -116,27 +117,34 @@ public class CoreProfilesDialogModelTest {
|
116
|
117
|
public void testAddProfile() {
|
117
|
118
|
when(profileManager.getProfiles()).thenReturn(Lists.newArrayList());
|
118
|
119
|
instance.loadModel();
|
|
120
|
+ verify(listener).profileSelectionChanged(Optional.empty());
|
|
121
|
+ assertTrue("testAddProfile", !instance.getSelectedProfile().isPresent());
|
119
|
122
|
assertFalse("testAddProfile", instance.getProfile("profile4").isPresent());
|
120
|
|
- instance.addProfile("profile4", "realname", "ident", Lists.newArrayList("nickname"));
|
121
|
|
- assertTrue("testAddProfile", instance.getProfile("profile4").isPresent());
|
|
123
|
+ instance.addProfile(mutableProfile1.getName(), mutableProfile1.getRealname(),
|
|
124
|
+ mutableProfile1.getIdent().get(), mutableProfile1.getNicknames());
|
|
125
|
+ assertTrue("testAddProfile", instance.getProfile(mutableProfile1.getName()).isPresent());
|
|
126
|
+ verify(listener).profileAdded(mutableProfile1);
|
|
127
|
+ verify(listener).profileSelectionChanged(Optional.of(mutableProfile1));
|
122
|
128
|
}
|
123
|
129
|
|
124
|
130
|
@Test
|
125
|
131
|
public void testEditProfile() {
|
126
|
132
|
final MutableProfile preEdit = instance.getProfile("profile1").get();
|
127
|
|
- assertEquals("testEditProfile", "profile1", preEdit.getName());
|
128
|
|
- assertEquals("testEditProfile", "realname1", preEdit.getRealname());
|
129
|
|
- assertEquals("testEditProfile", "ident1", preEdit.getIdent().get());
|
130
|
|
- assertEquals("testEditProfile", Lists.newArrayList("nickname11", "nickname12",
|
131
|
|
- "nickname13"), preEdit.getNicknames());
|
132
|
|
- instance.editProfile(preEdit, "profile1", "newRealname", "newIdent",
|
133
|
|
- Lists.newArrayList("nickname"));
|
134
|
|
- final MutableProfile postEdit = instance.getProfile("profile1").get();
|
135
|
|
- assertEquals("testEditProfile", "profile1", postEdit.getName());
|
136
|
|
- assertEquals("testEditProfile", "newRealname", postEdit.getRealname());
|
137
|
|
- assertEquals("testEditProfile", "newIdent", postEdit.getIdent().get());
|
138
|
|
- assertEquals("testEditProfile", Lists.newArrayList("nickname"),
|
139
|
|
- postEdit.getNicknames());
|
|
133
|
+ assertEquals("testEditProfile", "profile1", mutableProfile1.getName());
|
|
134
|
+ assertEquals("testEditProfile", "realname1", mutableProfile1.getRealname());
|
|
135
|
+ assertEquals("testEditProfile", "ident1", mutableProfile1.getIdent().get());
|
|
136
|
+ assertEquals("testEditProfile",
|
|
137
|
+ Lists.newArrayList("nickname11", "nickname12", "nickname13"),
|
|
138
|
+ mutableProfile1.getNicknames());
|
|
139
|
+ instance.editProfile(preEdit, mutableProfile4.getName(), mutableProfile4.getRealname(),
|
|
140
|
+ mutableProfile4.getIdent().get(), mutableProfile4.getNicknames());
|
|
141
|
+ verify(listener).profileEdited(mutableProfile4);
|
|
142
|
+ assertEquals("testEditProfile", "profile4", mutableProfile4.getName());
|
|
143
|
+ assertEquals("testEditProfile", "realname4", mutableProfile4.getRealname());
|
|
144
|
+ assertEquals("testEditProfile", "ident4", mutableProfile4.getIdent().get());
|
|
145
|
+ assertEquals("testEditProfile",
|
|
146
|
+ Lists.newArrayList("nickname41", "nickname42", "nickname43"),
|
|
147
|
+ mutableProfile4.getNicknames());
|
140
|
148
|
}
|
141
|
149
|
|
142
|
150
|
@Test
|
|
@@ -155,6 +163,7 @@ public class CoreProfilesDialogModelTest {
|
155
|
163
|
assertEquals("testRemoveProfile", 3, instance.getProfileList().size());
|
156
|
164
|
assertTrue("testRemoveProfile", instance.getProfile("profile3").isPresent());
|
157
|
165
|
instance.removeProfile("profile3");
|
|
166
|
+ verify(listener).profileRemoved(mutableProfile3);
|
158
|
167
|
assertEquals("testRemoveProfile", 2, instance.getProfileList().size());
|
159
|
168
|
assertFalse("testRemoveProfile", instance.getProfile("profile3").isPresent());
|
160
|
169
|
}
|
|
@@ -163,6 +172,7 @@ public class CoreProfilesDialogModelTest {
|
163
|
172
|
public void testGetSelectedProfile() {
|
164
|
173
|
assertTrue("testGetSelectedProfile", instance.getSelectedProfile().isPresent());
|
165
|
174
|
instance.setSelectedProfile(instance.getProfile("profile2"));
|
|
175
|
+ verify(listener).profileSelectionChanged(Optional.of(mutableProfile2));
|
166
|
176
|
assertEquals("testGetSelectedProfile", "profile2",
|
167
|
177
|
instance.getSelectedProfile().get().getName());
|
168
|
178
|
}
|
|
@@ -170,6 +180,9 @@ public class CoreProfilesDialogModelTest {
|
170
|
180
|
@Test
|
171
|
181
|
public void testGetSelectedProfileDetails() {
|
172
|
182
|
instance.setSelectedProfile(instance.getProfile("profile1"));
|
|
183
|
+ verify(listener, times(0)).profileSelectionChanged(Optional.of(mutableProfile1));
|
|
184
|
+ assertEquals("testGetSelectedProfileDetails", Optional.of(mutableProfile1),
|
|
185
|
+ instance.getSelectedProfile());
|
173
|
186
|
assertEquals("testGetSelectedProfileDetails", "profile1",
|
174
|
187
|
instance.getSelectedProfileName().get());
|
175
|
188
|
assertEquals("testGetSelectedProfileDetails", "ident1",
|
|
@@ -184,17 +197,18 @@ public class CoreProfilesDialogModelTest {
|
184
|
197
|
@Test
|
185
|
198
|
public void testSetSelectedProfileSelectedNickname() {
|
186
|
199
|
instance.setSelectedProfile(instance.getProfile("profile1"));
|
187
|
|
- assertEquals("testSetSelectedProfileSelectedNickname",
|
188
|
|
- Optional.<String>empty(), instance.getSelectedProfileSelectedNickname());
|
|
200
|
+ assertEquals("testSetSelectedProfileSelectedNickname", Optional.<String>empty(),
|
|
201
|
+ instance.getSelectedProfileSelectedNickname());
|
189
|
202
|
instance.setSelectedProfileSelectedNickname(Optional.ofNullable("nickname12"));
|
190
|
|
- assertEquals("testSetSelectedProfileSelectedNickname",
|
191
|
|
- Optional.ofNullable("nickname12"),
|
|
203
|
+ verify(listener).selectedNicknameChanged(Optional.of("nickname12"));
|
|
204
|
+ assertEquals("testSetSelectedProfileSelectedNickname", Optional.ofNullable("nickname12"),
|
192
|
205
|
instance.getSelectedProfileSelectedNickname());
|
193
|
206
|
}
|
194
|
207
|
|
195
|
208
|
@Test
|
196
|
209
|
public void testSetSelectedProfileDetails() {
|
197
|
|
- instance.setSelectedProfile(instance.getProfile("profile1"));
|
|
210
|
+ instance.setSelectedProfile(instance.getProfile("profile2"));
|
|
211
|
+ verify(listener).profileSelectionChanged(Optional.of(mutableProfile2));
|
198
|
212
|
instance.setSelectedProfileName(Optional.ofNullable("testName"));
|
199
|
213
|
instance.setSelectedProfileIdent(Optional.ofNullable("testIdent"));
|
200
|
214
|
instance.setSelectedProfileRealname(Optional.ofNullable("testRealname"));
|
|
@@ -218,6 +232,7 @@ public class CoreProfilesDialogModelTest {
|
218
|
232
|
Lists.newArrayList("nickname11", "nickname12", "nickname13"),
|
219
|
233
|
instance.getSelectedProfileNicknames().get());
|
220
|
234
|
instance.addSelectedProfileNickname("nickname4");
|
|
235
|
+ verify(listener).selectedProfileNicknameAdded("nickname4");
|
221
|
236
|
assertEquals("testAddSelectedProfileNickname",
|
222
|
237
|
Lists.newArrayList("nickname11", "nickname12", "nickname13", "nickname4"),
|
223
|
238
|
instance.getSelectedProfileNicknames().get());
|
|
@@ -230,6 +245,7 @@ public class CoreProfilesDialogModelTest {
|
230
|
245
|
Lists.newArrayList("nickname11", "nickname12", "nickname13"),
|
231
|
246
|
instance.getSelectedProfileNicknames().get());
|
232
|
247
|
instance.removeSelectedProfileNickname("nickname13");
|
|
248
|
+ verify(listener).selectedProfileNicknameRemoved("nickname13");
|
233
|
249
|
assertEquals("testRemoveSelectedProfileNickname",
|
234
|
250
|
Lists.newArrayList("nickname11", "nickname12"),
|
235
|
251
|
instance.getSelectedProfileNicknames().get());
|
|
@@ -243,6 +259,7 @@ public class CoreProfilesDialogModelTest {
|
243
|
259
|
Optional.ofNullable("nickname12"),
|
244
|
260
|
instance.getSelectedProfileSelectedNickname());
|
245
|
261
|
instance.editSelectedProfileNickname("nickname12", "nickname4");
|
|
262
|
+ verify(listener).selectedProfileNicknameEdited("nickname12", "nickname4");
|
246
|
263
|
assertEquals("testAddSelectedProfileNickname",
|
247
|
264
|
Lists.newArrayList("nickname11", "nickname4", "nickname13"),
|
248
|
265
|
instance.getSelectedProfileNicknames().get());
|
|
@@ -250,14 +267,12 @@ public class CoreProfilesDialogModelTest {
|
250
|
267
|
|
251
|
268
|
@Test
|
252
|
269
|
public void testAddListener() {
|
253
|
|
- instance.addListener(listener);
|
254
|
270
|
instance.addProfile("profile4", "realname", "ident", Lists.newArrayList("nickname"));
|
255
|
271
|
verify(listener).profileAdded(any(MutableProfile.class));
|
256
|
272
|
}
|
257
|
273
|
|
258
|
274
|
@Test
|
259
|
275
|
public void testRemoveListener() {
|
260
|
|
- instance.addListener(listener);
|
261
|
276
|
instance.addProfile("profile4", "realname", "ident", Lists.newArrayList("nickname"));
|
262
|
277
|
assertTrue(instance.getProfile("profile4").isPresent());
|
263
|
278
|
final MutableProfile profile4 = instance.getProfile("profile4").get();
|