Skip to content

Commit

Permalink
Merge remote-tracking branch 'origin/v3.6.x'
Browse files Browse the repository at this point in the history
  • Loading branch information
Ronald Holshausen committed Oct 13, 2019
2 parents d54923d + f53bd4c commit 3a311c8
Show file tree
Hide file tree
Showing 3 changed files with 108 additions and 2 deletions.
7 changes: 7 additions & 0 deletions CHANGELOG.md
Expand Up @@ -35,6 +35,13 @@ To generate the log, run `git log --pretty='* %h - %s (%an, %ad)' TAGNAME..HEAD
* 28447536 - Issue#929 Added the ability to add a version for the provider in pact-jvm-provider-gradle (yoran.kerbusch, Fri Aug 30 16:06:02 2019 +0200)
* 87df5116 - chore: switch to openjdk 8 on travis (Ronald Holshausen, Sat Aug 24 10:39:54 2019 +1000)

# 3.6.14 - Bugfix Release

* f0acf0a7 - fix: use the charset from the content type when converting bodies to bytes #941 (Ronald Holshausen, Fri Sep 27 18:24:48 2019 +1000)
* 63fed4ca - fix: remove all references to the mockserver on complete #939 (Ronald Holshausen, Fri Sep 27 17:09:27 2019 +1000)
* c5a9e050 - fix: GET on pact-jvm-server root delivers broken json #938 (Ronald Holshausen, Fri Sep 27 16:29:20 2019 +1000)
* 72bbfaa1 - bump version to 3.6.14 (Ronald Holshausen, Sun Sep 8 12:44:35 2019 +1000)

# 3.6.13 - Bugfix Release

* 97a076d3 - fix: mark the test result as failed if a state change callback fails #930 (Ronald Holshausen, Sun Sep 8 11:38:54 2019 +1000)
Expand Down
Expand Up @@ -16,8 +16,11 @@ class RunStateChanges(

override fun evaluate() {
invokeStateChangeMethods(StateChangeAction.SETUP)
next.evaluate()
invokeStateChangeMethods(StateChangeAction.TEARDOWN)
try {
next.evaluate()
} finally {
invokeStateChangeMethods(StateChangeAction.TEARDOWN)
}
}

private fun invokeStateChangeMethods(action: StateChangeAction) {
Expand Down
@@ -0,0 +1,96 @@
package au.com.dius.pact.provider.junit

import au.com.dius.pact.core.model.ProviderState
import kotlin.Pair
import org.junit.runners.model.FrameworkMethod
import org.junit.runners.model.Statement
import spock.lang.Specification

import java.util.function.Supplier

@SuppressWarnings(['ThrowRuntimeException', 'UnnecessaryParenthesesForMethodCallWithClosure'])
class RunStateChangesSpec extends Specification {

private Statement next
private ProviderState providerState
private Map testContext
private List<Pair<FrameworkMethod, State>> methods
private List<Supplier> stateChangeHandlers

class TestTarget {
boolean called = false
boolean teardownCalled = false

@State('Test State')
void stateChange() {
called = true
}

@State(value = 'Test State', action = StateChangeAction.TEARDOWN)
void stateChangeTeardown() {
teardownCalled = true
}
}

private TestTarget target

def setup() {
providerState = new ProviderState('Test State')
testContext = [:]
next = Mock()
methods = [
new Pair(new FrameworkMethod(TestTarget.getDeclaredMethod('stateChange')),
TestTarget.getDeclaredMethod('stateChange').getAnnotation(State))
]
stateChangeHandlers = [
{ target } as Supplier
]
target = Spy(TestTarget)
}

def 'invokes the state change method before the next statement'() {
when:
new RunStateChanges(next, methods, stateChangeHandlers, providerState, testContext).evaluate()

then:
1 * next.evaluate()
1 * target.stateChange()
0 * target.stateChangeTeardown()
}

def 'invokes the state change teardown method after the next statement'() {
given:
methods << new Pair(new FrameworkMethod(TestTarget.getDeclaredMethod('stateChangeTeardown')),
TestTarget.getDeclaredMethod('stateChangeTeardown').getAnnotation(State))

when:
new RunStateChanges(next, methods, stateChangeHandlers, providerState, testContext).evaluate()

then:
1 * next.evaluate()
1 * target.stateChange()

then:
1 * target.stateChangeTeardown()
}

def 'still invokes the state change teardown method if the the next statement fails'() {
given:
methods << new Pair(new FrameworkMethod(TestTarget.getDeclaredMethod('stateChangeTeardown')),
TestTarget.getDeclaredMethod('stateChangeTeardown').getAnnotation(State))
next = Mock() {
evaluate() >> { throw new RuntimeException('Boom') }
}

when:
new RunStateChanges(next, methods, stateChangeHandlers, providerState, testContext).evaluate()

then:
1 * target.stateChange()
thrown(RuntimeException)

then:
1 * target.stateChangeTeardown()
}

}

0 comments on commit 3a311c8

Please sign in to comment.