Skip to content

Commit

Permalink
Merge branch 'master' into fix-1049
Browse files Browse the repository at this point in the history
  • Loading branch information
arhohuttunen authored Mar 21, 2020
2 parents 7d6a507 + 049ac1f commit f8997d7
Show file tree
Hide file tree
Showing 19 changed files with 350 additions and 156 deletions.
2 changes: 1 addition & 1 deletion build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ buildscript {
}

plugins {
id 'nebula.kotlin' version '1.3.60'
id 'nebula.kotlin' version '1.3.70'
id 'org.jmailen.kotlinter' version '1.26.0'
id 'io.gitlab.arturbosch.detekt' version '1.0.0-RC14'
id 'org.jetbrains.dokka' version '0.10.0'
Expand Down
2 changes: 1 addition & 1 deletion consumer/pact-jvm-consumer-groovy/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ overwritten, set the Java system property `pact.writer.overwrite` to `true`.

# Publishing your pact files to a pact broker

If you use Gradle, you can use the [pact Gradle plugin](https://github.com/DiUS/pact-jvm/tree/master/pact-jvm-provider-gradle#publishing-pact-files-to-a-pact-broker) to publish your pact files.
If you use Gradle, you can use the [pact Gradle plugin](https://github.com/DiUS/pact-jvm/tree/master/provider/pact-jvm-provider-gradle#publishing-pact-files-to-a-pact-broker) to publish your pact files.

# Pact Specification V3

Expand Down
8 changes: 3 additions & 5 deletions consumer/pact-jvm-consumer-java8/build.gradle
Original file line number Diff line number Diff line change
@@ -1,12 +1,10 @@
dependencies {
api project(path: ":consumer:pact-jvm-consumer", configuration: 'default')

testCompile "org.junit.jupiter:junit-jupiter-api:${project.junit5Version}"
testRuntime "org.junit.vintage:junit-vintage-engine:${project.junit5Version}"
testImplementation "org.junit.jupiter:junit-jupiter:${project.junit5Version}"
testRuntime "ch.qos.logback:logback-classic:${project.logbackVersion}"
testCompile "junit:junit:${project.junitVersion}"
testCompile "org.codehaus.groovy:groovy:${project.groovyVersion}"
testCompile('org.spockframework:spock-core:2.0-M2-groovy-3.0') {
testImplementation "org.codehaus.groovy:groovy:${project.groovyVersion}"
testImplementation('org.spockframework:spock-core:2.0-M2-groovy-3.0') {
exclude group: 'org.codehaus.groovy'
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,13 @@ fun LambdaDslObject.newObject(name: String, nestedObject: LambdaDslObject.() ->
return `object`(name) { it.nestedObject() }
}

/**
* Extension function to make [LambdaDslObject.array] Kotlin friendly.
*/
fun LambdaDslObject.newArray(name: String, body: LambdaDslJsonArray.() -> (Unit)): LambdaDslObject {
return array(name) { it.body() }
}

/**
* Extension function to make [LambdaDslJsonArray.array] Kotlin friendly.
*/
Expand All @@ -35,4 +42,4 @@ fun LambdaDslJsonArray.newArray(body: LambdaDslJsonArray.() -> (Unit)): LambdaDs
*/
fun LambdaDslJsonArray.newObject(body: LambdaDslObject.() -> (Unit)): LambdaDslJsonArray {
return `object` { it.body() }
}
}
Original file line number Diff line number Diff line change
@@ -1,19 +1,41 @@
package io.pactfoundation.consumer.dsl

import org.hamcrest.CoreMatchers.equalTo
import org.junit.Assert.assertThat
import org.junit.jupiter.api.Test

class ExtensionsTest {
@Test
fun `can use LambdaDslJsonArray#newObject`() {
newJsonArray { newObject { stringType("foo") } }
}
@Test
fun `can use Kotlin DSL to create a Json Array`() {
val expectedJson = """[
|{"key":"value"},
|{"key_1":"value_1"}
|]""".trimMargin().replace("\n", "")

@Test
fun `can use LambdaDslObject#newObject`() {
newJsonObject {
newObject("object") {
stringType("field")
}
val actualJson = newJsonArray {
newObject { stringValue("key", "value") }
newObject { stringValue("key_1", "value_1") }
}.body.toString()

assertThat(actualJson, equalTo(expectedJson))
}

@Test
fun `can use Kotlin DSL to create a Json`() {
val expectedJson = """{
|"array":[{"key":"value"}],
|"object":{"property":"value"}
|}""".trimMargin().replace("\n", "")

val actualJson = newJsonObject {
newArray("array") {
newObject { stringValue("key", "value") }
}
newObject("object") {
stringValue("property", "value")
}
}.body.toString()

assertThat(actualJson, equalTo(expectedJson))
}
}
}
1 change: 1 addition & 0 deletions consumer/pact-jvm-consumer-junit5/build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ dependencies {
testCompile "org.codehaus.groovy:groovy-xml:${project.groovyVersion}"
testCompile 'org.apache.commons:commons-io:1.3.2'
testRuntime "org.junit.vintage:junit-vintage-engine:${project.junit5Version}"
testRuntime "org.junit.jupiter:junit-jupiter-engine:${project.junit5Version}"
testCompile project(path: ":consumer:pact-jvm-consumer-java8", configuration: 'default')
testCompile 'org.hamcrest:hamcrest:2.1'
testCompile('org.spockframework:spock-core:2.0-M2-groovy-3.0') {
Expand Down
Loading

0 comments on commit f8997d7

Please sign in to comment.