-
-
Notifications
You must be signed in to change notification settings - Fork 481
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
chore(pact-jvm-server): Converted PactSessionResults to Kotlin
- Loading branch information
1 parent
21c9978
commit d154527
Showing
4 changed files
with
140 additions
and
29 deletions.
There are no files selected for viewing
25 changes: 25 additions & 0 deletions
25
pact-jvm-server/src/main/kotlin/au/com/dius/pact/server/PactSessionResults.kt
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,25 @@ | ||
package au.com.dius.pact.server | ||
|
||
import au.com.dius.pact.core.matchers.PartialRequestMatch | ||
import au.com.dius.pact.core.model.Interaction | ||
import au.com.dius.pact.core.model.Request | ||
import scala.collection.JavaConverters.asJavaIterable | ||
|
||
data class PactSessionResults( | ||
val matched: List<Interaction>, | ||
val almostMatched: List<PartialRequestMatch>, | ||
val missing: List<Interaction>, | ||
val unexpected: List<Request> | ||
) { | ||
fun addMatched(inter: Interaction) = copy(matched = listOf(inter) + matched) | ||
fun addUnexpected(request: Request) = copy(unexpected = listOf(request) + unexpected) | ||
fun addMissing(inters: scala.collection.Iterable<Interaction>) = copy(missing = asJavaIterable(inters).toList() + missing) | ||
fun addAlmostMatched(partial: PartialRequestMatch) = copy(almostMatched = listOf(partial) + almostMatched) | ||
|
||
fun allMatched(): Boolean = missing.isEmpty() && unexpected.isEmpty() | ||
|
||
companion object { | ||
@JvmStatic | ||
val empty = PactSessionResults(emptyList(), emptyList(), emptyList(), emptyList()) | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
103 changes: 103 additions & 0 deletions
103
pact-jvm-server/src/test/groovy/au/com/dius/pact/server/PactSessionResultsSpec.groovy
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,103 @@ | ||
package au.com.dius.pact.server | ||
|
||
import au.com.dius.pact.core.matchers.PartialRequestMatch | ||
import au.com.dius.pact.core.model.Request | ||
import au.com.dius.pact.core.model.RequestResponseInteraction | ||
import spock.lang.Specification | ||
|
||
import static scala.collection.JavaConverters.iterableAsScalaIterable | ||
|
||
class PactSessionResultsSpec extends Specification { | ||
def 'empty state'() { | ||
given: | ||
def state = PactSessionResults.empty | ||
|
||
expect: | ||
state.allMatched() | ||
state.almostMatched.empty | ||
state.matched.empty | ||
state.unexpected.empty | ||
state.missing.empty | ||
} | ||
|
||
def 'add matched interaction'() { | ||
given: | ||
def state = PactSessionResults.empty | ||
|
||
when: | ||
state = state.addMatched(new RequestResponseInteraction('test')) | ||
|
||
then: | ||
state.allMatched() | ||
state.almostMatched.empty | ||
state.matched*.description == ['test'] | ||
state.unexpected.empty | ||
state.missing.empty | ||
} | ||
|
||
def 'add two matched interactions'() { | ||
given: | ||
def state = PactSessionResults.empty | ||
|
||
when: | ||
state = state.addMatched(new RequestResponseInteraction('test')) | ||
state = state.addMatched(new RequestResponseInteraction('test2')) | ||
|
||
then: | ||
state.allMatched() | ||
state.almostMatched.empty | ||
state.matched*.description == ['test2', 'test'] | ||
state.unexpected.empty | ||
state.missing.empty | ||
} | ||
|
||
def 'add unexpected request'() { | ||
given: | ||
def state = PactSessionResults.empty | ||
def request = new Request('GET', '/test') | ||
|
||
when: | ||
state = state.addUnexpected(request) | ||
|
||
then: | ||
!state.allMatched() | ||
state.almostMatched.empty | ||
state.matched.empty | ||
state.unexpected*.path == ['/test'] | ||
state.missing.empty | ||
} | ||
|
||
def 'add missing interactions'() { | ||
given: | ||
def state = PactSessionResults.empty | ||
def interaction1 = new RequestResponseInteraction('test') | ||
def interaction2 = new RequestResponseInteraction('test2') | ||
def interaction3 = new RequestResponseInteraction('test3') | ||
|
||
when: | ||
state = state.addMissing(iterableAsScalaIterable([interaction1])) | ||
state = state.addMissing(iterableAsScalaIterable([interaction2, interaction3])) | ||
|
||
then: | ||
!state.allMatched() | ||
state.almostMatched.empty | ||
state.matched.empty | ||
state.unexpected.empty | ||
state.missing*.description == ['test2', 'test3', 'test'] | ||
} | ||
|
||
def 'add almost matched'() { | ||
given: | ||
def state = PactSessionResults.empty | ||
|
||
when: | ||
state = state.addAlmostMatched(new PartialRequestMatch([:])) | ||
|
||
then: | ||
state.allMatched() | ||
!state.almostMatched.empty | ||
state.matched.empty | ||
state.unexpected.empty | ||
state.missing.empty | ||
} | ||
} |