Code example for Handler

Methods: hasMessages

0
@RunWith(TestRunners.WithDefaults.class) 
public class MessengerTest { 
 
    @Test 
    public void testMessengerSend() throws Exception { 
        Handler handler = new Handler();
        Messenger messenger = new Messenger(handler);
 
        ShadowLooper.pauseMainLooper(); 
        Message msg = Message.obtain(null, 123);
        messenger.send(msg);
 
        assertTrue(handler.hasMessages(123));
        ShadowHandler.runMainLooperOneTask(); 
        assertFalse(handler.hasMessages(123));
    } 
}