@@ -10,6 +10,7 @@ import au.com.dius.pact.provider.junit.loader.PactUrl
10
10
import au.com.dius.pact.provider.junit.loader.PactUrlLoader
11
11
import au.com.dius.pact.provider.junit.target.Target
12
12
import au.com.dius.pact.provider.junit.target.TestTarget
13
+ import org.junit.runner.notification.RunNotifier
13
14
import org.junit.runners.model.InitializationError
14
15
import spock.lang.Specification
15
16
@@ -115,7 +116,7 @@ class PactRunnerSpec extends Specification {
115
116
116
117
def ' PactRunner throws an exception if there is no @Provider annotation on the test class' () {
117
118
when :
118
- new PactRunner (PactRunnerSpec )
119
+ new PactRunner (PactRunnerSpec ). run( new RunNotifier ())
119
120
120
121
then :
121
122
InitializationError e = thrown()
@@ -125,7 +126,7 @@ class PactRunnerSpec extends Specification {
125
126
126
127
def ' PactRunner throws an exception if there is no pact source' () {
127
128
when :
128
- new PactRunner (NoSourceTestClass )
129
+ new PactRunner (NoSourceTestClass ). run( new RunNotifier ())
129
130
130
131
then :
131
132
InitializationError e = thrown()
@@ -134,7 +135,7 @@ class PactRunnerSpec extends Specification {
134
135
135
136
def ' PactRunner throws an exception if the pact source throws an IO exception' () {
136
137
when :
137
- new PactRunner (FailsTestClass )
138
+ new PactRunner (FailsTestClass ). run( new RunNotifier ())
138
139
139
140
then :
140
141
InitializationError e = thrown()
@@ -143,13 +144,26 @@ class PactRunnerSpec extends Specification {
143
144
144
145
def ' PactRunner throws an exception if there are no pacts to verify' () {
145
146
when :
146
- new PactRunner (NoPactsTestClass )
147
+ new PactRunner (NoPactsTestClass ). run( new RunNotifier ())
147
148
148
149
then :
149
150
InitializationError e = thrown()
150
151
e. causes* . message == [' Did not find any pact files for provider Bob' ]
151
152
}
152
153
154
+ def 'PactRunner only initializes once if run () is called multiple times' () {
155
+ when:
156
+ def runner = new PactRunner(TestClass)
157
+ runner.run(new RunNotifier())
158
+ def children1 = runner.children.clone()
159
+
160
+ runner.run(new RunNotifier())
161
+ def children2 = runner.children.clone()
162
+
163
+ then:
164
+ children1 == children2
165
+ }
166
+
153
167
def ' PactRunner does not throw an exception if there are no pacts to verify and @IgnoreNoPactsToVerify' () {
154
168
when :
155
169
new PactRunner (NoPactsIgnoredTestClass )
@@ -169,7 +183,7 @@ class PactRunnerSpec extends Specification {
169
183
170
184
def ' PactRunner throws an exception if there is both a pact source and pact loader annotation' () {
171
185
when :
172
- new PactRunner (BothPactSourceAndPactLoaderTestClass )
186
+ new PactRunner (BothPactSourceAndPactLoaderTestClass ). run( new RunNotifier ())
173
187
174
188
then :
175
189
InitializationError e = thrown()
@@ -179,6 +193,7 @@ class PactRunnerSpec extends Specification {
179
193
def ' PactRunner handles a pact source with a pact loader that takes a class parameter' () {
180
194
when :
181
195
def runner = new PactRunner (PactLoaderWithConstructorParameterTestClass )
196
+ runner. run(new RunNotifier ())
182
197
183
198
then :
184
199
! runner. children. empty
@@ -187,6 +202,7 @@ class PactRunnerSpec extends Specification {
187
202
def ' PactRunner handles a pact source with a pact loader that does not takes a class parameter' () {
188
203
when :
189
204
def runner = new PactRunner (PactLoaderWithDefaultConstructorClass )
205
+ runner. run(new RunNotifier ())
190
206
191
207
then :
192
208
! runner. children. empty
@@ -195,6 +211,7 @@ class PactRunnerSpec extends Specification {
195
211
def ' PactRunner loads the pact loader class from the pact loader associated with the pact loader annotation' () {
196
212
when :
197
213
def runner = new PactRunner (TestClass )
214
+ runner. run(new RunNotifier ())
198
215
199
216
then :
200
217
! runner. children. empty
0 commit comments