コード例 #1
0
 @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();
   }
 }
コード例 #2
0
 @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();
   }
 }
コード例 #3
0
ファイル: EntityWrapper.java プロジェクト: sjones4/eucalyptus
 /**
  * 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);
   }
 }
コード例 #4
0
ファイル: DiggExceptionsTest.java プロジェクト: digipost/digg
  @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");
  }
コード例 #5
0
ファイル: DiggExceptionsTest.java プロジェクト: digipost/digg
  @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");
  }
コード例 #6
0
ファイル: DiggExceptionsTest.java プロジェクト: digipost/digg
  @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");
  }