Skip to content

Commit efab826

Browse files
committed
Fix test case
1 parent 71ac62d commit efab826

File tree

2 files changed

+14
-24
lines changed

2 files changed

+14
-24
lines changed

modules/scala-extensions/src/main/scala/io/restassured/module/scala/extensions/RestAssuredScalaExtensions.scala

Lines changed: 5 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,8 @@ package io.restassured.module.scala.extensions
33
import scala.util.chaining.*
44
import scala.reflect.ClassTag
55
import io.restassured.RestAssured.`given`
6-
import io.restassured.RestAssured.`when`
76
import io.restassured.response.{ExtractableResponse, Response, ValidatableResponse}
8-
import io.restassured.specification.{RequestSender, RequestSpecification}
7+
import io.restassured.specification.RequestSpecification
98
import io.restassured.internal.{ValidatableResponseImpl, ResponseSpecificationImpl}
109

1110
// Main wrappers
@@ -75,25 +74,6 @@ extension (spec: RequestSpecification)
7574
infix def When(block: RequestSpecification => Response): Response =
7675
spec.`when`().pipe(block)
7776

78-
/**
79-
* A wrapper around [io.restassured.RestAssured.when] to start building the DSL
80-
* expression by sending a request without any parameters or headers etc. E.g.
81-
* {{{
82-
* Given()
83-
* .When(_.get("/x"))
84-
* .Then(_.body("x.y.z1", equalTo("Z1")))
85-
* }}}
86-
* Note that if you need to add parameters, headers, cookies or other request
87-
* properties use the [[Given()]] method.
88-
*
89-
* @see
90-
* io.restassured.RestAssured.when
91-
* @return
92-
* A request sender interface that let's you call resources on the server
93-
*/
94-
def When(block: RequestSender => Response): Response =
95-
`when`().pipe(block)
96-
9777
/**
9878
* A wrapper around [then] that lets you validate the response. Usage example:
9979
* {{{
@@ -170,4 +150,7 @@ extension [T](resp: ValidatableResponse)
170150
// End main wrappers
171151

172152
private def doIfValidatableResponseImpl(fn: ResponseSpecificationImpl => Unit): ValidatableResponse => Unit =
173-
resp => if resp.isInstanceOf[ValidatableResponseImpl] then fn(resp.asInstanceOf[ValidatableResponseImpl].responseSpec)
153+
resp =>
154+
resp match
155+
case resp: ValidatableResponseImpl => fn(resp.responseSpec)
156+
case _ => ()

modules/scala-extensions/src/test/scala/io/restassured/module/scala/extensions/RestAssuredScalaExtensionsTest.scala

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,6 @@ import io.restassured.builder.ResponseBuilder
2121
import io.restassured.filter.Filter
2222
import io.restassured.http.ContentType.JSON
2323
import org.assertj.core.api.Assertions.assertThat
24-
import org.assertj.core.api.Assertions.catchThrowable
2524
import org.hamcrest.Matchers.*
2625
import org.junit.Before
2726
import org.junit.Test
@@ -141,7 +140,15 @@ class RestAssuredScalaExtensionsTest:
141140
)
142141
} catch {
143142
case e: AssertionError =>
144-
assertThat(e).hasMessage("""1 expectation failed.
143+
assertThat(e).hasMessage("""3 expectations failed.
145144
|Expected status code <400> but was <200>.
145+
|
146+
|JSON path message doesn't match.
147+
|Expected: Another World
148+
| Actual: Hello World
149+
|
150+
|JSON path message doesn't match.
151+
|Expected: Brave new world
152+
| Actual: Hello World
146153
|""".stripMargin)
147154
}

0 commit comments

Comments
 (0)