Selaa lähdekoodia

Start adding IdentityManager tests.

Change-Id: I66c8a3500310d214756f0c19a0fc26883d2da440
Reviewed-on: http://gerrit.dmdirc.com/4037
Automatic-Compile: DMDirc Build Manager
Reviewed-by: Greg Holmes <greg@dmdirc.com>
pull/1/head
Chris Smith 9 vuotta sitten
vanhempi
commit
b107fb8785
1 muutettua tiedostoa jossa 105 lisäystä ja 0 poistoa
  1. 105
    0
      test/com/dmdirc/config/IdentityManagerTest.java

+ 105
- 0
test/com/dmdirc/config/IdentityManagerTest.java Näytä tiedosto

@@ -0,0 +1,105 @@
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;
24
+
25
+import com.dmdirc.DMDircMBassador;
26
+import com.dmdirc.interfaces.config.ConfigProvider;
27
+
28
+import com.google.common.jimfs.Configuration;
29
+import com.google.common.jimfs.Jimfs;
30
+
31
+import java.io.IOException;
32
+import java.nio.file.FileSystem;
33
+import java.nio.file.Files;
34
+import java.nio.file.Path;
35
+
36
+import org.junit.Before;
37
+import org.junit.Test;
38
+import org.junit.runner.RunWith;
39
+import org.mockito.Mock;
40
+import org.mockito.runners.MockitoJUnitRunner;
41
+
42
+import static org.junit.Assert.assertEquals;
43
+import static org.junit.Assert.assertNotNull;
44
+import static org.junit.Assert.assertTrue;
45
+
46
+@RunWith(MockitoJUnitRunner.class)
47
+public class IdentityManagerTest {
48
+
49
+    @Mock private DMDircMBassador eventBus;
50
+
51
+    private FileSystem fs;
52
+    private Path baseDirectory;
53
+    private Path identitiesDirectory;
54
+
55
+    @Before
56
+    public void setUp() throws Exception {
57
+        fs = Jimfs.newFileSystem(Configuration.unix());
58
+        baseDirectory = fs.getPath("config");
59
+        identitiesDirectory = baseDirectory.resolve("identities");
60
+    }
61
+
62
+    @Test
63
+    public void testLoadsVersionIdentity() throws InvalidIdentityFileException {
64
+        final IdentityManager identityManager = new IdentityManager(
65
+                baseDirectory, identitiesDirectory, eventBus);
66
+        identityManager.initialise();
67
+
68
+        final ConfigProvider versionSettings = identityManager.getVersionSettings();
69
+        assertNotNull(versionSettings);
70
+        assertEquals(ConfigTarget.TYPE.GLOBALDEFAULT, versionSettings.getTarget().getType());
71
+        assertEquals("DMDirc version information", versionSettings.getName());
72
+    }
73
+
74
+    @Test
75
+    public void testRenamesExistingDefaultsFile() throws IOException, InvalidIdentityFileException {
76
+        Files.createDirectories(identitiesDirectory);
77
+        Files.createFile(identitiesDirectory.resolve("default"));
78
+
79
+        final IdentityManager identityManager = new IdentityManager(
80
+                baseDirectory, identitiesDirectory, eventBus);
81
+        identityManager.initialise();
82
+
83
+        assertTrue(Files.exists(identitiesDirectory.resolve("default.old")));
84
+        assertTrue(Files.isDirectory(identitiesDirectory.resolve("default")));
85
+    }
86
+
87
+    @Test
88
+    public void testRenamesExistingDefaultsFileWithSuffix() throws IOException,
89
+            InvalidIdentityFileException {
90
+        Files.createDirectories(identitiesDirectory);
91
+        Files.createFile(identitiesDirectory.resolve("default"));
92
+        Files.createFile(identitiesDirectory.resolve("default.old"));
93
+        Files.createFile(identitiesDirectory.resolve("default.old-1"));
94
+
95
+        final IdentityManager identityManager = new IdentityManager(
96
+                baseDirectory, identitiesDirectory, eventBus);
97
+        identityManager.initialise();
98
+
99
+        assertTrue(Files.exists(identitiesDirectory.resolve("default.old")));
100
+        assertTrue(Files.exists(identitiesDirectory.resolve("default.old-1")));
101
+        assertTrue(Files.exists(identitiesDirectory.resolve("default.old-2")));
102
+        assertTrue(Files.isDirectory(identitiesDirectory.resolve("default")));
103
+    }
104
+
105
+}

Loading…
Peruuta
Tallenna