@Test(expected = NullPointerException.class)
 public void testInvokingTimerWithNullMethodName() throws Throwable {
   try {
     helper.invokeTimerFor(TestAggregator.class, null);
   } catch (RuntimeException e) {
     assertThat(e.getClass().getName(), is(RuntimeException.class.getName()));
     throw e.getCause();
   }
 }
 @Test(expected = NullPointerException.class)
 public void testInvokingNotExistentTimer() throws Throwable {
   try {
     helper.invokeTimerFor(TestAggregator.class, "blkjhsdgfksdyufgks");
   } catch (RuntimeException e) {
     assertThat(e.getClass().getName(), is(RuntimeException.class.getName()));
     throw e.getCause();
   }
 }
Example #3
0
 /**
  * Returns the unique result from the database that exactly matches <code>example</code>. This
  * method is same as {@link #uniqueResult(Object)} but calls {@link #getUniqueEscape(Object)}
  * instead of {@link #getUnique(Object)}
  *
  * @param example
  * @return
  * @throws TransactionException
  */
 @SuppressWarnings("unchecked")
 public <T> T uniqueResultEscape(final T example) throws TransactionException {
   try {
     return this.recast((Class<T>) example.getClass()).getUniqueEscape(example);
   } catch (final RuntimeException ex) {
     throw new TransactionInternalException(ex.getMessage(), ex);
   } catch (final EucalyptusCloudException ex) {
     throw new TransactionExecutionException(ex.getMessage(), ex);
   }
 }
Example #4
0
  @Test
  public void getAThrowingSupplierUnchecked() {
    assertThat(getUnchecked(() -> 42), is(42));

    Exception e = new Exception();
    try {
      getUnchecked(
          () -> {
            throw e;
          });
    } catch (RuntimeException ex) {
      assertThat(ex.getCause(), sameInstance(e));
      return;
    }
    fail("Should throw exception");
  }
Example #5
0
  @Test
  public void applyAThrowingFunctionUnchecked() {
    assertThat(applyUnchecked(Math::round, 4.6f), is(5));
    assertThat(applyUnchecked(n -> n, null), nullValue());
    assertThat(applyUnchecked(n -> n, Optional.empty()), is(Optional.empty()));

    Exception e = new Exception();
    try {
      applyUnchecked(
          t -> {
            throw e;
          },
          "anything");
    } catch (RuntimeException ex) {
      assertThat(ex.getCause(), sameInstance(e));
      return;
    }
    fail("Should throw exception");
  }
Example #6
0
  @Test
  public void runAThrowingRunnableUnchecked() {
    OneTimeToggle toggled = new OneTimeToggle();
    DiggExceptions.runUnchecked(
        () ->
            toggled.nowOrIfAlreadyThenThrow(() -> new AssertionError("should not be run twice!")));
    assertTrue(toggled.yet());

    Exception e = new Exception();
    try {
      runUnchecked(
          () -> {
            throw e;
          });
    } catch (RuntimeException ex) {
      assertThat(ex.getCause(), sameInstance(e));
      return;
    }
    fail("Should throw exception");
  }