1 package com.xtremelabs.robolectric.shadows; 2 3 import static org.junit.Assert.*; 4 5 import com.xtremelabs.robolectric.WithTestDefaultsRunner; 6 import org.junit.Before; 7 import org.junit.Test; 8 import org.junit.runner.RunWith; 9 10 import android.os.Bundle; 11 import android.os.Handler; 12 import android.os.Message; 13 import android.os.Messenger; 14 15 import static com.xtremelabs.robolectric.Robolectric.shadowOf; 16 17 @RunWith(WithTestDefaultsRunner.class) 18 public class MessengerTest { 19 20 @Test 21 public void testMessengerSend() throws Exception { 22 Handler handler = new Handler(); 23 Messenger messenger = new Messenger(handler); 24 25 ShadowLooper.pauseMainLooper(); 26 Message msg = Message.obtain(null, 123); 27 messenger.send(msg); 28 29 assertTrue(handler.hasMessages(123)); 30 ShadowHandler.runMainLooperOneTask(); 31 assertFalse(handler.hasMessages(123)); 32 } 33 } 34