@Test public void shouldReturnToStringOnFatal() { try { Try.of( () -> { throw new UnknownError(); }); fail("Exception Expected"); } catch (Try.FatalException x) { assertThat(x.toString()).isEqualTo("Fatal(java.lang.UnknownError)"); } }
@Test public void shouldReturnHashCodeOnFatal() { UnknownError error = new UnknownError(); try { Try.of( () -> { throw error; }); fail("Exception Expected"); } catch (Try.FatalException x) { assertThat(x.hashCode()).isEqualTo(Objects.hashCode(error)); } }
@Test public void shouldSubsequentlyHandOverCause() { final Supplier<?> inner = () -> { throw new UnknownError("\uD83D\uDCA9"); }; final Supplier<?> outer = () -> Try.of(inner::get).get(); try { Try.of(outer::get).get(); Assertions.fail("Exception expected"); } catch (Try.FatalException x) { Assertions.assertThat(x.getCause().getMessage()).isEqualTo("\uD83D\uDCA9"); } catch (Throwable x) { Assertions.fail("Unexpected exception type: " + x.getClass().getName()); } }
@Test public void shouldReturnEqualsOnFatal() { UnknownError error = new UnknownError(); try { Try.of( () -> { throw error; }); fail("Exception Expected"); } catch (Try.FatalException x) { try { Try.of( () -> { throw error; }); fail("Exception Expected"); } catch (Try.FatalException fatal) { assertThat(x.equals(fatal)).isEqualTo(true); } } }