1 package android.os; 2 3 import static java.util.concurrent.TimeUnit.SECONDS; 4 import static org.junit.Assert.assertTrue; 5 6 import androidx.test.ext.junit.runners.AndroidJUnit4; 7 import java.util.concurrent.CountDownLatch; 8 import org.junit.Test; 9 import org.junit.runner.RunWith; 10 import org.robolectric.annotation.LooperMode; 11 import org.robolectric.annotation.LooperMode.Mode; 12 import org.robolectric.annotation.internal.DoNotInstrument; 13 14 /** Tests to verify INSTRUMENTATION_TEST mode Looper behaves like a looping Looper. */ 15 @DoNotInstrument 16 @RunWith(AndroidJUnit4.class) 17 public class LooperTest { 18 19 @Test 20 @LooperMode(Mode.INSTRUMENTATION_TEST) postAndWait()21 public void postAndWait() throws InterruptedException { 22 CountDownLatch latch = new CountDownLatch(1); 23 new Handler(Looper.getMainLooper()).post(latch::countDown); 24 assertTrue(latch.await(1, SECONDS)); 25 } 26 } 27