I'm having trouble getting the main UI thread inside a robolectric(version 1.1) testcase. The application method I'm testing has the following check in it:
if (Thread.currentThread() != Looper.getMainLooper().getThread()) {
throw new IllegalStateException(
"This method should be called from the Main UI Thread");
}
}
This check fails when invoked in the following way:
@Test
public void maTest() {
Runnable task = new Runnable() {
@Override
public void run() {
adapter.testThreadPrecondition();
}
};
new Handler(Looper.getMainLooper()).post(task);
}
Also tried "runOnUiThread", and got same check to fail. What is going on? different main loopers?