GivenWhenThenScenario

Single use Given/When/Then scenario runner and asserter

Assertions exceptions thrown from then_, thenExpectNoEvent, thenFailsWithException, thenFailsWithExceptionType are all subclasses of AssertionException

Example:

val scenario = GivenWhenThenScenario(ShipOrderDecider())

var orderId = OrderId.random()
scenario
.given(
OrderCreated(orderId),
OrderAccepted(orderId)
)
.when_(ShipOrder(orderId))
.then_(OrderShipped(orderId))

And Decider example

class ShipOrderDecider : Decider<ShipOrder, OrderEvent> {
override fun handle(cmd: ShipOrder, events: List<OrderEvent>): OrderEvent? {
if (events.isEmpty()) {
throw RuntimeException("Cannot accept an order that hasn't been created")
}
if (events.any { it is OrderShipped}) {
// Already shipped - idempotent handling
return null
}
if (!events.any { it is OrderAccepted }) {
throw RuntimeException("Cannot ship an order that hasn't been accepted")
}
return OrderShipped(cmd.id)
}
}

Constructors

Link copied to clipboard
constructor(decider: Decider<CMD, EVENT>)

Properties

Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard
Link copied to clipboard

Functions

Link copied to clipboard
fun given(vararg events: EVENT): GivenWhenThenScenario<CMD, EVENT>

Set up the test scenario by providing past events that will be provided to the Decider.handle method as an event stream.

Link copied to clipboard
fun then_(expectedEvent: EVENT?): GivenWhenThenScenario<CMD, EVENT>

Define the expected event outcome when GivenWhenThenScenario is calling the Decider.handle with the command provided in when_ and past events provided in given

Link copied to clipboard
fun thenAssert(actualEventAsserter: Consumer<EVENT?>): GivenWhenThenScenario<CMD, EVENT>

Define the expected event outcome when GivenWhenThenScenario is calling the Decider.handle with the command provided in when_ and past events provided in given

Link copied to clipboard

Define that we don't expect any events outcome when GivenWhenThenScenario is calling the Decider.handle with the command provided in when_ and past events provided in given

Link copied to clipboard

Define that we expect the scenario to fail with an expectedException of a given Exception instance when the GivenWhenThenScenario is calling the Decider.handle with the command provided in when_ and past events provided in given

Link copied to clipboard

Define that we expect the scenario to fail with an expectedExceptionType of a specific Exception type when the GivenWhenThenScenario is calling the Decider.handle with the command provided in when_ and past events provided in given

Link copied to clipboard

Define the command that will be supplied to the Decider.handle as the command when one of the then methods are called