Skip to content

Instantly share code, notes, and snippets.

@iboss-ptk
Created July 8, 2018 06:13
Show Gist options
  • Select an option

  • Save iboss-ptk/e60e16845d4eb8d8c03340ed2bfae7e7 to your computer and use it in GitHub Desktop.

Select an option

Save iboss-ptk/e60e16845d4eb8d8c03340ed2bfae7e7 to your computer and use it in GitHub Desktop.
class NotificationServiceTest : Spek({
describe(".notify") {
context("when message creation fails") {
// constants
val messagingServiceId = "message-service-id"
val errorCode = 9
val errorMessage = "error message"
val restClient = mock<TwilioRestClient>()
val secretRepository = mock<SecretRepository> {
on { getTwilloMessagingServiceId() } doReturn messagingServiceId
}
val notificationService = NotificationService(restClient, secretRepository)
val notificationRequest = NotificationRequest("+66", "839992233", "text")
// Assign a lambda to val directly
val creator: MessageCreatorFactory = { _, _, _ ->
mock {
on { create(restClient) } doReturn Message.fromJson(
"""
{
"error_code": $errorCode,
"error_message": "$errorMessage",
"status": "failed"
}
""".trimIndent(), jacksonObjectMapper())
}
}
// `::` is not needed anymore
val result = notificationService.notify(notificationRequest, creator)
it("returns `NotificationFailed` with error code and error message") {
assertThat(result).isEqualTo(NotificationFailed(errorCode, errorMessage))
}
}
}
})
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment