|
@@ -0,0 +1,118 @@
|
|
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 THE
|
|
20
|
+ * SOFTWARE.
|
|
21
|
+ */
|
|
22
|
+
|
|
23
|
+package com.dmdirc.config.profiles;
|
|
24
|
+
|
|
25
|
+import com.dmdirc.config.IdentityManager;
|
|
26
|
+import com.dmdirc.interfaces.config.ConfigProvider;
|
|
27
|
+
|
|
28
|
+import com.google.common.collect.Lists;
|
|
29
|
+
|
|
30
|
+import java.util.Optional;
|
|
31
|
+
|
|
32
|
+import org.junit.Before;
|
|
33
|
+import org.junit.Test;
|
|
34
|
+import org.junit.runner.RunWith;
|
|
35
|
+import org.mockito.Mock;
|
|
36
|
+import org.mockito.runners.MockitoJUnitRunner;
|
|
37
|
+
|
|
38
|
+import static junit.framework.TestCase.assertFalse;
|
|
39
|
+import static junit.framework.TestCase.assertTrue;
|
|
40
|
+import static org.mockito.Mockito.verify;
|
|
41
|
+import static org.mockito.Mockito.when;
|
|
42
|
+
|
|
43
|
+@RunWith(MockitoJUnitRunner.class)
|
|
44
|
+public class IdentitiesProfileMigratorTest {
|
|
45
|
+
|
|
46
|
+ @Mock private IdentityManager identityManager;
|
|
47
|
+ @Mock private ProfileManager profileManager;
|
|
48
|
+ @Mock private ConfigProvider configProvider1;
|
|
49
|
+ @Mock private ConfigProvider configProvider2;
|
|
50
|
+ @Mock private ConfigProvider configProvider3;
|
|
51
|
+
|
|
52
|
+ private IdentitiesProfileMigrator instance;
|
|
53
|
+
|
|
54
|
+ @Before
|
|
55
|
+ public void setup() {
|
|
56
|
+ instance = new IdentitiesProfileMigrator(identityManager, profileManager);
|
|
57
|
+ when(configProvider1.getName()).thenReturn("name1");
|
|
58
|
+ when(configProvider1.getOption("profile", "realname")).thenReturn("realname1");
|
|
59
|
+ when(configProvider1.hasOptionString("profile", "ident1")).thenReturn(false);
|
|
60
|
+ when(configProvider1.getOptionList("profile", "nicknames")).thenReturn(
|
|
61
|
+ Lists.newArrayList("nickname1")
|
|
62
|
+ );
|
|
63
|
+ when(configProvider2.getName()).thenReturn("name2");
|
|
64
|
+ when(configProvider2.getOption("profile", "realname")).thenReturn("realname2");
|
|
65
|
+ when(configProvider2.hasOptionString("profile", "ident")).thenReturn(true);
|
|
66
|
+ when(configProvider2.getOption("profile", "ident")).thenReturn("ident2");
|
|
67
|
+ when(configProvider2.getOptionList("profile", "nicknames")).thenReturn(
|
|
68
|
+ Lists.newArrayList("nickname2")
|
|
69
|
+ );
|
|
70
|
+ when(configProvider3.getName()).thenReturn("name3");
|
|
71
|
+ when(configProvider3.getOption("profile", "realname")).thenReturn("realname3");
|
|
72
|
+ when(configProvider3.hasOptionString("profile", "ident")).thenReturn(true);
|
|
73
|
+ when(configProvider3.getOption("profile", "ident")).thenReturn("ident3");
|
|
74
|
+ when(configProvider3.getOptionList("profile", "nicknames")).thenReturn(
|
|
75
|
+ Lists.newArrayList("nickname31", "nickname32", "nickname33")
|
|
76
|
+ );
|
|
77
|
+ }
|
|
78
|
+
|
|
79
|
+ @Test
|
|
80
|
+ public void testNeedsMigration_NoProfiles() {
|
|
81
|
+ when(identityManager.getProvidersByType("profile")).thenReturn(Lists.newArrayList());
|
|
82
|
+ assertFalse(instance.needsMigration());
|
|
83
|
+ }
|
|
84
|
+
|
|
85
|
+ @Test
|
|
86
|
+ public void testNeedsMigration_Profiles() {
|
|
87
|
+ when(identityManager.getProvidersByType("profile")).thenReturn(
|
|
88
|
+ Lists.newArrayList(configProvider1));
|
|
89
|
+ assertTrue(instance.needsMigration());
|
|
90
|
+ }
|
|
91
|
+
|
|
92
|
+ @Test
|
|
93
|
+ public void testMigrate_NoIdent() {
|
|
94
|
+ when(identityManager.getProvidersByType("profile")).thenReturn(
|
|
95
|
+ Lists.newArrayList(configProvider1));
|
|
96
|
+ instance.migrate();
|
|
97
|
+ verify(profileManager).addProfile(new Profile("name1", "realname1", Optional.empty(),
|
|
98
|
+ Lists.newArrayList("nickname1")));
|
|
99
|
+ }
|
|
100
|
+
|
|
101
|
+ @Test
|
|
102
|
+ public void testMigrate_Ident() {
|
|
103
|
+ when(identityManager.getProvidersByType("profile")).thenReturn(
|
|
104
|
+ Lists.newArrayList(configProvider2));
|
|
105
|
+ instance.migrate();
|
|
106
|
+ verify(profileManager).addProfile(new Profile("name2", "realname2", Optional.of("ident2"),
|
|
107
|
+ Lists.newArrayList("nickname2")));
|
|
108
|
+ }
|
|
109
|
+
|
|
110
|
+ @Test
|
|
111
|
+ public void testMigrate_MultipleNicknames() {
|
|
112
|
+ when(identityManager.getProvidersByType("profile")).thenReturn(
|
|
113
|
+ Lists.newArrayList(configProvider3));
|
|
114
|
+ instance.migrate();
|
|
115
|
+ verify(profileManager).addProfile(new Profile("name3", "realname3", Optional.of("ident3"),
|
|
116
|
+ Lists.newArrayList("nickname31", "nickname32", "nickname33")));
|
|
117
|
+ }
|
|
118
|
+}
|