1 package org.robolectric.shadows; 2 3 import static org.robolectric.shadow.api.Shadow.directlyOn; 4 5 import android.os.Message; 6 import android.os.Messenger; 7 import android.os.RemoteException; 8 import org.robolectric.annotation.Implementation; 9 import org.robolectric.annotation.Implements; 10 import org.robolectric.annotation.RealObject; 11 import org.robolectric.annotation.Resetter; 12 13 @Implements(Messenger.class) 14 public class ShadowMessenger { 15 private static Message lastMessageSent = null; 16 17 /** Returns the last {@link Message} sent, or {@code null} if there isn't any message sent. */ getLastMessageSent()18 public static Message getLastMessageSent() { 19 return lastMessageSent; 20 } 21 22 @RealObject private Messenger messenger; 23 24 @Implementation send(Message message)25 protected void send(Message message) throws RemoteException { 26 lastMessageSent = Message.obtain(message); 27 directlyOn(messenger, Messenger.class).send(message); 28 } 29 30 @Resetter reset()31 public static void reset() { 32 lastMessageSent = null; 33 } 34 } 35