Sfoglia il codice sorgente

Mark temp files as deleteOnExit.

Fixes-Issue: CLIENT-453
Change-Id: Ia88e231381da2d1907c78ecccb5f7456e71adb16
Reviewed-on: http://gerrit.dmdirc.com/3195
Reviewed-by: Greg Holmes <greg@dmdirc.com>
Automatic-Compile: DMDirc Build Manager
changes/95/3195/2
Chris Smith 10 anni fa
parent
commit
6780ea88e2

+ 12
- 5
test/com/dmdirc/util/io/ConfigFileTest.java Vedi File

@@ -19,7 +19,6 @@
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
21 21
  */
22
-
23 22
 package com.dmdirc.util.io;
24 23
 
25 24
 import java.io.File;
@@ -30,7 +29,9 @@ import java.util.Map;
30 29
 import org.junit.Before;
31 30
 import org.junit.Test;
32 31
 
33
-import static org.junit.Assert.*;
32
+import static org.junit.Assert.assertEquals;
33
+import static org.junit.Assert.assertFalse;
34
+import static org.junit.Assert.assertTrue;
34 35
 
35 36
 public class ConfigFileTest {
36 37
 
@@ -46,7 +47,7 @@ public class ConfigFileTest {
46 47
         cf.read();
47 48
     }
48 49
 
49
-    @Test(expected=UnsupportedOperationException.class)
50
+    @Test(expected = UnsupportedOperationException.class)
50 51
     public void testWrite() throws IOException {
51 52
         cf.write();
52 53
     }
@@ -99,6 +100,7 @@ public class ConfigFileTest {
99 100
     @Test
100 101
     public void testColons() throws IOException, InvalidConfigFileException {
101 102
         final File file = File.createTempFile("DMDirc.unittest", null);
103
+        file.deleteOnExit();
102 104
         ConfigFile config = new ConfigFile(file);
103 105
         Map<String, String> data = new HashMap<>();
104 106
         data.put("test1", "hello");
@@ -120,6 +122,7 @@ public class ConfigFileTest {
120 122
     @Test
121 123
     public void testEquals() throws IOException, InvalidConfigFileException {
122 124
         final File file = File.createTempFile("DMDirc.unittest", null);
125
+        file.deleteOnExit();
123 126
         ConfigFile config = new ConfigFile(file);
124 127
         Map<String, String> data = new HashMap<>();
125 128
         data.put("test1", "hello");
@@ -141,6 +144,7 @@ public class ConfigFileTest {
141 144
     @Test
142 145
     public void testNewlines() throws IOException, InvalidConfigFileException {
143 146
         final File file = File.createTempFile("DMDirc.unittest", null);
147
+        file.deleteOnExit();
144 148
         ConfigFile config = new ConfigFile(file);
145 149
         Map<String, String> data = new HashMap<>();
146 150
         data.put("test1", "hello");
@@ -164,6 +168,7 @@ public class ConfigFileTest {
164 168
     @Test
165 169
     public void testBackslash() throws IOException, InvalidConfigFileException {
166 170
         final File file = File.createTempFile("DMDirc.unittest", null);
171
+        file.deleteOnExit();
167 172
         ConfigFile config = new ConfigFile(file);
168 173
         Map<String, String> data = new HashMap<>();
169 174
         data.put("test1", "hello\\");
@@ -185,6 +190,7 @@ public class ConfigFileTest {
185 190
     @Test
186 191
     public void testHash() throws IOException, InvalidConfigFileException {
187 192
         final File file = File.createTempFile("DMDirc.unittest", null);
193
+        file.deleteOnExit();
188 194
         ConfigFile config = new ConfigFile(file);
189 195
         Map<String, String> data = new HashMap<>();
190 196
         data.put("test1#", "hello");
@@ -219,6 +225,7 @@ public class ConfigFileTest {
219 225
     @Test
220 226
     public void testDelete() throws IOException {
221 227
         final File file = File.createTempFile("DMDirc_unittest", null);
228
+        file.deleteOnExit();
222 229
         ConfigFile config = new ConfigFile(file);
223 230
         config.write();
224 231
         assertTrue(file.exists());
@@ -236,10 +243,10 @@ public class ConfigFileTest {
236 243
         assertTrue(file.isFlatDomain("section one point one"));
237 244
     }
238 245
 
239
-    @Test(expected=InvalidConfigFileException.class)
246
+    @Test(expected = InvalidConfigFileException.class)
240 247
     public void testInvalidLine() throws IOException, InvalidConfigFileException {
241 248
         final ConfigFile file = new ConfigFile(getClass().getResourceAsStream("test1.txt"));
242 249
         file.read();
243 250
     }
244 251
 
245
-}
252
+}

+ 42
- 32
test/com/dmdirc/util/io/TextFileTest.java Vedi File

@@ -19,7 +19,6 @@
19 19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20 20
  * SOFTWARE.
21 21
  */
22
-
23 22
 package com.dmdirc.util.io;
24 23
 
25 24
 import java.io.File;
@@ -28,71 +27,82 @@ import java.util.Arrays;
28 27
 import java.util.List;
29 28
 
30 29
 import org.junit.Test;
31
-import static org.junit.Assert.*;
30
+
31
+import static org.junit.Assert.assertEquals;
32
+import static org.junit.Assert.assertFalse;
33
+import static org.junit.Assert.assertTrue;
32 34
 
33 35
 public class TextFileTest {
34
-    
35
-    private static File tfile;
36 36
 
37 37
     @Test
38 38
     public void testGetLines() throws IOException {
39
-        final TextFile file =
40
-                new TextFile(getClass().getResourceAsStream("test1.txt"));
39
+        final TextFile file
40
+                = new TextFile(getClass().getResourceAsStream("test1.txt"));
41 41
         final List<String> lines = file.getLines();
42 42
 
43 43
         assertEquals(7, lines.size());
44 44
         assertEquals("Line 1", lines.get(0));
45 45
     }
46
-    
46
+
47 47
     @Test
48 48
     public void testGetLines2() throws IOException {
49
-        final TextFile file =
50
-                new TextFile(getClass().getResourceAsStream("test1.txt"));
49
+        final TextFile file
50
+                = new TextFile(getClass().getResourceAsStream("test1.txt"));
51 51
         final List<String> lines = file.getLines();
52 52
 
53 53
         assertEquals(7, lines.size());
54 54
         assertEquals("Line 1", lines.get(0));
55 55
     }
56
-    
56
+
57 57
     @Test
58 58
     public void testWrite() throws IOException {
59
-        tfile = File.createTempFile("dmdirc_unit_test", null);
60
-        TextFile file = new TextFile(tfile);
61
-        
59
+        File tempFile = File.createTempFile("dmdirc_unit_test", null);
60
+        TextFile file = new TextFile(tempFile);
61
+
62 62
         final List<String> lines = Arrays.asList(new String[]{
63 63
             "hello", "this is a test", "meep"
64 64
         });
65
-        
65
+
66 66
         file.writeLines(lines);
67
-        
68
-        file = new TextFile(tfile);
67
+
68
+        file = new TextFile(tempFile);
69 69
         final List<String> newLines = file.getLines();
70
-        
70
+
71 71
         assertEquals(lines, newLines);
72
+        tempFile.deleteOnExit();
72 73
     }
73
-    
74
-    @Test(expected=UnsupportedOperationException.class)
74
+
75
+    @Test(expected = UnsupportedOperationException.class)
75 76
     public void testIllegalWrite() throws IOException {
76
-        final TextFile file =
77
-                new TextFile(getClass().getResourceAsStream("test1.txt"));
77
+        final TextFile file
78
+                = new TextFile(getClass().getResourceAsStream("test1.txt"));
78 79
         file.writeLines(Arrays.asList(new String[]{
79 80
             "hello", "this is a test", "meep"
80 81
         }));
81 82
     }
82
-    
83
-    @Test(expected=UnsupportedOperationException.class)
83
+
84
+    @Test(expected = UnsupportedOperationException.class)
84 85
     public void testIllegalDelete() throws IOException {
85
-        final TextFile file =
86
-                new TextFile(getClass().getResourceAsStream("test1.txt"));
86
+        final TextFile file
87
+                = new TextFile(getClass().getResourceAsStream("test1.txt"));
87 88
         file.delete();
88 89
     }
89
-    
90
+
90 91
     @Test
91
-    public void testDelete() {
92
-        assertTrue(tfile.exists());
93
-        TextFile file = new TextFile(tfile);
92
+    public void testDelete() throws IOException {
93
+        File tempFile = File.createTempFile("dmdirc_unit_test", "de;ete");
94
+        TextFile file = new TextFile(tempFile);
95
+
96
+        final List<String> lines = Arrays.asList(new String[]{
97
+            "hello", "this is a test", "meep"
98
+        });
99
+
100
+        file.writeLines(lines);
101
+
102
+        assertTrue(tempFile.exists());
103
+        file = new TextFile(tempFile);
94 104
         file.delete();
95
-        assertFalse(tfile.exists());
105
+        assertFalse(tempFile.exists());
96 106
     }
97
-    
98
-}
107
+
108
+}

Loading…
Annulla
Salva