diff --git a/src/main/java/net/kemitix/mon/result/Err.java b/src/main/java/net/kemitix/mon/result/Err.java index b8666a4..0e76126 100644 --- a/src/main/java/net/kemitix/mon/result/Err.java +++ b/src/main/java/net/kemitix/mon/result/Err.java @@ -72,4 +72,9 @@ class Err implements Result { public T orElseThrow() throws Throwable { throw error; } + + @Override + public String toString() { + return String.format("Result.Error{error=%s}", error); + } } diff --git a/src/main/java/net/kemitix/mon/result/Success.java b/src/main/java/net/kemitix/mon/result/Success.java index f10c25d..830b41e 100644 --- a/src/main/java/net/kemitix/mon/result/Success.java +++ b/src/main/java/net/kemitix/mon/result/Success.java @@ -75,4 +75,9 @@ class Success implements Result { public T orElseThrow() { return value; } + + @Override + public String toString() { + return String.format("Result.Success{value=%s}", value); + } } diff --git a/src/test/java/net/kemitix/mon/ResultTest.java b/src/test/java/net/kemitix/mon/ResultTest.java index 7c25651..75ab5d1 100644 --- a/src/test/java/net/kemitix/mon/ResultTest.java +++ b/src/test/java/net/kemitix/mon/ResultTest.java @@ -348,6 +348,26 @@ public class ResultTest implements WithAssertions { ); } + @Test + public void success_toString() { + //given + final Result ok = Result.ok(1); + //when + final String toString = ok.toString(); + //then + assertThat(toString).contains("Result.Success{value=1}"); + } + + @Test + public void err_toString() { + //given + final Result error = Result.error(new RuntimeException("failed")); + //when + final String toString = error.toString(); + //then + assertThat(toString).contains("Result.Error{error=java.lang.RuntimeException: failed}"); + } + @RequiredArgsConstructor private static class UseCase {