com.clouway.kcqrs.testing.InMemoryEventPublisher.kt Maven / Gradle / Ivy
The newest version!
package com.clouway.kcqrs.testing
import com.clouway.kcqrs.core.Event
import com.clouway.kcqrs.core.EventPublisher
import com.clouway.kcqrs.core.PublishErrorException
/**
* @author Miroslav Genov ([email protected])
*/
class InMemoryEventPublisher : EventPublisher {
var events = mutableListOf()
var nextPublishFailsWithError = false
override fun publish(events: Iterable) {
if (nextPublishFailsWithError) {
nextPublishFailsWithError = false
throw PublishErrorException()
}
this.events.addAll(events)
}
fun cleanUp() {
events = mutableListOf()
}
fun pretendThatNextPublishWillFail() {
nextPublishFailsWithError = true
}
}