Skip to content

Commit df692b9

Browse files
Merge pull request #17 from magneticflux-/feature/spock-tests
Feature/spock tests
2 parents bc80d2a + b732cc0 commit df692b9

File tree

16 files changed

+306
-80
lines changed

16 files changed

+306
-80
lines changed

build.gradle

Lines changed: 67 additions & 72 deletions
Original file line numberDiff line numberDiff line change
@@ -1,107 +1,102 @@
11
buildscript {
2-
ext.kotlin_version = '1.2.21'
3-
ext.spek_version = '1.1.5'
4-
5-
repositories {
6-
jcenter()
7-
}
8-
dependencies {
9-
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
10-
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.16"
11-
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0'
12-
}
2+
ext.kotlin_version = '1.2.21'
3+
ext.spek_version = '1.1.5'
4+
5+
repositories { jcenter() }
6+
dependencies {
7+
classpath "org.jetbrains.kotlin:kotlin-gradle-plugin:$kotlin_version"
8+
classpath "org.jetbrains.dokka:dokka-gradle-plugin:0.9.16"
9+
classpath 'org.junit.platform:junit-platform-gradle-plugin:1.1.0'
10+
}
1311
}
1412

1513
plugins {
16-
id 'java-library'
17-
id 'jacoco'
18-
id 'maven-publish'
19-
id 'com.jfrog.bintray' version '1.8.0'
20-
id 'org.shipkit.java' version '2.0.2'
21-
id 'com.diffplug.gradle.spotless' version '3.10.0'
22-
id 'com.github.ben-manes.versions' version '0.17.0'
14+
id 'java-library'
15+
id 'jacoco'
16+
id 'maven-publish'
17+
id 'groovy'
18+
id 'com.jfrog.bintray' version '1.8.0'
19+
id 'org.shipkit.java' version '2.0.2'
20+
id 'com.diffplug.gradle.spotless' version '3.10.0'
21+
id 'com.github.ben-manes.versions' version '0.17.0'
2322
}
2423

2524
apply plugin: 'kotlin'
2625
apply plugin: 'org.jetbrains.dokka'
27-
apply plugin: 'org.junit.platform.gradle.plugin'
2826

2927
group 'com.github.magneticflux'
3028

3129
repositories {
32-
jcenter()
33-
maven { url 'http://dl.bintray.com/jetbrains/spek' }
30+
jcenter()
31+
maven { url 'http://dl.bintray.com/jetbrains/spek' }
3432
}
3533

36-
junitPlatform {
37-
filters {
38-
engines {
39-
include 'spek'
40-
}
41-
}
34+
test {
35+
useJUnitPlatform { includeEngines 'spek', 'junit-vintage' }
4236
}
4337

4438
publishing {
45-
publications {
46-
myPublication(MavenPublication) {
47-
from components.java
48-
//noinspection GroovyAssignabilityCheck
49-
artifact sourcesJar
50-
//noinspection GroovyAssignabilityCheck
51-
artifact dokkaJavadocJar
52-
}
53-
}
39+
publications {
40+
myPublication(MavenPublication) {
41+
from components.java
42+
//noinspection GroovyAssignabilityCheck
43+
artifact sourcesJar
44+
//noinspection GroovyAssignabilityCheck
45+
artifact dokkaJavadocJar
46+
}
47+
}
5448
}
5549

5650
dokka {
57-
outputFormat = 'javadoc'
58-
jdkVersion = 7
59-
impliedPlatforms = ["JVM"]
51+
outputFormat = 'javadoc'
52+
jdkVersion = 7
53+
impliedPlatforms = ["JVM"]
6054
}
6155

6256
task dokkaJavadocJar(type: Jar, dependsOn: dokka) {
63-
classifier = 'javadoc'
64-
from dokka.outputDirectory
57+
classifier = 'javadoc'
58+
//noinspection GroovyAssignabilityCheck
59+
from dokka.outputDirectory
6560
}
6661

6762
spotless {
68-
kotlin {
69-
ktlint('0.14.0')
70-
}
71-
}
72-
73-
dependencies {
74-
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
63+
kotlin { ktlint('0.15.1') }
7564

76-
api 'org.simpleframework:simple-xml:2.7.1'
77-
api 'org.threeten:threetenbp:1.3.6'
65+
groovy { greclipse() }
7866

79-
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
80-
testImplementation "org.jetbrains.spek:spek-api:$spek_version"
81-
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
82-
testRuntimeOnly "org.jetbrains.spek:spek-junit-platform-engine:$spek_version"
67+
groovyGradle { greclipse() }
8368
}
8469

85-
jacoco {
86-
applyTo junitPlatformTest
87-
}
88-
89-
junitPlatformTest {
90-
jacoco {
91-
destinationFile = file("$buildDir/jacoco/test.exec")
92-
}
70+
dependencies {
71+
implementation "org.jetbrains.kotlin:kotlin-stdlib-jdk7:$kotlin_version"
72+
73+
api 'org.simpleframework:simple-xml:2.7.1'
74+
api 'org.threeten:threetenbp:1.3.6'
75+
76+
// Tests
77+
testImplementation 'org.hamcrest:java-hamcrest:2.0.0.0'
78+
79+
// Spock
80+
testImplementation 'org.codehaus.groovy:groovy-all:2.4.13'
81+
testImplementation "org.spockframework:spock-core:1.1-groovy-2.4"
82+
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.1.0'
83+
testRuntimeOnly 'org.junit.jupiter:junit-jupiter-engine:5.1.0'
84+
testRuntimeOnly 'org.junit.vintage:junit-vintage-engine:5.1.0'
85+
testCompileOnly 'junit:junit:4.12'
86+
87+
// Spek
88+
testImplementation "org.jetbrains.spek:spek-api:$spek_version"
89+
testImplementation "org.jetbrains.kotlin:kotlin-reflect:$kotlin_version"
90+
testRuntimeOnly "org.jetbrains.spek:spek-junit-platform-engine:$spek_version"
9391
}
9492

9593
jacocoTestReport {
96-
executionData junitPlatformTest
97-
sourceSets sourceSets.main
98-
dependsOn(junitPlatformTest)
99-
100-
reports {
101-
//noinspection GroovyAssignabilityCheck
102-
xml {
103-
enabled true
104-
}
105-
}
94+
sourceSets sourceSets.main
95+
dependsOn test
96+
97+
reports {
98+
//noinspection GroovyAssignabilityCheck
99+
xml { enabled true }
100+
}
106101
}
107102
check.dependsOn(jacocoTestReport)

gradle.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,2 @@
11
org.gradle.caching=true
2-
org.gradle.parallel=true
2+
org.gradle.parallel=true

gradle/wrapper/gradle-wrapper.properties

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,4 +2,4 @@ distributionBase=GRADLE_USER_HOME
22
distributionPath=wrapper/dists
33
zipStoreBase=GRADLE_USER_HOME
44
zipStorePath=wrapper/dists
5-
distributionUrl=https\://services.gradle.org/distributions/gradle-4.5.1-all.zip
5+
distributionUrl=https\://services.gradle.org/distributions/gradle-4.6-rc-2-all.zip

src/main/kotlin/com/github/magneticflux/rss/Converters.kt

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ internal val InputNode.fullName: String
1616
get() {
1717
val prefix = this.prefix
1818
val name = this.name
19-
return if (prefix.isNullOrEmpty()) name else "$prefix:$name"
19+
return if (prefix.isEmpty()) name else "$prefix:$name"
2020
}
2121

2222
/**
@@ -44,7 +44,6 @@ private class InputNodeChildIterator(val rootNode: InputNode) : AbstractIterator
4444
val next = rootNode.next
4545
if (next != null)
4646
setNext(next)
47-
else
48-
done()
47+
else done()
4948
}
50-
}
49+
}

src/main/kotlin/com/github/magneticflux/rss/Transforms.kt

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -82,7 +82,6 @@ object URLTransform : Transform<URL> {
8282
override fun write(value: URL): String {
8383
return if (value.authority == null)
8484
value.file
85-
else
86-
value.toExternalForm()
85+
else value.toExternalForm()
8786
}
8887
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.github.magneticflux.rss
2+
3+
import spock.lang.Shared
4+
import spock.lang.Specification
5+
6+
abstract class PersisterSpecification extends Specification {
7+
@Shared
8+
protected persister = PersistersKt.createRssPersister()
9+
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
package com.github.magneticflux.rss
2+
3+
class UrlUtils {
4+
static URL testUrl() {
5+
return new URL('http://www.example.com')
6+
}
7+
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
package com.github.magneticflux.rss.namespaces.standard.elements
2+
3+
import com.github.magneticflux.rss.PersisterSpecification
4+
import spock.lang.Unroll
5+
6+
class CategoryTest extends PersisterSpecification {
7+
8+
@Unroll
9+
def 'category #object read/write'() {
10+
11+
expect: 'the output XML equals the given XML'
12+
persister.write(object) == xml
13+
14+
and: 'the input object equals the given object'
15+
persister.read(Category, xml) == object
16+
17+
where:
18+
domain | text | xml
19+
'testDomain' | 'testText' | """<category domain="$domain">$text</category>"""
20+
null | 'testText' | """<category>$text</category>"""
21+
object = new Category(domain, text)
22+
}
23+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.magneticflux.rss.namespaces.standard.elements
2+
3+
import com.github.magneticflux.rss.PersisterSpecification
4+
import spock.lang.Unroll
5+
6+
class CloudTest extends PersisterSpecification {
7+
@Unroll
8+
def 'cloud #object read/write'() {
9+
10+
expect: 'the output XML equals the given XML'
11+
persister.write(object) == xml
12+
13+
and: 'the input object equals the given object'
14+
persister.read(Cloud, xml) == object
15+
16+
where:
17+
domain | path | port | protocol | registerProcedure | xml
18+
'testDomain' | 'testPath' | 8080 | 'testProtocol' | 'testRegisterProcedure' | """<cloud domain="$domain" path="$path" port="$port" protocol="$protocol" registerProcedure="$registerProcedure"/>"""
19+
object = new Cloud(domain, path, port, protocol, registerProcedure)
20+
}
21+
}
Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
package com.github.magneticflux.rss.namespaces.standard.elements
2+
3+
import com.github.magneticflux.rss.PersisterSpecification
4+
import spock.lang.Unroll
5+
6+
class EnclosureTest extends PersisterSpecification {
7+
@Unroll
8+
def 'enclosure #object read/write'() {
9+
10+
expect: 'the output XML equals the given XML'
11+
persister.write(object) == xml
12+
13+
and: 'the input object equals the given object'
14+
persister.read(Enclosure, xml) == object
15+
16+
where:
17+
url | length | type | xml
18+
'http://www.example.com'.toURL() | 1000 | 'testType' | """<enclosure url="$url" length="$length" type="$type"/>"""
19+
object = new Enclosure(url, length, type)
20+
}
21+
}

0 commit comments

Comments
 (0)