public void testConstructorAndEquals() { Messenger messenger = new Messenger(mHandler); Messenger objMessenger = new Messenger(mHandler); assertTrue(messenger.equals(objMessenger)); messenger = new Messenger(mIBinder); assertFalse(messenger.equals(objMessenger)); }
public void testWriteToParcel() { Parcel parcel = Parcel.obtain(); mMessenger.writeToParcel(parcel, 0); parcel.setDataPosition(0); Messenger messenger = Messenger.CREATOR.createFromParcel(parcel); assertTrue(messenger.equals(mMessenger)); parcel.recycle(); }
/** * This method is used to check if the message sent by another messenger is correctly handled by * this thread. If not equals to expected, there will be a failure thrown. */ public void handleMessage(Message msg) { if (msg.arg1 != MSG_ARG1) { failure(new RuntimeException("Message.arg1 is not " + MSG_ARG1 + ", it's " + msg.arg1)); return; } if (msg.arg2 != MSG_ARG2) { failure(new RuntimeException("Message.arg2 is not " + MSG_ARG2 + ", it's " + msg.arg2)); return; } if (!mTestMessenger.equals(msg.replyTo)) { failure(new RuntimeException("Message.replyTo is not me, it's " + msg.replyTo)); return; } success(); }
public void testWriteMessengerOrNullToParcel() { Parcel parcelWithMessenger = Parcel.obtain(); Messenger.writeMessengerOrNullToParcel(mMessenger, parcelWithMessenger); parcelWithMessenger.setDataPosition(0); Messenger messenger = Messenger.readMessengerOrNullFromParcel(parcelWithMessenger); assertNotNull(messenger); assertTrue(messenger.equals(mMessenger)); parcelWithMessenger.recycle(); Parcel parcelWithNull = Parcel.obtain(); Messenger.writeMessengerOrNullToParcel(null, parcelWithNull); parcelWithNull.setDataPosition(0); messenger = Messenger.readMessengerOrNullFromParcel(parcelWithNull); assertNull(messenger); parcelWithNull.recycle(); }