Search in sources :

Example 41 with AssertionFailedError

use of junit.framework.AssertionFailedError in project guava by hceylan.

the class FuturesTest method pseudoTimedGet.

/**
   * Very rough equivalent of a timed get, produced by calling the no-arg get
   * method in another thread and waiting a short time for it.
   *
   * <p>We need this to test the behavior of no-arg get methods without hanging
   * the main test thread forever in the case of failure.
   */
private static <V> V pseudoTimedGet(final Future<V> input, long timeout, TimeUnit unit) throws InterruptedException, ExecutionException, TimeoutException {
    ExecutorService executor = newSingleThreadExecutor();
    Future<V> waiter = executor.submit(new Callable<V>() {

        @Override
        public V call() throws Exception {
            return input.get();
        }
    });
    try {
        return waiter.get(timeout, unit);
    } catch (ExecutionException e) {
        propagateIfInstanceOf(e.getCause(), ExecutionException.class);
        propagateIfInstanceOf(e.getCause(), CancellationException.class);
        AssertionFailedError error = new AssertionFailedError("Unexpected exception");
        error.initCause(e);
        throw error;
    } finally {
        executor.shutdownNow();
        assertTrue(executor.awaitTermination(10, SECONDS));
    }
}
Also used : CancellationException(java.util.concurrent.CancellationException) ExecutorService(java.util.concurrent.ExecutorService) ExecutionException(java.util.concurrent.ExecutionException) AssertionFailedError(junit.framework.AssertionFailedError) TimeoutException(java.util.concurrent.TimeoutException) CancellationException(java.util.concurrent.CancellationException) IOException(java.io.IOException) ExecutionException(java.util.concurrent.ExecutionException)

Example 42 with AssertionFailedError

use of junit.framework.AssertionFailedError in project guava by hceylan.

the class NullPointerTester method testFunctorParameter.

/**
   * Verifies that {@code func} produces a {@link NullPointerException} or
   * {@link UnsupportedOperationException} when the parameter in position {@code
   * paramIndex} is null.  If this parameter is marked {@link Nullable}, this
   * method does nothing.
   *
   * @param instance the instance to invoke {@code func} on, or null if
   *     {@code func} is static
   */
private void testFunctorParameter(Object instance, Functor func, int paramIndex, Class<?> testedClass) {
    if (parameterIsPrimitiveOrNullable(func, paramIndex)) {
        // there's nothing to test
        return;
    }
    Object[] params = buildParamList(func, paramIndex);
    try {
        func.invoke(instance, params);
        Assert.fail("No exception thrown from " + func + Arrays.toString(params) + " for " + testedClass);
    } catch (InvocationTargetException e) {
        Throwable cause = e.getCause();
        if (cause instanceof NullPointerException || cause instanceof UnsupportedOperationException) {
            return;
        }
        AssertionFailedError error = new AssertionFailedError("wrong exception thrown from " + func + ": " + cause);
        error.initCause(cause);
        throw error;
    } catch (IllegalAccessException e) {
        throw new RuntimeException(e);
    } catch (InstantiationException e) {
        throw new RuntimeException(e);
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) InvocationTargetException(java.lang.reflect.InvocationTargetException)

Example 43 with AssertionFailedError

use of junit.framework.AssertionFailedError in project guava by hceylan.

the class RelationshipTester method assertUnrelated.

private void assertUnrelated(int groupNumber, int itemNumber, int unrelatedGroupNumber, int unrelatedItemNumber) {
    T item = groups.get(groupNumber).get(itemNumber);
    T unrelated = groups.get(unrelatedGroupNumber).get(unrelatedItemNumber);
    try {
        assertion.assertUnrelated(item, unrelated);
    } catch (AssertionFailedError e) {
        // TODO(gak): special handling for ComparisonFailure?
        throw new AssertionFailedError(e.getMessage().replace("$ITEM", itemString(item, groupNumber, itemNumber)).replace("$UNRELATED", itemString(unrelated, unrelatedGroupNumber, unrelatedItemNumber)));
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError)

Example 44 with AssertionFailedError

use of junit.framework.AssertionFailedError in project guava by hceylan.

the class RelationshipTester method assertRelated.

private void assertRelated(int groupNumber, int itemNumber, int relatedItemNumber) {
    ImmutableList<T> group = groups.get(groupNumber);
    T item = group.get(itemNumber);
    T related = group.get(relatedItemNumber);
    try {
        assertion.assertRelated(item, related);
    } catch (AssertionFailedError e) {
        // TODO(gak): special handling for ComparisonFailure?
        throw new AssertionFailedError(e.getMessage().replace("$ITEM", itemString(item, groupNumber, itemNumber)).replace("$RELATED", itemString(related, groupNumber, relatedItemNumber)));
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError)

Example 45 with AssertionFailedError

use of junit.framework.AssertionFailedError in project guava by hceylan.

the class Helpers method fail.

static void fail(Throwable cause, Object message) {
    AssertionFailedError assertionFailedError = new AssertionFailedError(String.valueOf(message));
    assertionFailedError.initCause(cause);
    throw assertionFailedError;
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError)

Aggregations

AssertionFailedError (junit.framework.AssertionFailedError)787 TestFailureException (org.apache.openejb.test.TestFailureException)503 JMSException (javax.jms.JMSException)336 EJBException (javax.ejb.EJBException)334 RemoteException (java.rmi.RemoteException)268 InitialContext (javax.naming.InitialContext)168 RemoveException (javax.ejb.RemoveException)80 CreateException (javax.ejb.CreateException)77 NamingException (javax.naming.NamingException)65 BasicStatefulObject (org.apache.openejb.test.stateful.BasicStatefulObject)42 Test (org.junit.Test)42 BasicBmpObject (org.apache.openejb.test.entity.bmp.BasicBmpObject)41 BasicStatelessObject (org.apache.openejb.test.stateless.BasicStatelessObject)38 CountDownLatch (java.util.concurrent.CountDownLatch)28 EntityManager (javax.persistence.EntityManager)21 HSSFWorkbook (org.apache.poi.hssf.usermodel.HSSFWorkbook)21 EntityManagerFactory (javax.persistence.EntityManagerFactory)17 IOException (java.io.IOException)16 DataSource (javax.sql.DataSource)16 ConnectionFactory (javax.jms.ConnectionFactory)15