TODO: this is just a generated example
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.
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 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