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