Search in sources :

Example 46 with AssertionFailedError

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;
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError)

Example 47 with AssertionFailedError

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);
    }
}
Also used : Method(java.lang.reflect.Method) AssertionFailedError(junit.framework.AssertionFailedError)

Example 48 with AssertionFailedError

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));
}
Also used : MockTimer(com.birbit.android.jobqueue.test.timer.MockTimer) CommandMessage(com.birbit.android.jobqueue.messaging.message.CommandMessage) CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) CommandMessage(com.birbit.android.jobqueue.messaging.message.CommandMessage)

Example 49 with AssertionFailedError

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;
}
Also used : Field(java.lang.reflect.Field) Test(junit.framework.Test) TestCase(junit.framework.TestCase) TestListener(junit.framework.TestListener) AssertionFailedError(junit.framework.AssertionFailedError)

Example 50 with AssertionFailedError

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");
            }
        }
    };
}
Also used : ViewAssertion(android.support.test.espresso.ViewAssertion) NoMatchingViewException(android.support.test.espresso.NoMatchingViewException) TextView(android.widget.TextView) AssertionFailedError(junit.framework.AssertionFailedError) TextView(android.widget.TextView) View(android.view.View)

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