예제 #1
0
 @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)");
   }
 }
예제 #2
0
 @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));
   }
 }
예제 #3
0
 @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());
   }
 }
예제 #4
0
 @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);
     }
   }
 }