Selaa lähdekoodia

Minor random unit test changes

Change-Id: Ibefb42aba3dc5e5f30335054f26237c6be551b4b
Reviewed-on: http://gerrit.dmdirc.com/1073
Automatic-Compile: DMDirc Local Commits <dmdirc@googlemail.com>
Reviewed-by: Gregory Holmes <greg@dmdirc.com>
tags/0.6.4
Chris Smith 14 vuotta sitten
vanhempi
commit
f71650983e
2 muutettua tiedostoa jossa 43 lisäystä ja 27 poistoa
  1. 24
    27
      test/com/dmdirc/util/ConfigFileTest.java
  2. 19
    0
      test/com/dmdirc/util/RollingListTest.java

+ 24
- 27
test/com/dmdirc/util/ConfigFileTest.java Näytä tiedosto

@@ -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
 }

+ 19
- 0
test/com/dmdirc/util/RollingListTest.java Näytä tiedosto

@@ -80,6 +80,25 @@ public class RollingListTest {
80 80
         rl.seekToStart();
81 81
         assertEquals(0, rl.getPosition());
82 82
     }
83
+
84
+    @Test
85
+    public void testSetPosition() {
86
+        final RollingList<String> rl = new RollingList<String>(3);
87
+
88
+        rl.add("Foo");
89
+        rl.add("Bar");
90
+        rl.add("Baz");
91
+
92
+        assertEquals(0, rl.getPosition());
93
+
94
+        rl.setPosition(1);
95
+        assertEquals(1, rl.getPosition());
96
+        assertEquals("Baz", rl.getNext());
97
+
98
+        rl.setPosition(0);
99
+        assertEquals(0, rl.getPosition());
100
+        assertEquals("Bar", rl.getNext());
101
+    }
83 102
     
84 103
     @Test
85 104
     public void testPrevNext() {

Loading…
Peruuta
Tallenna