|
@@ -22,50 +22,65 @@
|
22
|
22
|
|
23
|
23
|
package com.dmdirc.util;
|
24
|
24
|
|
|
25
|
+import java.io.File;
|
25
|
26
|
import java.io.FileNotFoundException;
|
26
|
27
|
import java.io.IOException;
|
27
|
28
|
import java.net.URISyntaxException;
|
|
29
|
+import java.util.Arrays;
|
28
|
30
|
import java.util.List;
|
29
|
31
|
|
30
|
32
|
import org.junit.Test;
|
31
|
33
|
import static org.junit.Assert.*;
|
32
|
34
|
|
33
|
35
|
public class TextFileTest extends junit.framework.TestCase {
|
|
36
|
+
|
|
37
|
+ private static File tfile;
|
|
38
|
+
|
|
39
|
+ @Test
|
|
40
|
+ public void testGetLines() throws IOException {
|
|
41
|
+ final TextFile file =
|
|
42
|
+ new TextFile(getClass().getClassLoader().
|
|
43
|
+ getResource("com/dmdirc/util/test1.txt").openStream());
|
|
44
|
+ final List<String> lines = file.getLines();
|
|
45
|
+
|
|
46
|
+ assertEquals(7, lines.size());
|
|
47
|
+ assertEquals("Line 1", lines.get(0));
|
|
48
|
+ }
|
|
49
|
+
|
|
50
|
+ @Test
|
|
51
|
+ public void testGetLines2() throws IOException {
|
|
52
|
+ final TextFile file =
|
|
53
|
+ new TextFile(getClass().getClassLoader().
|
|
54
|
+ getResource("com/dmdirc/util/test1.txt").openStream());
|
|
55
|
+ final List<String> lines = file.getLines();
|
34
|
56
|
|
|
57
|
+ assertEquals(7, lines.size());
|
|
58
|
+ assertEquals("Line 1", lines.get(0));
|
|
59
|
+ }
|
|
60
|
+
|
35
|
61
|
@Test
|
36
|
|
- public void testGetLines() {
|
37
|
|
- try {
|
38
|
|
- final TextFile file =
|
39
|
|
- new TextFile(getClass().getClassLoader().
|
40
|
|
- getResource("com/dmdirc/util/test1.txt").toURI());
|
41
|
|
- final List<String> lines = file.getLines();
|
42
|
|
-
|
43
|
|
- assertEquals(7, lines.size());
|
44
|
|
- assertEquals("Line 1", lines.get(0));
|
45
|
|
- } catch (FileNotFoundException ex) {
|
46
|
|
- assertFalse(true);
|
47
|
|
- } catch (IOException ex) {
|
48
|
|
- assertFalse(true);
|
49
|
|
- } catch (URISyntaxException ex) {
|
50
|
|
- // Do nothing
|
51
|
|
- }
|
|
62
|
+ public void testWrite() throws IOException {
|
|
63
|
+ tfile = File.createTempFile("dmdirc_unit_test", null);
|
|
64
|
+ TextFile file = new TextFile(tfile);
|
|
65
|
+
|
|
66
|
+ final List<String> lines = Arrays.asList(new String[]{
|
|
67
|
+ "hello", "this is a test", "meep"
|
|
68
|
+ });
|
|
69
|
+
|
|
70
|
+ file.writeLines(lines);
|
|
71
|
+
|
|
72
|
+ file = new TextFile(tfile);
|
|
73
|
+ final List<String> newLines = file.getLines();
|
|
74
|
+
|
|
75
|
+ assertEquals(lines, newLines);
|
52
|
76
|
}
|
53
|
77
|
|
54
|
78
|
@Test
|
55
|
|
- public void testGetLines2() {
|
56
|
|
- try {
|
57
|
|
- final TextFile file =
|
58
|
|
- new TextFile(getClass().getClassLoader().
|
59
|
|
- getResource("com/dmdirc/util/test1.txt").openStream());
|
60
|
|
- final List<String> lines = file.getLines();
|
61
|
|
-
|
62
|
|
- assertEquals(7, lines.size());
|
63
|
|
- assertEquals("Line 1", lines.get(0));
|
64
|
|
- } catch (FileNotFoundException ex) {
|
65
|
|
- assertFalse(true);
|
66
|
|
- } catch (IOException ex) {
|
67
|
|
- assertFalse(true);
|
68
|
|
- }
|
69
|
|
- }
|
|
79
|
+ public void testDelete() {
|
|
80
|
+ assertTrue(tfile.exists());
|
|
81
|
+ TextFile file = new TextFile(tfile);
|
|
82
|
+ file.delete();
|
|
83
|
+ assertFalse(tfile.exists());
|
|
84
|
+ }
|
70
|
85
|
|
71
|
86
|
}
|