All Downloads are FREE. Search and download functionalities are using the official Maven repository.

com.lightningkite.lightningserver.notifications.TestNotificationClient.kt Maven / Gradle / Ivy

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)
    }

}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy