Bläddra i källkod

Merge pull request #594 from csmith/master

Add getPath utility method to JimFsRule.
pull/598/merge
Shane Mc Cormack 9 år sedan
förälder
incheckning
aab5a4fd4c

+ 16
- 20
test/com/dmdirc/commandparser/aliases/ActionAliasMigratorTest.java Visa fil

@@ -38,7 +38,6 @@ import static org.junit.Assert.assertFalse;
38 38
 import static org.junit.Assert.assertTrue;
39 39
 import static org.mockito.Mockito.verify;
40 40
 
41
-@SuppressWarnings("resource")
42 41
 @RunWith(MockitoJUnitRunner.class)
43 42
 public class ActionAliasMigratorTest {
44 43
 
@@ -53,23 +52,20 @@ public class ActionAliasMigratorTest {
53 52
 
54 53
     @Before
55 54
     public void setup() throws IOException {
56
-        Files.createDirectories(jimFsRule.getFileSystem().getPath("test1/aliases"));
57
-        Files.createDirectories(jimFsRule.getFileSystem().getPath("test2/other-stuff/aliases"));
58
-        Files.createDirectories(jimFsRule.getFileSystem().getPath("test3/aliases"));
55
+        Files.createDirectories(jimFsRule.getPath("test1/aliases"));
56
+        Files.createDirectories(jimFsRule.getPath("test2/other-stuff/aliases"));
57
+        Files.createDirectories(jimFsRule.getPath("test3/aliases"));
59 58
 
60 59
         Files.copy(getClass().getResource("op-greater-0").openStream(),
61
-                jimFsRule.getFileSystem().getPath("test1/aliases/op"));
60
+                jimFsRule.getPath("test1/aliases/op"));
62 61
         Files.copy(getClass().getResource("unset-equals-2").openStream(),
63
-                jimFsRule.getFileSystem().getPath("test1/aliases/unset"));
62
+                jimFsRule.getPath("test1/aliases/unset"));
64 63
         Files.copy(getClass().getResource("no-trigger").openStream(),
65
-                jimFsRule.getFileSystem().getPath("test3/aliases/bad"));
66
-
67
-        migrator1 = new ActionAliasMigrator(jimFsRule.getFileSystem().getPath("test1"),
68
-                aliasFactory, aliasManager);
69
-        migrator2 = new ActionAliasMigrator(jimFsRule.getFileSystem().getPath("test2"),
70
-                aliasFactory, aliasManager);
71
-        migrator3 = new ActionAliasMigrator(jimFsRule.getFileSystem().getPath("test3"),
72
-                aliasFactory, aliasManager);
64
+                jimFsRule.getPath("test3/aliases/bad"));
65
+
66
+        migrator1 = new ActionAliasMigrator(jimFsRule.getPath("test1"), aliasFactory, aliasManager);
67
+        migrator2 = new ActionAliasMigrator(jimFsRule.getPath("test2"), aliasFactory, aliasManager);
68
+        migrator3 = new ActionAliasMigrator(jimFsRule.getPath("test3"), aliasFactory, aliasManager);
73 69
     }
74 70
 
75 71
     @Test
@@ -81,16 +77,16 @@ public class ActionAliasMigratorTest {
81 77
     @Test
82 78
     public void testDeletesFilesAfterMigration() {
83 79
         migrator1.migrate();
84
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("test1/aliases/unset")));
85
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("test1/aliases/op")));
86
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("test1/aliases")));
87
-        assertTrue(Files.exists(jimFsRule.getFileSystem().getPath("test1")));
80
+        assertFalse(Files.exists(jimFsRule.getPath("test1/aliases/unset")));
81
+        assertFalse(Files.exists(jimFsRule.getPath("test1/aliases/op")));
82
+        assertFalse(Files.exists(jimFsRule.getPath("test1/aliases")));
83
+        assertTrue(Files.exists(jimFsRule.getPath("test1")));
88 84
     }
89 85
 
90 86
     @Test
91 87
     public void testLeavesOtherFilesDuringMigration() {
92 88
         migrator2.migrate();
93
-        assertTrue(Files.exists(jimFsRule.getFileSystem().getPath("test2/other-stuff/aliases")));
89
+        assertTrue(Files.exists(jimFsRule.getPath("test2/other-stuff/aliases")));
94 90
     }
95 91
 
96 92
     @Test
@@ -103,7 +99,7 @@ public class ActionAliasMigratorTest {
103 99
     @Test
104 100
     public void testBadActionsLeftOnDisk() {
105 101
         migrator3.migrate();
106
-        assertTrue(Files.exists(jimFsRule.getFileSystem().getPath("test3/aliases/bad")));
102
+        assertTrue(Files.exists(jimFsRule.getPath("test3/aliases/bad")));
107 103
     }
108 104
 
109 105
 }

+ 1
- 2
test/com/dmdirc/commandparser/aliases/DefaultAliasInstallerTest.java Visa fil

@@ -37,7 +37,6 @@ import org.mockito.runners.MockitoJUnitRunner;
37 37
 import static org.junit.Assert.assertFalse;
38 38
 import static org.junit.Assert.assertTrue;
39 39
 
40
-@SuppressWarnings("resource")
41 40
 @RunWith(MockitoJUnitRunner.class)
42 41
 public class DefaultAliasInstallerTest {
43 42
 
@@ -49,7 +48,7 @@ public class DefaultAliasInstallerTest {
49 48
 
50 49
     @Before
51 50
     public void setup() {
52
-        path = jimFsRule.getFileSystem().getPath("aliases.yml");
51
+        path = jimFsRule.getPath("aliases.yml");
53 52
         installer = new DefaultAliasInstaller(path);
54 53
     }
55 54
 

+ 5
- 6
test/com/dmdirc/commandparser/auto/YamlAutoCommandStoreTest.java Visa fil

@@ -39,7 +39,6 @@ import static junit.framework.TestCase.assertFalse;
39 39
 import static org.junit.Assert.assertEquals;
40 40
 import static org.junit.Assert.assertTrue;
41 41
 
42
-@SuppressWarnings("resource")
43 42
 public class YamlAutoCommandStoreTest {
44 43
 
45 44
     @Rule public final JimFsRule jimFsRule = new JimFsRule();
@@ -54,7 +53,7 @@ public class YamlAutoCommandStoreTest {
54 53
     @Before
55 54
     public void setup() throws IOException {
56 55
         Files.copy(getClass().getResource("readtest.yml").openStream(),
57
-                jimFsRule.getFileSystem().getPath("readtest.yml"));
56
+                jimFsRule.getPath("readtest.yml"));
58 57
         command = AutoCommand.create(Optional.ofNullable("server"),
59 58
                 Optional.ofNullable("network"),
60 59
                 Optional.ofNullable("profile"),
@@ -77,7 +76,7 @@ public class YamlAutoCommandStoreTest {
77 76
 
78 77
     @Test
79 78
     public void testReadAutoCommands() {
80
-        ycs = new YamlAutoCommandStore(jimFsRule.getFileSystem().getPath("readtest.yml"));
79
+        ycs = new YamlAutoCommandStore(jimFsRule.getPath("readtest.yml"));
81 80
         final Set<AutoCommand> commands = ycs.readAutoCommands();
82 81
         assertTrue("Command 1 not present", commands.contains(command1));
83 82
         assertTrue("Command 2 not present", commands.contains(command2));
@@ -87,13 +86,13 @@ public class YamlAutoCommandStoreTest {
87 86
 
88 87
     @Test
89 88
     public void testWriteAutoCommands() throws IOException {
90
-        ycs = new YamlAutoCommandStore(jimFsRule.getFileSystem().getPath("store.yml"));
89
+        ycs = new YamlAutoCommandStore(jimFsRule.getPath("store.yml"));
91 90
         assertEquals(0, ycs.readAutoCommands().size());
92
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("store.yml")));
91
+        assertFalse(Files.exists(jimFsRule.getPath("store.yml")));
93 92
         ycs.writeAutoCommands(Sets.newHashSet(command));
94 93
         final Set<AutoCommand> commands = ycs.readAutoCommands();
95 94
         assertTrue("Command not present", commands.contains(command));
96
-        assertTrue(Files.exists(jimFsRule.getFileSystem().getPath("store.yml")));
95
+        assertTrue(Files.exists(jimFsRule.getPath("store.yml")));
97 96
     }
98 97
 
99 98
 }

+ 6
- 10
test/com/dmdirc/config/ConfigFileBackedConfigProviderTest.java Visa fil

@@ -50,7 +50,6 @@ import static org.mockito.Matchers.anyString;
50 50
 import static org.mockito.Mockito.never;
51 51
 import static org.mockito.Mockito.verify;
52 52
 
53
-@SuppressWarnings("resource")
54 53
 @RunWith(MockitoJUnitRunner.class)
55 54
 public class ConfigFileBackedConfigProviderTest {
56 55
 
@@ -70,27 +69,26 @@ public class ConfigFileBackedConfigProviderTest {
70 69
     @Before
71 70
     public void setUp() throws Exception {
72 71
         for (String file: FILES) {
73
-            Files.copy(getClass().getResourceAsStream(file),
74
-                    jimFsRule.getFileSystem().getPath(file));
72
+            Files.copy(getClass().getResourceAsStream(file), jimFsRule.getPath(file));
75 73
         }
76 74
     }
77 75
 
78 76
     @Test(expected = InvalidIdentityFileException.class)
79 77
     public void testNoName() throws IOException, InvalidIdentityFileException {
80 78
         new ConfigFileBackedConfigProvider(identityManager,
81
-                jimFsRule.getFileSystem().getPath("no-name"), false);
79
+                jimFsRule.getPath("no-name"), false);
82 80
     }
83 81
 
84 82
     @Test(expected = InvalidIdentityFileException.class)
85 83
     public void testNoTarget() throws IOException, InvalidIdentityFileException {
86 84
         new ConfigFileBackedConfigProvider(identityManager,
87
-                jimFsRule.getFileSystem().getPath("no-target"), false);
85
+                jimFsRule.getPath("no-target"), false);
88 86
     }
89 87
 
90 88
     @Test(expected = InvalidIdentityFileException.class)
91 89
     public void testInvalidConfigFile() throws IOException, InvalidIdentityFileException {
92 90
         new ConfigFileBackedConfigProvider(identityManager,
93
-                jimFsRule.getFileSystem().getPath("invalid-config-file"), false);
91
+                jimFsRule.getPath("invalid-config-file"), false);
94 92
     }
95 93
 
96 94
     @Test
@@ -313,16 +311,14 @@ public class ConfigFileBackedConfigProviderTest {
313 311
 
314 312
     private void copyFileAndReload(final ConfigProvider provider)
315 313
             throws IOException, InvalidConfigFileException {
316
-        Files.copy(jimFsRule.getFileSystem().getPath("simple-ircd-extra"),
317
-                jimFsRule.getFileSystem().getPath("simple-ircd"),
314
+        Files.copy(jimFsRule.getPath("simple-ircd-extra"), jimFsRule.getPath("simple-ircd"),
318 315
                 StandardCopyOption.REPLACE_EXISTING);
319 316
         provider.reload();
320 317
     }
321 318
 
322 319
     private ConfigFileBackedConfigProvider getProvider(final String file)
323 320
             throws IOException, InvalidIdentityFileException {
324
-        return new ConfigFileBackedConfigProvider(identityManager,
325
-                jimFsRule.getFileSystem().getPath(file), false);
321
+        return new ConfigFileBackedConfigProvider(identityManager, jimFsRule.getPath(file), false);
326 322
     }
327 323
 
328 324
 }

+ 1
- 2
test/com/dmdirc/config/IdentityManagerTest.java Visa fil

@@ -54,9 +54,8 @@ public class IdentityManagerTest {
54 54
     private Path identitiesDirectory;
55 55
 
56 56
     @Before
57
-    @SuppressWarnings("resource")
58 57
     public void setUp() throws Exception {
59
-        baseDirectory = jimFsRule.getFileSystem().getPath("config");
58
+        baseDirectory = jimFsRule.getPath("config");
60 59
         identitiesDirectory = baseDirectory.resolve("identities");
61 60
     }
62 61
 

+ 7
- 8
test/com/dmdirc/logger/DiskLoggingErrorManagerTest.java Visa fil

@@ -45,7 +45,6 @@ import static org.junit.Assert.assertTrue;
45 45
 import static org.mockito.Mockito.verify;
46 46
 import static org.mockito.Mockito.when;
47 47
 
48
-@SuppressWarnings("resource")
49 48
 @RunWith(MockitoJUnitRunner.class)
50 49
 public class DiskLoggingErrorManagerTest {
51 50
 
@@ -67,16 +66,16 @@ public class DiskLoggingErrorManagerTest {
67 66
         when(programError.getThrowableAsString()).thenReturn(Optional.of("test"));
68 67
         when(programError.getLevel()).thenReturn(ErrorLevel.MEDIUM);
69 68
         when(config.getBinder()).thenReturn(configBinder);
70
-        instance = new DiskLoggingErrorManager(jimFsRule.getFileSystem().getPath("/errors"),
69
+        instance = new DiskLoggingErrorManager(jimFsRule.getPath("/errors"),
71 70
                 eventBus);
72 71
     }
73 72
 
74 73
     @Test
75 74
     public void testInitialise() throws Exception {
76
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors")));
75
+        assertFalse(Files.exists(jimFsRule.getPath("/errors")));
77 76
         instance.initialise(config);
78 77
         verify(configBinder).bind(instance, DiskLoggingErrorManager.class);
79
-        assertTrue(Files.exists(jimFsRule.getFileSystem().getPath("/errors")));
78
+        assertTrue(Files.exists(jimFsRule.getPath("/errors")));
80 79
         assertFalse(instance.isDirectoryError());
81 80
     }
82 81
 
@@ -90,9 +89,9 @@ public class DiskLoggingErrorManagerTest {
90 89
         instance.initialise(config);
91 90
         instance.handleLoggingSetting(true);
92 91
         final String logName = error.getTimestamp() + "-" + error.getError().getLevel() + ".log";;
93
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors", logName)));
92
+        assertFalse(Files.exists(jimFsRule.getPath("/errors", logName)));
94 93
         instance.handleErrorEvent(error);
95
-        final Path errorPath = jimFsRule.getFileSystem().getPath("/errors", logName);
94
+        final Path errorPath = jimFsRule.getPath("/errors", logName);
96 95
         assertTrue(Files.exists(errorPath));
97 96
         assertTrue(Files.readAllLines(errorPath).contains("Level: Medium"));
98 97
     }
@@ -102,9 +101,9 @@ public class DiskLoggingErrorManagerTest {
102 101
         instance.initialise(config);
103 102
         instance.handleLoggingSetting(false);
104 103
         final String logName = error.getTimestamp() + "-" + error.getError().getLevel() + ".log";;
105
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors", logName)));
104
+        assertFalse(Files.exists(jimFsRule.getPath("/errors", logName)));
106 105
         instance.handleErrorEvent(error);
107
-        assertFalse(Files.exists(jimFsRule.getFileSystem().getPath("/errors", logName)));
106
+        assertFalse(Files.exists(jimFsRule.getPath("/errors", logName)));
108 107
     }
109 108
 
110 109
     @Test

+ 17
- 3
test/com/dmdirc/tests/JimFsRule.java Visa fil

@@ -26,8 +26,7 @@ import com.google.common.jimfs.Configuration;
26 26
 import com.google.common.jimfs.Jimfs;
27 27
 
28 28
 import java.nio.file.FileSystem;
29
-
30
-import javax.annotation.WillCloseWhenClosed;
29
+import java.nio.file.Path;
31 30
 
32 31
 import org.junit.rules.TestRule;
33 32
 import org.junit.runner.Description;
@@ -55,9 +54,24 @@ public class JimFsRule implements TestRule {
55 54
         };
56 55
     }
57 56
 
58
-    @WillCloseWhenClosed
57
+    /**
58
+     * Gets the file system for use in the test.
59
+     *
60
+     * @return The JimFS filesystem.
61
+     */
59 62
     public FileSystem getFileSystem() {
60 63
         return fileSystem;
61 64
     }
62 65
 
66
+    /**
67
+     * Utility method to get a path from the file system.
68
+     *
69
+     * @param first The first component of the path
70
+     * @param more Any additional path components
71
+     * @return A corresponding {@link Path} object from the JimFS file system.
72
+     */
73
+    public Path getPath(final String first, final String ... more) {
74
+        return fileSystem.getPath(first, more);
75
+    }
76
+
63 77
 }

+ 1
- 3
test/com/dmdirc/util/URLBuilderTest.java Visa fil

@@ -59,15 +59,13 @@ public class URLBuilderTest {
59 59
     @Mock private DMDircMBassador eventBus;
60 60
 
61 61
     @Before
62
-    @SuppressWarnings("resource")
63 62
     public void setup() throws MalformedURLException {
64 63
         when(pluginManagerProvider.get()).thenReturn(pluginManager);
65 64
         when(themeManagerProvider.get()).thenReturn(themeManager);
66 65
         when(pluginManager.getPluginInfoByName(Matchers.anyString())).thenReturn(pluginInfo);
67 66
         when(themeManager.getDirectory()).thenReturn("/themes/");
68 67
         when(pluginInfo.getMetaData()).thenReturn(pluginMetaData);
69
-        when(pluginMetaData.getPluginPath()).thenReturn(
70
-                jimFsRule.getFileSystem().getPath("file://testPlugin"));
68
+        when(pluginMetaData.getPluginPath()).thenReturn(jimFsRule.getPath("file://testPlugin"));
71 69
     }
72 70
 
73 71
     @Test

Laddar…
Avbryt
Spara