Add Result.toString() implementations
This commit is contained in:
parent
f0be463028
commit
3496fa0972
3 changed files with 30 additions and 0 deletions
|
@ -72,4 +72,9 @@ class Err<T> implements Result<T> {
|
|||
public T orElseThrow() throws Throwable {
|
||||
throw error;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Result.Error{error=%s}", error);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -75,4 +75,9 @@ class Success<T> implements Result<T> {
|
|||
public T orElseThrow() {
|
||||
return value;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
return String.format("Result.Success{value=%s}", value);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -348,6 +348,26 @@ public class ResultTest implements WithAssertions {
|
|||
);
|
||||
}
|
||||
|
||||
@Test
|
||||
public void success_toString() {
|
||||
//given
|
||||
final Result<Integer> 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<Integer> 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 {
|
||||
|
||||
|
|
Loading…
Reference in a new issue