Browse Source

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 years ago
parent
commit
6780ea88e2

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

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

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

19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
19
  * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
  * SOFTWARE.
20
  * SOFTWARE.
21
  */
21
  */
22
-
23
 package com.dmdirc.util.io;
22
 package com.dmdirc.util.io;
24
 
23
 
25
 import java.io.File;
24
 import java.io.File;
28
 import java.util.List;
27
 import java.util.List;
29
 
28
 
30
 import org.junit.Test;
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
 public class TextFileTest {
35
 public class TextFileTest {
34
-    
35
-    private static File tfile;
36
 
36
 
37
     @Test
37
     @Test
38
     public void testGetLines() throws IOException {
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
         final List<String> lines = file.getLines();
41
         final List<String> lines = file.getLines();
42
 
42
 
43
         assertEquals(7, lines.size());
43
         assertEquals(7, lines.size());
44
         assertEquals("Line 1", lines.get(0));
44
         assertEquals("Line 1", lines.get(0));
45
     }
45
     }
46
-    
46
+
47
     @Test
47
     @Test
48
     public void testGetLines2() throws IOException {
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
         final List<String> lines = file.getLines();
51
         final List<String> lines = file.getLines();
52
 
52
 
53
         assertEquals(7, lines.size());
53
         assertEquals(7, lines.size());
54
         assertEquals("Line 1", lines.get(0));
54
         assertEquals("Line 1", lines.get(0));
55
     }
55
     }
56
-    
56
+
57
     @Test
57
     @Test
58
     public void testWrite() throws IOException {
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
         final List<String> lines = Arrays.asList(new String[]{
62
         final List<String> lines = Arrays.asList(new String[]{
63
             "hello", "this is a test", "meep"
63
             "hello", "this is a test", "meep"
64
         });
64
         });
65
-        
65
+
66
         file.writeLines(lines);
66
         file.writeLines(lines);
67
-        
68
-        file = new TextFile(tfile);
67
+
68
+        file = new TextFile(tempFile);
69
         final List<String> newLines = file.getLines();
69
         final List<String> newLines = file.getLines();
70
-        
70
+
71
         assertEquals(lines, newLines);
71
         assertEquals(lines, newLines);
72
+        tempFile.deleteOnExit();
72
     }
73
     }
73
-    
74
-    @Test(expected=UnsupportedOperationException.class)
74
+
75
+    @Test(expected = UnsupportedOperationException.class)
75
     public void testIllegalWrite() throws IOException {
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
         file.writeLines(Arrays.asList(new String[]{
79
         file.writeLines(Arrays.asList(new String[]{
79
             "hello", "this is a test", "meep"
80
             "hello", "this is a test", "meep"
80
         }));
81
         }));
81
     }
82
     }
82
-    
83
-    @Test(expected=UnsupportedOperationException.class)
83
+
84
+    @Test(expected = UnsupportedOperationException.class)
84
     public void testIllegalDelete() throws IOException {
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
         file.delete();
88
         file.delete();
88
     }
89
     }
89
-    
90
+
90
     @Test
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
         file.delete();
104
         file.delete();
95
-        assertFalse(tfile.exists());
105
+        assertFalse(tempFile.exists());
96
     }
106
     }
97
-    
98
-}
107
+
108
+}

Loading…
Cancel
Save