Kaynağa Gözat

Merge pull request #32 from csmith/master

Add a couple of trivial tests.
pull/33/head
Greg Holmes 9 yıl önce
ebeveyn
işleme
c5e1f41b5b

+ 1
- 1
src/com/dmdirc/util/colours/ColourUtils.java Dosyayı Görüntüle

@@ -25,7 +25,7 @@ package com.dmdirc.util.colours;
25 25
 /**
26 26
  * Some util methods for dealing with colours.
27 27
  */
28
-public class ColourUtils {
28
+public final class ColourUtils {
29 29
 
30 30
     private ColourUtils() {
31 31
         //Do not instantiate.

+ 46
- 0
test/com/dmdirc/util/colours/ColourUtilsTest.java Dosyayı Görüntüle

@@ -0,0 +1,46 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
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
+
23
+package com.dmdirc.util.colours;
24
+
25
+import org.junit.Test;
26
+
27
+import static org.junit.Assert.assertEquals;
28
+
29
+public class ColourUtilsTest {
30
+
31
+    @Test
32
+    public void testGetHexZero() {
33
+        assertEquals("000000", ColourUtils.getHex(new Colour(0, 0, 0)));
34
+    }
35
+
36
+    @Test
37
+    public void testGetHexEffs() {
38
+        assertEquals("ffffff", ColourUtils.getHex(new Colour(255, 255, 255)));
39
+    }
40
+
41
+    @Test
42
+    public void testGetHexRandom() {
43
+        assertEquals("44978f", ColourUtils.getHex(new Colour(68, 151, 143)));
44
+    }
45
+
46
+}

+ 52
- 0
test/com/dmdirc/util/validators/ValidatorChainBuilderTest.java Dosyayı Görüntüle

@@ -0,0 +1,52 @@
1
+/*
2
+ * Copyright (c) 2006-2015 DMDirc Developers
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
+
23
+package com.dmdirc.util.validators;
24
+
25
+import org.junit.Test;
26
+
27
+import static org.junit.Assert.assertFalse;
28
+import static org.junit.Assert.assertTrue;
29
+
30
+public class ValidatorChainBuilderTest {
31
+
32
+    @Test
33
+    public void testEmptyBuilder() {
34
+        final ValidatorChain<String> validatorChain = ValidatorChain.<String>builder().build();
35
+
36
+        assertFalse(validatorChain.validate("test").isFailure());
37
+        assertFalse(validatorChain.validate("").isFailure());
38
+    }
39
+
40
+    @Test
41
+    public void testBuilderWithMultipleValidators() {
42
+        final ValidatorChain<String> validatorChain = ValidatorChain.<String>builder()
43
+                .addValidator(new StringLengthValidator(0, 5))
44
+                .addValidator(new NotEmptyValidator())
45
+                .build();
46
+
47
+        assertFalse(validatorChain.validate("test").isFailure());
48
+        assertTrue(validatorChain.validate("").isFailure());
49
+        assertTrue(validatorChain.validate("123456").isFailure());
50
+    }
51
+
52
+}

Loading…
İptal
Kaydet