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));
}
}
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);
}
}
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)));
}
}
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)));
}
}
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;
}
Aggregations