소스 검색

Merge branch 'master' of https://github.com/DMDirc/Util

pull/35/head
Greg Holmes 9 년 전
부모
커밋
79b20338a6

+ 22
- 27
build.gradle 파일 보기

@@ -1,13 +1,11 @@
1
-import org.mdonoughe.JGitDescribeTask
2
-
3
-def jgit = new org.mdonoughe.JGitDescribeTask()
4
-jgit.setDir(new File("$projectDir", '.git'))
5
-project.version = jgit.getDescription() + '-SNAPSHOT'
1
+group = 'com.dmdirc'
6 2
 
3
+apply plugin: 'com.dmdirc.git-version'
7 4
 apply plugin: 'java'
8 5
 apply plugin: 'maven-publish'
6
+apply plugin: 'jacoco'
7
+apply plugin: 'com.github.kt3k.coveralls'
9 8
 
10
-group = 'com.dmdirc'
11 9
 
12 10
 sourceSets {
13 11
     main {
@@ -33,6 +31,11 @@ dependencies {
33 31
     testCompile group: 'com.google.jimfs', name: 'jimfs', version: '1.0'
34 32
 }
35 33
 
34
+// DMDirc uses 18.0, JimFS has a transient dep on 16.0.1 - force the newer version
35
+configurations.all {
36
+    resolutionStrategy.force('com.google.guava:guava:18.0')
37
+}
38
+
36 39
 publishing {
37 40
     publications {
38 41
         mavenJava(MavenPublication) {
@@ -51,34 +54,26 @@ task wrapper(type: Wrapper) {
51 54
     gradleVersion = '2.2.1'
52 55
 }
53 56
 
54
-task getCredentials << {
55
-    def target = file('nexus-teamcity.gradle')
56
-    if (!target.exists()) {
57
-        new URL('http://www.dmdirc.com/private/nexus-teamcity.gradle').withInputStream{
58
-            i -> target.withOutputStream { it << i }
59
-        }
60
-    }
61
-
62
-    apply from: 'nexus-teamcity.gradle'
63
-    project.publishing.repositories[0].credentials {
64
-        username "$nexusUser"
65
-        password "$nexusPass"
66
-    }
67
-}
68
-
69
-task publishSnapshot(dependsOn: ['getCredentials', 'publishMavenJavaPublicationToSnapshotsRepository']) << {
57
+task publishSnapshot(dependsOn: 'publishMavenJavaPublicationToSnapshotsRepository') << {
70 58
 }
71 59
 
72 60
 buildscript {
73 61
     repositories {
74 62
         mavenCentral()
75
-        maven {
76
-            url 'http://artifactory.dmdirc.com/artifactory/repo'
77
-        }
63
+        maven { url 'http://artifactory.dmdirc.com/artifactory/repo' }
64
+        maven { url 'https://dl.bintray.com/dmdirc/releases/' }
78 65
     }
79 66
 
80 67
     dependencies {
81
-        classpath group: 'com.github.shanemcc', name: 'jgit-describe', version: '0.5'
82
-        classpath group: 'org.eclipse.jgit', name: 'org.eclipse.jgit', version: '2.3.1.+'
68
+        classpath group: 'com.dmdirc', name: 'git-version', version: '1.0'
69
+        classpath 'org.kt3k.gradle.plugin:coveralls-gradle-plugin:2.1.0'
83 70
     }
84 71
 }
72
+
73
+jacocoTestReport {
74
+    reports {
75
+        xml.enabled = true // coveralls plugin depends on xml format report
76
+        html.enabled = true
77
+    }
78
+}
79
+

+ 17
- 1
circle.yml 파일 보기

@@ -2,4 +2,20 @@
2 2
 
3 3
 machine:
4 4
   java:
5
-    version: oraclejdk8
5
+    version: oraclejdk8
6
+  environment:
7
+    TERM: dumb
8
+
9
+checkout:
10
+  post:
11
+    - git fetch --tags
12
+
13
+dependencies:
14
+  override:
15
+    - ./gradlew dependencies
16
+
17
+test:
18
+  override:
19
+    - ./gradlew test
20
+  post:
21
+    - ./gradlew jacocoTestReport coveralls

+ 1
- 1
src/com/dmdirc/util/colours/ColourUtils.java 파일 보기

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

+ 45
- 3
test/com/dmdirc/util/collections/ObservableListDecoratorTest.java 파일 보기

@@ -23,12 +23,20 @@
23 23
 package com.dmdirc.util.collections;
24 24
 
25 25
 import java.util.Arrays;
26
-import java.util.List;
27
-import org.junit.Test;
28 26
 import java.util.LinkedList;
27
+import java.util.List;
29 28
 
30 29
 import org.junit.Before;
31
-import static org.mockito.Mockito.*;
30
+import org.junit.Test;
31
+
32
+import static org.junit.Assert.assertEquals;
33
+import static org.junit.Assert.assertFalse;
34
+import static org.junit.Assert.assertTrue;
35
+import static org.mockito.Mockito.anyInt;
36
+import static org.mockito.Mockito.anyObject;
37
+import static org.mockito.Mockito.mock;
38
+import static org.mockito.Mockito.never;
39
+import static org.mockito.Mockito.verify;
32 40
 
33 41
 public class ObservableListDecoratorTest {
34 42
 
@@ -101,4 +109,38 @@ public class ObservableListDecoratorTest {
101 109
         verify(observer).onItemsRemoved(obslist, 2, 2);
102 110
     }
103 111
 
112
+    @Test
113
+    public void testRemovingListenerStopsFutureCalls() {
114
+        obslist.removeListListener(observer);
115
+        obslist.add("test");
116
+        verify(observer, never()).onItemsAdded(obslist, 0, 0);
117
+    }
118
+
119
+    @Test
120
+    public void testSize() {
121
+        assertEquals(0, obslist.size());
122
+        obslist.add("test");
123
+        assertEquals(1, obslist.size());
124
+        obslist.add("test");
125
+        assertEquals(2, obslist.size());
126
+    }
127
+
128
+    @Test
129
+    public void testIsEmpty() {
130
+        assertTrue(obslist.isEmpty());
131
+        obslist.add("test");
132
+        assertFalse(obslist.isEmpty());
133
+        obslist.remove("test");
134
+        assertTrue(obslist.isEmpty());
135
+    }
136
+
137
+    @Test
138
+    public void testContains() {
139
+        assertFalse(obslist.contains("test"));
140
+        obslist.add("test");
141
+        assertTrue(obslist.contains("test"));
142
+        obslist.remove("test");
143
+        assertFalse(obslist.contains("test"));
144
+    }
145
+
104 146
 }

+ 133
- 0
test/com/dmdirc/util/collections/QueuedLinkedHashSetTest.java 파일 보기

@@ -0,0 +1,133 @@
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.collections;
24
+
25
+import java.util.NoSuchElementException;
26
+
27
+import org.junit.Before;
28
+import org.junit.Test;
29
+
30
+import static org.junit.Assert.assertEquals;
31
+import static org.junit.Assert.assertFalse;
32
+import static org.junit.Assert.assertNull;
33
+import static org.junit.Assert.assertTrue;
34
+
35
+public class QueuedLinkedHashSetTest {
36
+
37
+    private QueuedLinkedHashSet<String> set;
38
+
39
+    @Before
40
+    public void setup() {
41
+        set = new QueuedLinkedHashSet<>();
42
+    }
43
+
44
+    @Test(expected = NoSuchElementException.class)
45
+    public void testElementWhenNewlyCreated() {
46
+        set.element();
47
+    }
48
+
49
+    @Test(expected = NoSuchElementException.class)
50
+    public void testElementWhenEmpty() {
51
+        set.offer("foo");
52
+        set.remove();
53
+        set.element();
54
+    }
55
+
56
+    @Test(expected = NoSuchElementException.class)
57
+    public void testRemoveWhenNewlyCreated() {
58
+        set.remove();
59
+    }
60
+
61
+    @Test(expected = NoSuchElementException.class)
62
+    public void testRemoveWhenEmpty() {
63
+        set.offer("foo");
64
+        set.remove();
65
+        set.remove();
66
+    }
67
+
68
+    @Test
69
+    public void testOfferMultipleItems() {
70
+        assertTrue(set.offer("one"));
71
+        assertEquals(1, set.size());
72
+        assertFalse(set.offer("one"));
73
+        assertEquals(1, set.size());
74
+    }
75
+
76
+    @Test
77
+    public void testRemove() {
78
+        set.offer("one");
79
+        set.offer("two");
80
+        assertEquals("two", set.remove());
81
+        assertEquals("one", set.remove());
82
+        assertTrue(set.isEmpty());
83
+    }
84
+
85
+    @Test
86
+    public void testPoll() {
87
+        set.offer("one");
88
+        set.offer("two");
89
+        assertEquals("two", set.poll());
90
+        assertEquals("one", set.poll());
91
+        assertTrue(set.isEmpty());
92
+    }
93
+
94
+    @Test
95
+    public void testPeekWhenNewlyCreated() {
96
+        assertNull(set.peek());
97
+    }
98
+
99
+    @Test
100
+    public void testPeekWhenEmpty() {
101
+        set.offer("foo");
102
+        set.remove();
103
+        assertNull(set.peek());
104
+    }
105
+
106
+    @Test
107
+    public void testPeek() {
108
+        set.offer("one");
109
+        set.offer("two");
110
+        assertEquals("two", set.peek());
111
+        assertEquals("two", set.peek());
112
+        assertEquals(2, set.size());
113
+    }
114
+
115
+    @Test
116
+    public void testOfferAndMoveExisting() {
117
+        set.offer("one");
118
+        set.offer("two");
119
+        set.offerAndMove("one");
120
+        assertEquals("one", set.peek());
121
+        assertEquals(2, set.size());
122
+    }
123
+
124
+    @Test
125
+    public void testOfferAndMoveNew() {
126
+        set.offer("one");
127
+        set.offer("two");
128
+        set.offerAndMove("three");
129
+        assertEquals("three", set.peek());
130
+        assertEquals(3, set.size());
131
+    }
132
+
133
+}

+ 14
- 0
test/com/dmdirc/util/collections/RollingListTest.java 파일 보기

@@ -136,4 +136,18 @@ public class RollingListTest {
136 136
         assertEquals("Bar", rl.getPrevious());
137 137
     }
138 138
 
139
+    @Test
140
+    public void testRemove() {
141
+        final RollingList<String> rl = new RollingList<>(2);
142
+
143
+        rl.add("Foo");
144
+        rl.add("Bar");
145
+        rl.remove("Bar");
146
+        rl.add("Baz");
147
+
148
+        assertEquals("Foo", rl.get(0));
149
+        assertEquals("Baz", rl.get(1));
150
+        assertFalse(rl.contains("Bar"));
151
+    }
152
+
139 153
 }

+ 59
- 0
test/com/dmdirc/util/colours/ColourTest.java 파일 보기

@@ -0,0 +1,59 @@
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
+import static org.junit.Assert.assertFalse;
29
+import static org.junit.Assert.assertTrue;
30
+import static org.junit.Assume.assumeTrue;
31
+
32
+public class ColourTest {
33
+
34
+    @Test
35
+    public void testGetters() {
36
+        final Colour colour = new Colour(12, 0, 255);
37
+        assertEquals(12, colour.getRed());
38
+        assertEquals(0, colour.getGreen());
39
+        assertEquals(255, colour.getBlue());
40
+    }
41
+
42
+    @Test
43
+    public void testEquals() {
44
+        assertTrue(new Colour(1, 2, 3).equals(new Colour(1, 2, 3)));
45
+        assertTrue(Colour.RED.equals(new Colour(255, 0, 0)));
46
+        assertFalse(new Colour(3, 2, 1).equals(new Colour(1, 2, 3)));
47
+        assertFalse(Colour.RED.equals(new Colour(255, 1, 0)));
48
+    }
49
+
50
+    @Test
51
+    public void testHashcodeSameForEqualColours() {
52
+        assumeTrue(new Colour(1, 2, 3).equals(new Colour(1, 2, 3)));
53
+        assertEquals(new Colour(1, 2, 3).hashCode(), new Colour(1, 2, 3).hashCode());
54
+
55
+        assumeTrue(Colour.RED.equals(new Colour(255, 0, 0)));
56
+        assertEquals(Colour.RED.hashCode(), new Colour(255, 0, 0).hashCode());
57
+    }
58
+
59
+}

+ 46
- 0
test/com/dmdirc/util/colours/ColourUtilsTest.java 파일 보기

@@ -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 파일 보기

@@ -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…
취소
저장