From 966aad20f469b2eff222db8b86206b140a3833a9 Mon Sep 17 00:00:00 2001 From: Glavo Date: Tue, 11 Jun 2024 23:44:35 +0800 Subject: [PATCH] Update TryTest --- src/test/java/kala/control/TryTest.java | 33 ++++++++++++++++++++++++- 1 file changed, 32 insertions(+), 1 deletion(-) diff --git a/src/test/java/kala/control/TryTest.java b/src/test/java/kala/control/TryTest.java index 3c26b0fd..3827c78a 100644 --- a/src/test/java/kala/control/TryTest.java +++ b/src/test/java/kala/control/TryTest.java @@ -1,3 +1,18 @@ +/* + * Copyright 2024 Glavo + * + * Licensed under the Apache License, Version 2.0 (the "License"); + * you may not use this file except in compliance with the License. + * You may obtain a copy of the License at + * + * http://www.apache.org/licenses/LICENSE-2.0 + * + * Unless required by applicable law or agreed to in writing, software + * distributed under the License is distributed on an "AS IS" BASIS, + * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. + * See the License for the specific language governing permissions and + * limitations under the License. + */ package kala.control; import kala.SerializationUtils; @@ -10,7 +25,6 @@ import static org.junit.jupiter.api.Assertions.*; -@SuppressWarnings("ResultOfMethodCallIgnored") public class TryTest { @Test @@ -253,6 +267,22 @@ public void rethrowTest() { assertThrows(OutOfMemoryError.class, () -> Try.failure(new OutOfMemoryError()).rethrowFatal()); } + @Test + public void toEitherTest() { + MyException ex = new MyException(); + + assertEquals(Either.right("foo"), Try.success("foo").toEither()); + assertEquals(Either.left(ex), Try.failure(ex).toEither()); + } + + @Test + public void toResultTest() { + MyException ex = new MyException(); + + assertEquals(Result.ok("foo"), Try.success("foo").toResult()); + assertEquals(Result.err(ex), Try.failure(ex).toResult()); + } + @Test public void mapTest() { MyException ex = new MyException(); @@ -309,6 +339,7 @@ public void forEachTest() { @Test public void serializationTest() throws IOException, ClassNotFoundException { assertEquals(Try.success("foo"), SerializationUtils.writeAndRead(Try.success("foo"))); + assertInstanceOf(MyException.class, SerializationUtils.writeAndRead(Try.failure(new MyException())).getCause()); } private static final class MyException extends RuntimeException {