HappyPath<Happy, Sad> happyPathAttempt(BusinessFlow<Happy, Sad>>)

TODO: this is just a generated example

javadoc usage tests

Added in version 2.5.0

Sometimes it makes sense to attempt an action that will either produce a happy path or throw an exception.

Happy path attempt can fail

RuntimeException technicalFailure = new RuntimeException();
Attempt<HappyPath<Happy, Sad>> attempt = () -> {throw technicalFailure;};

HappyPath<Happy, Sad> happyPath = HappyPath.happyPathAttempt(attempt);

assertThat(happyPath.getTechnicalFailure()).isEqualTo(technicalFailure);

An attempt can fail and turn into a technical failure.

Happy path attempt can succeed

Happy happy = new Happy();
Attempt<HappyPath<Happy, Sad>> attempt = () -> HappyPath.happyPath(happy);

HappyPath<Happy, Sad> happyPath = HappyPath.happyPathAttempt(attempt);

assertThat(happyPath.getHappy()).isSameAs(happy);

An attempt can succeed and produce a happy path