|
@@ -24,7 +24,6 @@
|
24
|
24
|
package com.dmdirc.util;
|
25
|
25
|
|
26
|
26
|
import java.io.File;
|
27
|
|
-import java.io.FileNotFoundException;
|
28
|
27
|
import java.io.IOException;
|
29
|
28
|
import java.util.HashMap;
|
30
|
29
|
import java.util.Map;
|
|
@@ -39,30 +38,22 @@ public class ConfigFileTest {
|
39
|
38
|
|
40
|
39
|
@Before
|
41
|
40
|
public void setUp() throws Exception {
|
42
|
|
- cf = new ConfigFile(getClass().getClassLoader().
|
43
|
|
- getResourceAsStream("com/dmdirc/util/test2.txt"));
|
|
41
|
+ cf = new ConfigFile(getClass().getResourceAsStream("test2.txt"));
|
44
|
42
|
}
|
45
|
43
|
|
46
|
44
|
@Test
|
47
|
|
- public void testRead() {
|
48
|
|
- boolean err = false;
|
49
|
|
-
|
50
|
|
- try {
|
51
|
|
- cf.read();
|
52
|
|
- } catch (FileNotFoundException ex) {
|
53
|
|
- err = true;
|
54
|
|
- } catch (IOException ex) {
|
55
|
|
- err = true;
|
56
|
|
- } catch (InvalidConfigFileException ex) {
|
57
|
|
- err = true;
|
58
|
|
- }
|
59
|
|
-
|
60
|
|
- assertFalse(err);
|
|
45
|
+ public void testRead() throws IOException, InvalidConfigFileException {
|
|
46
|
+ cf.read();
|
|
47
|
+ }
|
|
48
|
+
|
|
49
|
+ @Test(expected=UnsupportedOperationException.class)
|
|
50
|
+ public void testWrite() throws IOException {
|
|
51
|
+ cf.write();
|
61
|
52
|
}
|
62
|
53
|
|
63
|
54
|
@Test
|
64
|
|
- public void testDomains() {
|
65
|
|
- testRead();
|
|
55
|
+ public void testDomains() throws IOException, InvalidConfigFileException {
|
|
56
|
+ cf.read();
|
66
|
57
|
assertTrue(cf.hasDomain("keysections"));
|
67
|
58
|
assertTrue(cf.hasDomain("section alpha"));
|
68
|
59
|
assertTrue(cf.hasDomain("section one point one"));
|
|
@@ -71,16 +62,16 @@ public class ConfigFileTest {
|
71
|
62
|
}
|
72
|
63
|
|
73
|
64
|
@Test
|
74
|
|
- public void testKeyDomains() {
|
75
|
|
- testRead();
|
|
65
|
+ public void testKeyDomains() throws IOException, InvalidConfigFileException {
|
|
66
|
+ cf.read();
|
76
|
67
|
assertTrue(cf.isKeyDomain("section one"));
|
77
|
68
|
assertFalse(cf.isKeyDomain("section one point one"));
|
78
|
69
|
assertFalse(cf.isKeyDomain("section two"));
|
79
|
70
|
}
|
80
|
71
|
|
81
|
72
|
@Test
|
82
|
|
- public void testFlatDomains() {
|
83
|
|
- testRead();
|
|
73
|
+ public void testFlatDomains() throws IOException, InvalidConfigFileException {
|
|
74
|
+ cf.read();
|
84
|
75
|
assertTrue(cf.isFlatDomain("keysections"));
|
85
|
76
|
assertTrue(cf.isFlatDomain("section alpha"));
|
86
|
77
|
assertTrue(cf.isFlatDomain("section one point one"));
|
|
@@ -89,16 +80,16 @@ public class ConfigFileTest {
|
89
|
80
|
}
|
90
|
81
|
|
91
|
82
|
@Test
|
92
|
|
- public void testFlatDomainContents() {
|
93
|
|
- testRead();
|
|
83
|
+ public void testFlatDomainContents() throws IOException, InvalidConfigFileException {
|
|
84
|
+ cf.read();
|
94
|
85
|
assertEquals(2, cf.getFlatDomain("section alpha").size());
|
95
|
86
|
assertEquals("line 1", cf.getFlatDomain("section alpha").get(0));
|
96
|
87
|
assertEquals("line 2", cf.getFlatDomain("section alpha").get(1));
|
97
|
88
|
}
|
98
|
89
|
|
99
|
90
|
@Test
|
100
|
|
- public void testKeyDomainContents() {
|
101
|
|
- testRead();
|
|
91
|
+ public void testKeyDomainContents() throws IOException, InvalidConfigFileException {
|
|
92
|
+ cf.read();
|
102
|
93
|
assertEquals(3, cf.getKeyDomain("section one").size());
|
103
|
94
|
assertEquals("one", cf.getKeyDomain("section one").get("1"));
|
104
|
95
|
assertEquals("two", cf.getKeyDomain("section one").get("2"));
|
|
@@ -245,4 +236,10 @@ public class ConfigFileTest {
|
245
|
236
|
assertTrue(file.isFlatDomain("section one point one"));
|
246
|
237
|
}
|
247
|
238
|
|
|
239
|
+ @Test(expected=InvalidConfigFileException.class)
|
|
240
|
+ public void testInvalidLine() throws IOException, InvalidConfigFileException {
|
|
241
|
+ final ConfigFile file = new ConfigFile(getClass().getResourceAsStream("test1.txt"));
|
|
242
|
+ file.read();
|
|
243
|
+ }
|
|
244
|
+
|
248
|
245
|
}
|