Browse Source

Unit tests++

git-svn-id: http://svn.dmdirc.com/trunk@3249 00569f92-eb28-0410-84fd-f71c24880f
tags/0.6
Chris Smith 16 years ago
parent
commit
a2a6d2bf5a

+ 37
- 0
test/com/dmdirc/actions/metatypes/ChannelEventsTest.java View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.actions.metatypes;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class ChannelEventsTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testArity() {
31
+        for (ChannelEvents event : ChannelEvents.values()) {
32
+            assertEquals(event.getArity(), event.getArgNames().length);
33
+            assertEquals(event.getArity(), event.getArgTypes().length);
34
+        }
35
+    }
36
+
37
+}

+ 37
- 0
test/com/dmdirc/actions/metatypes/ClientEventsTest.java View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.actions.metatypes;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class ClientEventsTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testArity() {
31
+        for (ClientEvents event : ClientEvents.values()) {
32
+            assertEquals(event.getArity(), event.getArgNames().length);
33
+            assertEquals(event.getArity(), event.getArgTypes().length);
34
+        }
35
+    }
36
+
37
+}

+ 37
- 0
test/com/dmdirc/actions/metatypes/PluginEventsTest.java View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.actions.metatypes;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class PluginEventsTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testArity() {
31
+        for (PluginEvents event : PluginEvents.values()) {
32
+            assertEquals(event.getArity(), event.getArgNames().length);
33
+            assertEquals(event.getArity(), event.getArgTypes().length);
34
+        }
35
+    }
36
+
37
+}

+ 37
- 0
test/com/dmdirc/actions/metatypes/QueryEventsTest.java View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.actions.metatypes;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class QueryEventsTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testArity() {
31
+        for (QueryEvents event : QueryEvents.values()) {
32
+            assertEquals(event.getArity(), event.getArgNames().length);
33
+            assertEquals(event.getArity(), event.getArgTypes().length);
34
+        }
35
+    }
36
+
37
+}

+ 37
- 0
test/com/dmdirc/actions/metatypes/ServerEventsTest.java View File

@@ -0,0 +1,37 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.actions.metatypes;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class ServerEventsTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testArity() {
31
+        for (ServerEvents event : ServerEvents.values()) {
32
+            assertEquals(event.getArity(), event.getArgNames().length);
33
+            assertEquals(event.getArity(), event.getArgTypes().length);
34
+        }
35
+    }
36
+
37
+}

+ 39
- 0
test/com/dmdirc/config/prefs/validator/NotEmptyValidatorTest.java View File

@@ -0,0 +1,39 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.config.prefs.validator;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class NotEmptyValidatorTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testValidate() {
31
+        final NotEmptyValidator nev = new NotEmptyValidator();
32
+        
33
+        assertTrue(nev.validate("").isFailure());
34
+        assertTrue(nev.validate("").getFailureReason().indexOf("empty") > -1);
35
+        assertFalse(nev.validate("moo").isFailure());
36
+        assertFalse(nev.validate(" ").isFailure());
37
+    }
38
+
39
+}

+ 47
- 0
test/com/dmdirc/config/prefs/validator/NumericalValidatorTest.java View File

@@ -0,0 +1,47 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.config.prefs.validator;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class NumericalValidatorTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testGetMax() {
31
+        assertEquals(10, new NumericalValidator(1, 10).getMax());
32
+    }
33
+
34
+    @Test
35
+    public void testGetMin() {
36
+        assertEquals(1, new NumericalValidator(1, 10).getMin());
37
+    }
38
+
39
+    @Test
40
+    public void testNAN() {
41
+        final ValidationResponse vr = new NumericalValidator(3, 5).validate("foo");
42
+        
43
+        assertTrue(vr.isFailure());
44
+        assertTrue(vr.getFailureReason().indexOf("number") > -1);
45
+    }
46
+
47
+}

+ 67
- 0
test/com/dmdirc/config/prefs/validator/StringLengthValidatorTest.java View File

@@ -0,0 +1,67 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.config.prefs.validator;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class StringLengthValidatorTest extends junit.framework.TestCase {
28
+
29
+    @Test
30
+    public void testUnlimited() {
31
+        final StringLengthValidator slv = new StringLengthValidator(-1, 10);
32
+        
33
+        assertFalse(slv.validate("123").isFailure());
34
+        assertFalse(slv.validate("").isFailure());
35
+        assertFalse(slv.validate("123456789").isFailure());
36
+        
37
+        final StringLengthValidator slv2 = new StringLengthValidator(0, -1);
38
+        
39
+        assertFalse(slv2.validate("123456789").isFailure());
40
+        assertFalse(slv2.validate("1").isFailure());
41
+    }
42
+    
43
+    @Test
44
+    public void testMinimum() {
45
+        final StringLengthValidator slv = new StringLengthValidator(5, 100);
46
+        
47
+        assertTrue(slv.validate("").isFailure());
48
+        assertTrue(slv.validate("123").isFailure());
49
+        assertTrue(slv.validate("1234").isFailure());
50
+        assertTrue(slv.validate("1234").getFailureReason().indexOf("at least 5") > -1);
51
+        assertFalse(slv.validate("12345").isFailure());
52
+        assertFalse(slv.validate("12345789").isFailure());
53
+    }
54
+    
55
+    @Test
56
+    public void testMaximum() {
57
+        final StringLengthValidator slv = new StringLengthValidator(0, 3);
58
+        
59
+        assertFalse(slv.validate("").isFailure());
60
+        assertFalse(slv.validate("12").isFailure());
61
+        assertFalse(slv.validate("123").isFailure());
62
+        assertTrue(slv.validate("1234").isFailure());
63
+        assertTrue(slv.validate("1234").getFailureReason().indexOf("at most 3") > -1);
64
+        assertTrue(slv.validate("12345").isFailure());
65
+    }    
66
+
67
+}

+ 93
- 0
test/com/dmdirc/logger/ErrorLevelTest.java View File

@@ -0,0 +1,93 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.logger;
23
+
24
+import javax.swing.Icon;
25
+import org.junit.Test;
26
+import static org.junit.Assert.*;
27
+
28
+public class ErrorLevelTest extends junit.framework.TestCase {
29
+
30
+    @Test
31
+    public void testToString() {
32
+        assertTrue("Low".equalsIgnoreCase(ErrorLevel.LOW.toString()));
33
+        assertTrue("Medium".equalsIgnoreCase(ErrorLevel.MEDIUM.toString()));
34
+        assertTrue("High".equalsIgnoreCase(ErrorLevel.HIGH.toString()));
35
+        assertTrue("Fatal".equalsIgnoreCase(ErrorLevel.FATAL.toString()));
36
+        assertTrue("Unknown".equalsIgnoreCase(ErrorLevel.UNKNOWN.toString()));
37
+    }
38
+
39
+    @Test
40
+    public void testGetIcon() {
41
+        assertTrue(ErrorLevel.LOW.getIcon() instanceof Icon);
42
+        assertTrue(ErrorLevel.MEDIUM.getIcon() instanceof Icon);
43
+        assertTrue(ErrorLevel.HIGH.getIcon() instanceof Icon);
44
+        assertTrue(ErrorLevel.FATAL.getIcon() instanceof Icon);
45
+        assertTrue(ErrorLevel.UNKNOWN.getIcon() instanceof Icon);
46
+    }
47
+
48
+    @Test
49
+    public void testMoreImportantLow() {
50
+        assertTrue(ErrorLevel.LOW.moreImportant(ErrorLevel.MEDIUM));
51
+        assertTrue(ErrorLevel.LOW.moreImportant(ErrorLevel.HIGH));
52
+        assertTrue(ErrorLevel.LOW.moreImportant(ErrorLevel.FATAL));
53
+        assertFalse(ErrorLevel.LOW.moreImportant(ErrorLevel.LOW));
54
+        assertFalse(ErrorLevel.LOW.moreImportant(ErrorLevel.UNKNOWN));
55
+    }
56
+
57
+    @Test
58
+    public void testMoreImportantMedium() {
59
+        assertFalse(ErrorLevel.MEDIUM.moreImportant(ErrorLevel.MEDIUM));
60
+        assertTrue(ErrorLevel.MEDIUM.moreImportant(ErrorLevel.HIGH));
61
+        assertTrue(ErrorLevel.MEDIUM.moreImportant(ErrorLevel.FATAL));
62
+        assertFalse(ErrorLevel.MEDIUM.moreImportant(ErrorLevel.LOW));
63
+        assertFalse(ErrorLevel.MEDIUM.moreImportant(ErrorLevel.UNKNOWN));
64
+    }
65
+
66
+    @Test
67
+    public void testMoreImportantHigh() {
68
+        assertFalse(ErrorLevel.HIGH.moreImportant(ErrorLevel.MEDIUM));
69
+        assertFalse(ErrorLevel.HIGH.moreImportant(ErrorLevel.HIGH));
70
+        assertTrue(ErrorLevel.HIGH.moreImportant(ErrorLevel.FATAL));
71
+        assertFalse(ErrorLevel.HIGH.moreImportant(ErrorLevel.LOW));
72
+        assertFalse(ErrorLevel.HIGH.moreImportant(ErrorLevel.UNKNOWN));
73
+    }
74
+
75
+    @Test
76
+    public void testMoreImportantFatal() {
77
+        assertFalse(ErrorLevel.FATAL.moreImportant(ErrorLevel.MEDIUM));
78
+        assertFalse(ErrorLevel.FATAL.moreImportant(ErrorLevel.HIGH));
79
+        assertFalse(ErrorLevel.FATAL.moreImportant(ErrorLevel.FATAL));
80
+        assertFalse(ErrorLevel.FATAL.moreImportant(ErrorLevel.LOW));
81
+        assertFalse(ErrorLevel.FATAL.moreImportant(ErrorLevel.UNKNOWN));
82
+    }
83
+    
84
+    @Test
85
+    public void testMoreImportantUnknown() {
86
+        assertTrue(ErrorLevel.UNKNOWN.moreImportant(ErrorLevel.MEDIUM));
87
+        assertTrue(ErrorLevel.UNKNOWN.moreImportant(ErrorLevel.HIGH));
88
+        assertTrue(ErrorLevel.UNKNOWN.moreImportant(ErrorLevel.FATAL));
89
+        assertTrue(ErrorLevel.UNKNOWN.moreImportant(ErrorLevel.LOW));
90
+        assertFalse(ErrorLevel.UNKNOWN.moreImportant(ErrorLevel.UNKNOWN));
91
+    }    
92
+
93
+}

+ 123
- 0
test/com/dmdirc/parser/ParserErrorTest.java View File

@@ -0,0 +1,123 @@
1
+/*
2
+ * Copyright (c) 2006-2008 Chris Smith, Shane Mc Cormack, Gregory Holmes
3
+ *
4
+ * Permission is hereby granted, free of charge, to any person obtaining a copy
5
+ * of this software and associated documentation files (the "Software"), to deal
6
+ * in the Software without restriction, including without limitation the rights
7
+ * to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8
+ * copies of the Software, and to permit persons to whom the Software is
9
+ * furnished to do so, subject to the following conditions:
10
+ *
11
+ * The above copyright notice and this permission notice shall be included in
12
+ * all copies or substantial portions of the Software.
13
+ *
14
+ * THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15
+ * IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16
+ * FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17
+ * AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18
+ * LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19
+ * OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20
+ * SOFTWARE.
21
+ */
22
+package com.dmdirc.parser;
23
+
24
+import org.junit.Test;
25
+import static org.junit.Assert.*;
26
+
27
+public class ParserErrorTest extends junit.framework.TestCase {
28
+
29
+    private final ParserError fatal = new ParserError(ParserError.ERROR_FATAL, "moo");
30
+    private final ParserError error = new ParserError(ParserError.ERROR_ERROR, "moo", "last line");
31
+    private final ParserError except = new ParserError(ParserError.ERROR_EXCEPTION, "moo", null);
32
+    private final ParserError warning = new ParserError(ParserError.ERROR_WARNING, "moo", "");
33
+
34
+    @Test
35
+    public void testIsFatal() {
36
+        assertTrue(fatal.isFatal());
37
+        assertFalse(error.isFatal());
38
+        assertFalse(except.isFatal());
39
+        assertFalse(warning.isFatal());
40
+    }
41
+
42
+    @Test
43
+    public void testIsError() {
44
+        assertTrue(error.isError());
45
+        assertFalse(fatal.isError());
46
+        assertFalse(except.isError());
47
+        assertFalse(warning.isError());
48
+    }
49
+
50
+    @Test
51
+    public void testIsWarning() {
52
+        assertFalse(error.isWarning());
53
+        assertFalse(fatal.isWarning());
54
+        assertFalse(except.isWarning());
55
+        assertTrue(warning.isWarning());
56
+    }
57
+
58
+    @Test
59
+    public void testIsException() {
60
+        assertFalse(error.isException());
61
+        assertFalse(fatal.isException());
62
+        assertTrue(except.isException());
63
+        assertFalse(warning.isException());        
64
+    }
65
+
66
+    @Test
67
+    public void testHasLastLine() {
68
+        assertTrue(error.hasLastLine());
69
+        assertFalse(fatal.hasLastLine());
70
+        assertFalse(except.hasLastLine());
71
+        assertFalse(warning.hasLastLine());
72
+    }
73
+    
74
+    @Test
75
+    public void getLevel() {
76
+        assertEquals(ParserError.ERROR_ERROR, error.getLevel());
77
+        assertEquals(ParserError.ERROR_EXCEPTION, except.getLevel());
78
+        assertEquals(ParserError.ERROR_FATAL, fatal.getLevel());
79
+        assertEquals(ParserError.ERROR_WARNING, warning.getLevel());
80
+    }    
81
+
82
+    @Test
83
+    public void testException() {
84
+        fatal.setException(new Exception("foo"));
85
+        
86
+        assertTrue(fatal.isException());
87
+        assertTrue(fatal.isFatal());
88
+        assertNotNull(fatal.getException());
89
+        assertEquals("foo", fatal.getException().getMessage());
90
+        
91
+        except.setException(new IllegalAccessException());
92
+        
93
+        assertTrue(except.isException());
94
+        assertFalse(except.isFatal());
95
+        assertFalse(except.isError());
96
+        assertFalse(except.isWarning());
97
+    }
98
+
99
+    @Test
100
+    public void getData() {
101
+        assertEquals("moo", except.getData());
102
+    }
103
+
104
+    @Test
105
+    public void appendData() {
106
+        final String origin = warning.getData();
107
+        warning.appendData("new data!");
108
+        
109
+        assertTrue(warning.getData().startsWith(origin));
110
+        assertTrue(warning.getData().indexOf("new data!") > -1);
111
+    }
112
+
113
+    @Test
114
+    public void getLastLine() {
115
+        assertEquals("last line", error.getLastLine());
116
+    }
117
+
118
+    @Test
119
+    public void getSvnInfo() {
120
+        assertTrue(ParserError.getSvnInfo().toLowerCase().startsWith("$id"));
121
+    }
122
+
123
+}

Loading…
Cancel
Save