Exemple #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)");
   }
 }
Exemple #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));
   }
 }
Exemple #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());
   }
 }
Exemple #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);
     }
   }
 }