@Test public void verifyThrowsOffMainThread() throws InterruptedException { final CountDownLatch latch = new CountDownLatch(1); new Thread(new Runnable() { @Override public void run() { try { AbstractDisposeOnMainThread.verifyMainThread(); fail(); } catch (IllegalStateException e) { assertTrue(e.getMessage().startsWith("Expected to be called on the main thread")); latch.countDown(); } } }).start(); assertTrue(latch.await(1, SECONDS)); }
public static void verifyMainThread() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName()); } }
AbstractDisposeOnMainThread implements Disposable { public static void verifyMainThread() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName()); } } }
AbstractDisposeOnMainThread implements Disposable { public static void verifyMainThread() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName()); } }  }
AbstractDisposeOnMainThread implements Disposable { public static void verifyMainThread() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName()); } }  static void verifyMainThread(); @Override final boolean isDisposed(); @Override final void dispose(); }
AbstractDisposeOnMainThread implements Disposable { public static void verifyMainThread() { if (Looper.myLooper() != Looper.getMainLooper()) { throw new IllegalStateException( "Expected to be called on the main thread but was " + Thread.currentThread().getName()); } }  static void verifyMainThread(); @Override final boolean isDisposed(); @Override final void dispose();  }