com.lightningkite.lightningserver.notifications.TestNotificationClient.kt Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of server-core Show documentation
Show all versions of server-core Show documentation
A set of tools to fill in/replace what Ktor is lacking in.
The newest version!
package com.lightningkite.lightningserver.notifications
/**
* The concrete implementation of NotificationClient that will is similar to ConsoleNotificationClient but with more options
* You can turn off the console printing
* It stores the last message sent
* You can set a lambda for getting send events
* This is useful for Unit Tests
*/
object TestNotificationClient : NotificationClient {
data class Message(val targets: List, val data: NotificationData)
var printToConsole: Boolean = false
var lastMessageSent: Message? = null
private set
var onMesasgeSent: ((Message)->Unit)? = null
override suspend fun send(
targets: List,
data: NotificationData
) {
val m = Message(targets, data)
lastMessageSent = m
onMesasgeSent?.invoke(m)
if(printToConsole)
ConsoleNotificationClient.send(targets, data)
}
}