private static <X> X callOnMainSync(Instrumentation instrumentation, final Callable<X> callable) throws Exception { final AtomicReference<X> retAtomic = new AtomicReference<>(); final AtomicReference<Throwable> exceptionAtomic = new AtomicReference<>(); instrumentation.runOnMainSync(new Runnable() { @Override public void run() { try { retAtomic.set(callable.call()); } catch (Throwable e) { exceptionAtomic.set(e); } } }); final Throwable exception = exceptionAtomic.get(); if (exception != null) { Throwables.propagateIfInstanceOf(exception, Exception.class); Throwables.propagate(exception); } return retAtomic.get(); }
public static <X> X callOnMainSync(Instrumentation instrumentation, final Callable<X> callable) throws Exception { final AtomicReference<X> retAtomic = new AtomicReference<>(); final AtomicReference<Throwable> exceptionAtomic = new AtomicReference<>(); instrumentation.runOnMainSync(new Runnable() { @Override public void run() { try { retAtomic.set(callable.call()); } catch (Throwable e) { exceptionAtomic.set(e); } } }); final Throwable exception = exceptionAtomic.get(); if (exception != null) { Throwables.propagateIfInstanceOf(exception, Exception.class); Throwables.propagate(exception); } return retAtomic.get(); }
@Override public void handle(Throwable error, Matcher<View> viewMatcher) { if (error instanceof EspressoException || error instanceof AssertionFailedError || error instanceof AssertionError) { Uri location = Uri.EMPTY; if (activityRef.get() != null) { location = screenShotManager.shoot(activityRef.get().getWindow().getDecorView()); } throw Throwables.propagate(getUserFriendlyError(error, viewMatcher, location.toString())); } else { throw Throwables.propagate(error); } }