Skip to content

Instantly share code, notes, and snippets.



Last active Jun 10, 2018
What would you like to do?
class RestSpec extends WordSpec with Matchers with ScalatestRouteTest with MockitoSugar {
val mockUserImpl = mock[UserImpl]
object TestObject extends RestService {
val userImpl = mockUserImpl
"The service" should {
"return user added as response for a Post request to /adduser" in {
when(mockUserImpl.addUser(User(2, "test"))).thenReturn(Future.successful(Done))
val jsonRequest = ByteString(
| "id":2,
| "name":"test"
val postRequest = HttpRequest(
uri = "/adduser",
entity = HttpEntity(MediaTypes.`application/json`, jsonRequest))
postRequest ~> Route.seal(TestObject.route) ~> check {
status.isSuccess() shouldEqual true
responseAs[String] shouldEqual "user added"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment