Search in sources :

Example 16 with AssertionFailedError

use of junit.framework.AssertionFailedError in project realm-java by realm.

the class RealmTests method close_differentThread.

// Tests close Realm in another thread different from where it is created.
@Test
public void close_differentThread() throws InterruptedException {
    final CountDownLatch latch = new CountDownLatch(1);
    final AssertionFailedError[] threadAssertionError = new AssertionFailedError[1];
    final Thread thatThread = new Thread(new Runnable() {

        @Override
        public void run() {
            try {
                realm.close();
                threadAssertionError[0] = new AssertionFailedError("Close realm in a different thread should throw IllegalStateException.");
            } catch (IllegalStateException ignored) {
            }
            latch.countDown();
        }
    });
    thatThread.start();
    // Timeout should never happen.
    latch.await();
    if (threadAssertionError[0] != null) {
        throw threadAssertionError[0];
    }
    // After exception thrown in another thread, nothing should be changed to the realm in this thread.
    realm.checkIfValid();
    realm.close();
    realm = null;
}
Also used : CountDownLatch(java.util.concurrent.CountDownLatch) AssertionFailedError(junit.framework.AssertionFailedError) RunInLooperThread(io.realm.rule.RunInLooperThread) RunTestInLooperThread(io.realm.rule.RunTestInLooperThread) RealmThread(io.realm.util.RealmThread) HandlerThread(android.os.HandlerThread) Test(org.junit.Test)

Example 17 with AssertionFailedError

use of junit.framework.AssertionFailedError in project robovm by robovm.

the class JSONTokenerTest method testNext0.

public void testNext0() throws JSONException {
    JSONTokener tokener = new JSONTokener("ABCDEF");
    tokener.next(5);
    tokener.next();
    try {
        tokener.next(0);
    } catch (JSONException e) {
        Error error = new AssertionFailedError("Returning an empty string should be valid");
        error.initCause(e);
        throw error;
    }
}
Also used : AssertionFailedError(junit.framework.AssertionFailedError) AssertionFailedError(junit.framework.AssertionFailedError)

Example 18 with AssertionFailedError

use of junit.framework.AssertionFailedError in project robovm by robovm.

the class Support_Exec method execAndGetOutput.

/**
     * Starts the specified process, collects its output from standard out and
     * standard err, and returns. If the stream emits anything to standard err,
     * an AssertionFailedError will be thrown.
     *
     * <p>This method assumes the target process will complete within thirty
     * seconds. If it does not, an AssertionFailedError will be thrown.
     */
public static String execAndGetOutput(ProcessBuilder builder) throws IOException {
    Process process = builder.start();
    ExecutorService executorService = Executors.newFixedThreadPool(2);
    try {
        Future<String> errFuture = executorService.submit(streamToStringCallable(process.getErrorStream()));
        Future<String> outFuture = executorService.submit(streamToStringCallable(process.getInputStream()));
        Throwable failure;
        String out = "";
        try {
            out = outFuture.get(30, TimeUnit.SECONDS);
            String err = errFuture.get(30, TimeUnit.SECONDS);
            failure = err.length() > 0 ? new AssertionFailedError("Unexpected err stream data:\n" + err) : null;
        } catch (Exception e) {
            failure = e;
        }
        if (failure != null) {
            AssertionFailedError error = new AssertionFailedError("Failed to execute " + builder.command() + "; output was:\n" + out);
            error.initCause(failure);
            throw error;
        } else {
            return out;
        }
    } finally {
        executorService.shutdown();
    }
}
Also used : ExecutorService(java.util.concurrent.ExecutorService) AssertionFailedError(junit.framework.AssertionFailedError) IOException(java.io.IOException)

Example 19 with AssertionFailedError

use of junit.framework.AssertionFailedError in project robovm by robovm.

the class AccessControllerTest method testDoPrivilegedWithCombiner.

public void testDoPrivilegedWithCombiner() {
    final Permission permission = new RuntimePermission("do stuff");
    final DomainCombiner union = new DomainCombiner() {

        public ProtectionDomain[] combine(ProtectionDomain[] a, ProtectionDomain[] b) {
            throw new AssertionFailedError("Expected combiner to be unused");
        }
    };
    ProtectionDomain protectionDomain = new ProtectionDomain(null, new Permissions());
    AccessControlContext accessControlContext = new AccessControlContext(new AccessControlContext(new ProtectionDomain[] { protectionDomain }), union);
    final AtomicInteger actionCount = new AtomicInteger();
    AccessController.doPrivileged(new PrivilegedAction<Void>() {

        public Void run() {
            assertEquals(null, AccessController.getContext().getDomainCombiner());
            AccessController.getContext().checkPermission(permission);
            // Calling doPrivileged again would have exercised the combiner
            AccessController.doPrivileged(new PrivilegedAction<Void>() {

                public Void run() {
                    actionCount.incrementAndGet();
                    assertEquals(null, AccessController.getContext().getDomainCombiner());
                    AccessController.getContext().checkPermission(permission);
                    return null;
                }
            });
            return null;
        }
    }, accessControlContext);
    assertEquals(1, actionCount.get());
}
Also used : ProtectionDomain(java.security.ProtectionDomain) DomainCombiner(java.security.DomainCombiner) AccessControlContext(java.security.AccessControlContext) AtomicInteger(java.util.concurrent.atomic.AtomicInteger) PrivilegedAction(java.security.PrivilegedAction) Permission(java.security.Permission) Permissions(java.security.Permissions) AssertionFailedError(junit.framework.AssertionFailedError)

Example 20 with AssertionFailedError

use of junit.framework.AssertionFailedError in project robovm by robovm.

the class ECDHKeyAgreementTest method invokeCallingMethodForEachKeyAgreementProvider.

private void invokeCallingMethodForEachKeyAgreementProvider() throws Exception {
    StackTraceElement[] stackTrace = Thread.currentThread().getStackTrace();
    String callingMethodName = null;
    for (int i = 0; i < stackTrace.length; i++) {
        if ("invokeCallingMethodForEachKeyAgreementProvider".equals(stackTrace[i].getMethodName())) {
            callingMethodName = stackTrace[i + 1].getMethodName();
        }
    }
    if (callingMethodName == null) {
        throw new RuntimeException("Failed to deduce calling method name from stack trace");
    }
    String invokedMethodName = callingMethodName;
    Method method;
    try {
        method = getClass().getDeclaredMethod(invokedMethodName, Provider.class);
    } catch (NoSuchMethodError e) {
        throw new AssertionFailedError("Failed to find per-Provider test method " + getClass().getSimpleName() + "." + invokedMethodName + "(Provider)");
    }
    for (Provider provider : getKeyAgreementProviders()) {
        try {
            method.invoke(this, provider);
        } catch (InvocationTargetException e) {
            throw new RuntimeException(getClass().getSimpleName() + "." + invokedMethodName + "(provider: " + provider.getName() + ") failed", e.getCause());
        }
    }
}
Also used : Method(java.lang.reflect.Method) AssertionFailedError(junit.framework.AssertionFailedError) InvocationTargetException(java.lang.reflect.InvocationTargetException) Provider(java.security.Provider)

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