Interface HandlerResult<ERROR,EVENT>
- Type Parameters:
EVENT- The type of Events that can be returned byHandler.handle(Object, Object)and applied in theStateEvolver.applyEvent(Object, Object)ERROR- The type of Error that can be returned by theHandler.handle(Object, Object)method
- All Known Implementing Classes:
HandlerResult.Error,HandlerResult.Success
public sealed interface HandlerResult<ERROR,EVENT>
permits HandlerResult.Success<ERROR,EVENT>, HandlerResult.Error<ERROR,EVENT>
Captures that result of calling a
Concrete instances can either be of type
Handler.handle(Object, Object) for a specific COMMAND and aggregate STATEConcrete instances can either be of type
HandlerResult.Success or type HandlerResult.Error-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic final recordError variant of theHandlerResultstatic final recordSuccess variant of theHandlerResult -
Method Summary
Modifier and TypeMethodDescriptiondefault HandlerResult.Error<ERROR,EVENT> asError()Convert theHandlerResultto anHandlerResult.Errordefault HandlerResult.Success<ERROR,EVENT> Convert theHandlerResultto aHandlerResult.Successstatic <EVENT,ERROR>
HandlerResult.Error<ERROR,EVENT> error(ERROR error) Factory method for returning anERRORfromHandler.handle(Object, Object)static <EVENT,ERROR>
HandlerResult.Success<ERROR,EVENT> events(EVENT... events) Factory method for returning a list ofEVENT's fromHandler.handle(Object, Object)static <EVENT,ERROR>
HandlerResult.Success<ERROR,EVENT> Factory method for returning a list ofEVENT's fromHandler.handle(Object, Object)booleanisError()Did the command handling result in an error?default booleanWas the result of the command handling a success?default voidshouldFailWith(ERROR error) Test oriented method that verify that theHandlerResultisError()and theHandlerResult.Error.error()is exactly same as theerrorparameterdefault voidshouldSucceedWith(EVENT... events) Test oriented method that verify that theHandlerResultisSuccess()and theHandlerResult.Success.events()contains exactly same events as theeventsparameterdefault voidshouldSucceedWith(List<EVENT> events) Test oriented method that verify that theHandlerResultisSuccess()and theHandlerResult.Success.events()contains exactly same events as theeventsparameter
-
Method Details
-
isError
boolean isError()Did the command handling result in an error?- Returns:
- Did the command handling result in an error?
-
isSuccess
default boolean isSuccess()Was the result of the command handling a success?- Returns:
- Was the result of the command handling a success?
-
asSuccess
Convert theHandlerResultto aHandlerResult.Success- Returns:
- the
HandlerResultconverted to aHandlerResult.Success - Throws:
IllegalStateException- if theHandlerResultis anHandlerResult.Error
-
asError
Convert theHandlerResultto anHandlerResult.Error- Returns:
- the
HandlerResultconverted to anHandlerResult.Error - Throws:
IllegalStateException- if theHandlerResultis anHandlerResult.Success
-
shouldSucceedWith
Test oriented method that verify that theHandlerResultisSuccess()and theHandlerResult.Success.events()contains exactly same events as theeventsparameter- Parameters:
events- the events that we want to verify theHandlerResult.Success.events()contains- Throws:
IllegalStateException- in case the expectations aren't met
-
shouldSucceedWith
Test oriented method that verify that theHandlerResultisSuccess()and theHandlerResult.Success.events()contains exactly same events as theeventsparameter- Parameters:
events- the events that we want to verify theHandlerResult.Success.events()contains- Throws:
IllegalStateException- in case the expectations aren't met
-
shouldFailWith
Test oriented method that verify that theHandlerResultisError()and theHandlerResult.Error.error()is exactly same as theerrorparameter- Parameters:
error- the error that we want to verify is the same as theHandlerResult.Error.error()- Throws:
IllegalStateException- in case the expectations aren't met
-
error
Factory method for returning anERRORfromHandler.handle(Object, Object)- Type Parameters:
EVENT- The type of Events that can be returned byHandler.handle(Object, Object)and applied in theStateEvolver.applyEvent(Object, Object)ERROR- The type of Error that can be returned by theHandler.handle(Object, Object)method- Parameters:
error- the error to return- Returns:
- An
EitherwithEither._1containing theerror
-
events
Factory method for returning a list ofEVENT's fromHandler.handle(Object, Object)- Type Parameters:
EVENT- The type of Events that can be returned byHandler.handle(Object, Object)and applied in theStateEvolver.applyEvent(Object, Object)ERROR- The type of Error that can be returned by theHandler.handle(Object, Object)method- Parameters:
events- the events to return (is allowed to be empty)- Returns:
- An
EitherwithEither._2containing a list ofevents
-
events
Factory method for returning a list ofEVENT's fromHandler.handle(Object, Object)- Type Parameters:
EVENT- The type of Events that can be returned byHandler.handle(Object, Object)and applied in theStateEvolver.applyEvent(Object, Object)ERROR- The type of Error that can be returned by theHandler.handle(Object, Object)method- Parameters:
events- the events to return (is allowed to be empty)- Returns:
- An
EitherwithEither._2containing a list ofevents
-