use of junit.framework.AssertionFailedError in project guava by hceylan.
the class AbstractFutureTest method findStackFrame.
private static int findStackFrame(ExecutionException e, String clazz, String method) {
StackTraceElement[] elements = e.getStackTrace();
for (int i = 0; i < elements.length; i++) {
StackTraceElement element = elements[i];
if (element.getClassName().equals(clazz) && element.getMethodName().equals(method)) {
return i;
}
}
AssertionFailedError failure = new AssertionFailedError("Expected element " + clazz + "." + method + " not found in stack trace");
failure.initCause(e);
throw failure;
}
use of junit.framework.AssertionFailedError in project guava by hceylan.
the class NullPointerTesterTest method testStaticOneArgMethodsThatShouldFail.
public void testStaticOneArgMethodsThatShouldFail() throws Exception {
for (String methodName : STATIC_ONE_ARG_METHODS_SHOULD_FAIL) {
Method method = OneArg.class.getMethod(methodName, String.class);
boolean foundProblem = false;
try {
tester.testMethodParameter(OneArg.class, method, 0);
} catch (AssertionFailedError expected) {
foundProblem = true;
}
assertTrue("Should report error in method " + methodName, foundProblem);
}
}
use of junit.framework.AssertionFailedError in project android-priority-jobqueue by yigit.
the class MessageQueueTestBase method addMessageOnIdle.
private void addMessageOnIdle(final boolean delayed) throws InterruptedException {
final MockTimer timer = new MockTimer();
final MessageQueue mq = createMessageQueue(timer, new MessageFactory());
final CountDownLatch idleLatch = new CountDownLatch(1);
final CountDownLatch runLatch = new CountDownLatch(1);
final MessageQueueConsumer mqConsumer = new MessageQueueConsumer() {
@Override
public void handleMessage(Message message) {
if (message.type == Type.COMMAND && ((CommandMessage) message).getWhat() == CommandMessage.POKE) {
runLatch.countDown();
}
}
@Override
public void onIdle() {
if (idleLatch.getCount() == 1) {
CommandMessage cm = new CommandMessage();
cm.set(CommandMessage.POKE);
if (delayed) {
mq.postAt(cm, timer.nanoTime() + 100000);
} else {
mq.post(cm);
}
idleLatch.countDown();
}
}
};
Thread thread = new Thread(new Runnable() {
@Override
public void run() {
mq.consume(mqConsumer);
}
});
thread.start();
assertThat(idleLatch.await(10, TimeUnit.SECONDS), CoreMatchers.is(true));
timer.incrementMs(1000000);
assertThat(runLatch.await(10, TimeUnit.SECONDS), CoreMatchers.is(true));
mq.stop();
thread.join(5000);
if (thread.isAlive()) {
threadDump.failed(new AssertionFailedError("thread did not die"), null);
}
assertThat(thread.isAlive(), CoreMatchers.is(false));
}
use of junit.framework.AssertionFailedError in project android_frameworks_base by DirtyUnicorns.
the class InstrumentationCoreTestRunner method getAndroidTestRunner.
@Override
protected AndroidTestRunner getAndroidTestRunner() {
AndroidTestRunner runner = super.getAndroidTestRunner();
runner.addTestListener(new TestListener() {
/**
* The last test class we executed code from.
*/
private Class<?> lastClass;
/**
* The minimum time we expect a test to take.
*/
private static final int MINIMUM_TIME = 100;
/**
* The start time of our current test in System.currentTimeMillis().
*/
private long startTime;
public void startTest(Test test) {
if (test.getClass() != lastClass) {
lastClass = test.getClass();
printMemory(test.getClass());
}
Thread.currentThread().setContextClassLoader(test.getClass().getClassLoader());
startTime = System.currentTimeMillis();
}
public void endTest(Test test) {
if (test instanceof TestCase) {
cleanup((TestCase) test);
/*
* Make sure all tests take at least MINIMUM_TIME to
* complete. If they don't, we wait a bit. The Cupcake
* Binder can't handle too many operations in a very
* short time, which causes headache for the CTS.
*/
long timeTaken = System.currentTimeMillis() - startTime;
if (timeTaken < MINIMUM_TIME) {
try {
Thread.sleep(MINIMUM_TIME - timeTaken);
} catch (InterruptedException ignored) {
// We don't care.
}
}
}
}
public void addError(Test test, Throwable t) {
// This space intentionally left blank.
}
public void addFailure(Test test, AssertionFailedError t) {
// This space intentionally left blank.
}
/**
* Dumps some memory info.
*/
private void printMemory(Class<? extends Test> testClass) {
Runtime runtime = Runtime.getRuntime();
long total = runtime.totalMemory();
long free = runtime.freeMemory();
long used = total - free;
Log.d(TAG, "Total memory : " + total);
Log.d(TAG, "Used memory : " + used);
Log.d(TAG, "Free memory : " + free);
Log.d(TAG, "Now executing : " + testClass.getName());
}
/**
* Nulls all non-static reference fields in the given test class.
* This method helps us with those test classes that don't have an
* explicit tearDown() method. Normally the garbage collector should
* take care of everything, but since JUnit keeps references to all
* test cases, a little help might be a good idea.
*/
private void cleanup(TestCase test) {
Class<?> clazz = test.getClass();
while (clazz != TestCase.class) {
Field[] fields = clazz.getDeclaredFields();
for (int i = 0; i < fields.length; i++) {
Field f = fields[i];
if (!f.getType().isPrimitive() && !Modifier.isStatic(f.getModifiers())) {
try {
f.setAccessible(true);
f.set(test, null);
} catch (Exception ignored) {
// Nothing we can do about it.
}
}
}
clazz = clazz.getSuperclass();
}
}
});
return runner;
}
use of junit.framework.AssertionFailedError in project android_frameworks_base by DirtyUnicorns.
the class TextViewAssertions method hasInsertionPointerAtIndex.
/**
* Returns a {@link ViewAssertion} that asserts that the text view insertion pointer is at
* a specified index.<br>
* <br>
* View constraints:
* <ul>
* <li>must be a text view displayed on screen
* <ul>
*
* @param index A matcher representing the expected index.
*/
public static ViewAssertion hasInsertionPointerAtIndex(final Matcher<Integer> index) {
return new ViewAssertion() {
@Override
public void check(View view, NoMatchingViewException exception) {
if (view instanceof TextView) {
TextView textView = (TextView) view;
int selectionStart = textView.getSelectionStart();
int selectionEnd = textView.getSelectionEnd();
try {
assertThat(selectionStart, index);
assertThat(selectionEnd, index);
} catch (IndexOutOfBoundsException e) {
throw new AssertionFailedError(e.getMessage());
}
} else {
throw new AssertionFailedError("TextView not found");
}
}
};
}
Aggregations