HappyPath<NewHappy, Sad> map(Mapping<Happy, NewHappy>)

TODO: this is just a generated example

javadoc usage tests

Added in version 1.0.0

If the underlying case is happy then the mapping is applied

Happy happy = new Happy("name");
HappyPath<Happy, Sad> happyPath = HappyPath.happyPath(happy);

HappyPath<String, Sad> mapped = happyPath.map(Happy::toString);

assertThat(mapped.getHappy()).isEqualTo("name");

Exceptions thrown during mapping are turned into technical failures

Exception uncaught = new Exception("boom");
Mapping<Happy, String> mapping =  happy -> {throw uncaught;};
HappyPath<Happy, Sad> happyPath = HappyPath.happyPath(new Happy());

HappyPath<String, Sad> mapped = happyPath.map(mapping);

assertThat(mapped.getTechnicalFailure()).isEqualTo(uncaught);

If the underlying case is sad then the mapping is not applied

Sad sad = new Sad();
HappyPath<Happy, Sad> happyPath = HappyPath.sadPath(sad);

HappyPath<String, Sad> mapped = happyPath.map(Happy::toString);

assertThat(mapped.getSad()).isEqualTo(sad);

If the underlying case is a technical failure then the mapping is not applied

Exception technicalFailure = new Exception();
HappyPath<Happy, Sad> happyPath = HappyPath.technicalFailure(technicalFailure);

HappyPath<String, Sad> mapped = happyPath.map(Happy::toString);

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