Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support using other JUnit @Disabled.. annotations #1844

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,15 @@ import au.com.dius.pact.core.support.isNotEmpty
import io.github.oshai.kotlinlogging.KLogging
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Nested
import org.junit.jupiter.api.condition.DisabledForJreRange
import org.junit.jupiter.api.condition.DisabledIf
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariable
import org.junit.jupiter.api.condition.DisabledIfEnvironmentVariables
import org.junit.jupiter.api.condition.DisabledIfSystemProperties
import org.junit.jupiter.api.condition.DisabledIfSystemProperty
import org.junit.jupiter.api.condition.DisabledInNativeImage
import org.junit.jupiter.api.condition.DisabledOnJre
import org.junit.jupiter.api.condition.DisabledOnOs
import org.junit.jupiter.api.extension.AfterAllCallback
import org.junit.jupiter.api.extension.AfterTestExecutionCallback
import org.junit.jupiter.api.extension.BeforeAllCallback
Expand Down Expand Up @@ -713,13 +722,27 @@ class PactConsumerTestExt : Extension, BeforeTestExecutionCallback, BeforeAllCal
val methods = AnnotationSupport.findAnnotatedMethods(context.requiredTestClass, Pact::class.java,
HierarchyTraversalMode.TOP_DOWN)
if (executedFragments.size < methods.size) {
val nonExecutedMethods = (methods - executedFragments).filter {
!isAnnotated(it, Disabled::class.java)
val disabledAnnotations = listOf(
Disabled::class.java,
DisabledForJreRange::class.java,
DisabledIf::class.java,
DisabledIfEnvironmentVariable::class.java,
DisabledIfEnvironmentVariables::class.java,
DisabledIfSystemProperties::class.java,
DisabledIfSystemProperty::class.java,
DisabledInNativeImage::class.java,
DisabledOnJre::class.java,
DisabledOnOs::class.java
)

val nonExecutedMethods = (methods - executedFragments).filter { method ->
!disabledAnnotations.any { disabledAnnotation -> isAnnotated(method, disabledAnnotation) }
}.joinToString(", ") { it.declaringClass.simpleName + "." + it.name }
if (nonExecutedMethods.isNotEmpty()) {
throw AssertionError(
"The following methods annotated with @Pact were not executed during the test: $nonExecutedMethods" +
"\nIf these are currently a work in progress, add a @Disabled annotation to the method\n")
"\nIf these are currently a work in progress, add JUnit's @Disabled annotation " +
"(or one of the @DisabledIf/@DisabledFor/@DisabledOn annotations) to the method\n")
}
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,7 @@ import org.apache.hc.client5.http.fluent.Request
import org.apache.hc.core5.http.ContentType
import org.junit.jupiter.api.Disabled
import org.junit.jupiter.api.Test
import org.junit.jupiter.api.condition.DisabledIf
import org.junit.jupiter.api.extension.ExtendWith

@SuppressWarnings(['PublicInstanceField', 'JUnitPublicNonTestMethod', 'FactoryMethodName'])
Expand Down Expand Up @@ -153,4 +154,20 @@ class MultiTest {
.status(404)
.toPact()
}

@Pact(provider = 'multitest_provider', consumer = 'test_consumer')
@DisabledIf('shouldBeDisabled')
RequestResponsePact getAnotherUsersFragment3(PactDslWithProvider builder) {
builder
.uponReceiving('get all users')
.path('/idm/user')
.method('GET')
.willRespondWith()
.status(404)
.toPact()
}

boolean shouldBeDisabled() {
true
}
}
Loading