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 interface HandlerResult<ERROR,EVENT>Captures that result of calling aHandler.handle(Object, Object)for a specificCOMMANDand aggregateSTATE
Concrete instances can either be of typeHandlerResult.Successor typeHandlerResult.Error
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static classHandlerResult.Error<ERROR,EVENT>Error variant of theHandlerResultstatic classHandlerResult.Success<ERROR,EVENT>Success variant of theHandlerResult
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Default Methods Modifier and Type Method Description default HandlerResult.Error<ERROR,EVENT>asError()Convert theHandlerResultto anHandlerResult.Errordefault HandlerResult.Success<ERROR,EVENT>asSuccess()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>events(List<EVENT> events)Factory method for returning a list ofEVENT's fromHandler.handle(Object, Object)booleanisError()Did the command handling result in an error?default booleanisSuccess()Was 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 Detail
-
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
default HandlerResult.Success<ERROR,EVENT> asSuccess()
Convert theHandlerResultto aHandlerResult.Success- Returns:
- the
HandlerResultconverted to aHandlerResult.Success - Throws:
IllegalStateException- if theHandlerResultis anHandlerResult.Error
-
asError
default HandlerResult.Error<ERROR,EVENT> asError()
Convert theHandlerResultto anHandlerResult.Error- Returns:
- the
HandlerResultconverted to anHandlerResult.Error - Throws:
IllegalStateException- if theHandlerResultis anHandlerResult.Success
-
shouldSucceedWith
default void shouldSucceedWith(EVENT... events)
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
default void shouldSucceedWith(List<EVENT> events)
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
default void shouldFailWith(ERROR error)
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
static <EVENT,ERROR> HandlerResult.Error<ERROR,EVENT> error(ERROR 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
static <EVENT,ERROR> HandlerResult.Success<ERROR,EVENT> events(EVENT... 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
static <EVENT,ERROR> HandlerResult.Success<ERROR,EVENT> events(List<EVENT> 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
-
-