Skip to content

Commit

Permalink
feat: add comment to state change annotation and log it out when exec…
Browse files Browse the repository at this point in the history
…uted #1177
  • Loading branch information
Ronald Holshausen committed Aug 22, 2020
1 parent 577223b commit 1f0e8f0
Show file tree
Hide file tree
Showing 4 changed files with 23 additions and 3 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,14 @@ class RunStateChanges(
private fun invokeStateChangeMethods(action: StateChangeAction) {
for (method in methods) {
if (method.second.action == action) {
logger.info {
val name = method.second.value.joinToString(", ")
if (method.second.comment.isNotEmpty()) {
"Invoking state change method '$name':${method.second.action} (${method.second.comment})"
} else {
"Invoking state change method '$name':${method.second.action}"
}
}
val target = stateChangeHandlers.map(Supplier<out Any>::get).find {
it::class.isSubclassOf(method.first.declaringClass.kotlin)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class InjectedHeadersContractTest {
request.addHeader('X-ContractTest', 'true')
}

@State('an active account exists')
@State(value = 'an active account exists', comment = 'I\'m a comment')
Map<String, Object> createAccount() {
[
port: 8332,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -374,8 +374,15 @@ class PactVerificationStateChangeExtension(
"for Interaction \"${testContext.interaction.description}\" \n" +
"with Consumer \"${testContext.consumer.name}\"")
} else {
stateChangeMethods.filter { it.second.action == action }.forEach { (method, _, instance) ->
logger.debug { "Invoking state change method ${method.name} for state '${state.name}' on $instance" }
stateChangeMethods.filter { it.second.action == action }.forEach { (method, stateAnnotation, instance) ->
logger.info {
val name = stateAnnotation.value.joinToString(", ")
if (stateAnnotation.comment.isNotEmpty()) {
"Invoking state change method '$name':${stateAnnotation.action} (${stateAnnotation.comment})"
} else {
"Invoking state change method '$name':${stateAnnotation.action}"
}
}
val stateChangeValue = if (method.parameterCount > 0) {
ReflectionSupport.invokeMethod(method, instance, state.params)
} else {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,4 +23,9 @@
* Whether to run the method before (SETUP) or after (TEARDOWN) the interaction
*/
StateChangeAction action() default StateChangeAction.SETUP;

/**
* Comment associated with the state change callback
*/
String comment() default "";
}

0 comments on commit 1f0e8f0

Please sign in to comment.