@@ -51,7 +51,7 @@ public class FailingExampleTest {
5151
5252 @ Test
5353 public void failingTrigger () {
54- // failure in runInteraction trigger should return configuration error
54+ // exception in runInteraction trigger should return configuration error
5555 assertThatThrownBy (() -> {
5656 contract .runInteraction (
5757 new InteractionDefinition <>(
@@ -83,8 +83,8 @@ public void failingTrigger() {
8383 }
8484 );
8585 ;
86- // Failure in throwing interaction trigger should fail with verify error, as the
87- // trigger's failure is passed to it
86+ // exception in throwing interaction trigger should fail with verify error, as the
87+ // trigger's failure is passed to the verify method, which should fail the assertion.
8888 assertThatThrownBy (() -> {
8989 contract .runThrowingInteraction (
9090 new InteractionDefinition <>(
@@ -115,6 +115,39 @@ public void failingTrigger() {
115115 }
116116 );
117117
118+ // Assertion error in failure trigger should fail the test with configuration error
119+ assertThatThrownBy (() -> {
120+ contract .runThrowingInteraction (
121+ new InteractionDefinition <>(
122+ List .of (new InState ("Server is broken" )),
123+ new WillSendHttpRequest (HttpExample .builder ()
124+
125+ .request (new NamedMatch (
126+ "Get health" ,
127+ new HttpRequest (HttpRequestExample .builder ()
128+ .path ("/health" )
129+ .method ("GET" )
130+ .build ())
131+ ))
132+ .response (new HttpResponse (HttpResponseExample .builder ().status (503 ).build ()))
133+ .build ())
134+ ),
135+ IndividualFailedTestConfigBuilder .<String >builder ()
136+ .withProviderName ("Java Example HTTP Server" )
137+ .withTrigger ((interactionSetup ) -> {
138+ throw new AssertionError ("This is meant to fail" );
139+ })
140+ .withTestErrorResponse ((exception , setupInfo ) -> {
141+ assertThat (exception .getMessage ()).isEqualTo ("The server is not ready" );
142+ })
143+ );
144+ }).isInstanceOf (ContractCaseConfigurationError .class )
145+ .satisfies ((e ) -> {
146+ assertThat (((HasUserFacingStackTrace ) e ).userFacingStackTrace ())
147+ .contains ("FailingExampleTest.java" );
148+ }
149+ );
150+
118151 assertThatThrownBy (() -> {
119152 contract .runInteraction (
120153 new InteractionDefinition <>(
@@ -148,6 +181,43 @@ public void failingTrigger() {
148181 }
149182 );
150183
184+ // Assertion error in success trigger should fail with configuration error
185+ assertThatThrownBy (() -> {
186+ contract .runInteraction (
187+ new InteractionDefinition <>(
188+ List .of (new InState ("Server is up" )),
189+ new WillSendHttpRequest (HttpExample .builder ()
190+
191+ .request (new NamedMatch (
192+ "Get health" ,
193+ new HttpRequest (HttpRequestExample .builder ()
194+ .path ("/health" )
195+ .method ("GET" )
196+ .build ())
197+ ))
198+ .response (new HttpResponse (HttpResponseExample .builder ()
199+ .status (200 )
200+ .body (Map .ofEntries (Map .entry ("status" , "up" )))
201+ .build ()))
202+ .build ())
203+ ),
204+ IndividualSuccessTestConfigBuilder .<String >builder ()
205+ .withProviderName ("Java Example HTTP Server" )
206+ .withTrigger ((interactionSetup ) -> {
207+ throw new AssertionError ("This is meant to fail" );
208+ })
209+ .withTestResponse ((data , setupInfo ) -> {
210+ assertThat (data ).isEqualTo ("It doesn't equal this" );
211+ })
212+ );
213+ }).isInstanceOf (ContractCaseConfigurationError .class )
214+ .satisfies ((e ) -> {
215+ assertThat (((HasUserFacingStackTrace ) e ).userFacingStackTrace ())
216+ .contains ("FailingExampleTest.java" );
217+ }
218+ );
219+
220+
151221 // Recording contract should throw an error
152222 assertThatThrownBy (contract ::endRecord ).
153223
0 commit comments