Skip to content

Commit d17fb50

Browse files
committed
feat(JUnit5): Add tests to cover the changes #1866
1 parent af9e35f commit d17fb50

File tree

1 file changed

+102
-0
lines changed

1 file changed

+102
-0
lines changed

consumer/junit5/src/test/groovy/au/com/dius/pact/consumer/junit5/PactConsumerTestExtSpec.groovy

Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -16,6 +16,7 @@ import au.com.dius.pact.core.model.messaging.MessagePact
1616
import au.com.dius.pact.core.support.BuiltToolConfig
1717
import groovy.json.JsonSlurper
1818
import kotlin.Pair
19+
import org.junit.jupiter.api.Disabled
1920
import org.junit.jupiter.api.extension.ExtensionContext
2021
import org.junit.jupiter.api.extension.ParameterContext
2122
import org.mockito.Mockito
@@ -538,4 +539,105 @@ class PactConsumerTestExtSpec extends Specification {
538539
testExt.setupPactForTest(provider, ['pactMethod1', 'pactMethod2'], mockContext).interactions*.description ==
539540
['interaction 1', 'interaction 2']
540541
}
542+
543+
static class TestSetupDisabled {
544+
@Pact(consumer = 'consumer1')
545+
RequestResponsePact method1(PactDslWithProvider builder) {
546+
builder
547+
.uponReceiving('interaction 1')
548+
.path('/one')
549+
.willRespondWith()
550+
.toPact()
551+
}
552+
553+
@Pact(consumer = 'consumer1')
554+
@Disabled
555+
RequestResponsePact method2(PactDslWithProvider builder) {
556+
builder
557+
.uponReceiving('interaction 2')
558+
.path('/two')
559+
.willRespondWith()
560+
.toPact()
561+
}
562+
563+
@Pact(consumer = 'consumer1')
564+
RequestResponsePact method3(PactDslWithProvider builder) {
565+
builder
566+
.uponReceiving('interaction 3')
567+
.path('/three')
568+
.willRespondWith()
569+
.toPact()
570+
}
571+
572+
@Pact(consumer = 'consumer1')
573+
RequestResponsePact method4(PactDslWithProvider builder) {
574+
builder
575+
.uponReceiving('interaction 4')
576+
.path('/')
577+
.willRespondWith()
578+
.toPact()
579+
}
580+
581+
@Pact(consumer = 'consumer1')
582+
RequestResponsePact method5(PactDslWithProvider builder) {
583+
builder
584+
.uponReceiving('interaction 5')
585+
.path('/')
586+
.willRespondWith()
587+
.toPact()
588+
}
589+
590+
@PactTestFor(pactMethod = 'method4')
591+
def testMethod1() { }
592+
593+
@PactTestFor(pactMethod = 'method5')
594+
def testMethod2() { }
595+
}
596+
597+
def 'isDisabled - is false for unannotated methods'() {
598+
given:
599+
requiredTestClass = TestSetupDisabled
600+
testMethod = TestSetupDisabled.declaredMethods.find { it.name == 'method1' }
601+
602+
expect:
603+
!testExt.isDisabled(testMethod, mockContext)
604+
}
605+
606+
def 'isDisabled - is true if the method is annotated with @Disable'() {
607+
given:
608+
requiredTestClass = TestSetupDisabled
609+
testMethod = TestSetupDisabled.declaredMethods.find { it.name == 'method2' }
610+
611+
expect:
612+
testExt.isDisabled(testMethod, mockContext)
613+
}
614+
615+
def 'isDisabled - is false if there is no associated test method'() {
616+
given:
617+
requiredTestClass = TestSetupDisabled
618+
testMethod = TestSetupDisabled.declaredMethods.find { it.name == 'method3' }
619+
620+
expect:
621+
!testExt.isDisabled(testMethod, mockContext)
622+
}
623+
624+
def 'isDisabled - is true if the associated test method was disabled'() {
625+
given:
626+
requiredTestClass = TestSetupDisabled
627+
testMethod = TestSetupDisabled.declaredMethods.find { it.name == 'method4' }
628+
testExt.disabledTestMethods << 'testMethod1'
629+
630+
expect:
631+
testExt.isDisabled(testMethod, mockContext)
632+
}
633+
634+
def 'isDisabled - is false if the associated test method was not disabled'() {
635+
given:
636+
requiredTestClass = TestSetupDisabled
637+
testMethod = TestSetupDisabled.declaredMethods.find { it.name == 'method5' }
638+
testExt.disabledTestMethods.clear()
639+
640+
expect:
641+
!testExt.isDisabled(testMethod, mockContext)
642+
}
541643
}

0 commit comments

Comments
 (0)