1package com.xtremelabs.robolectric.shadows;
2
3import android.os.Binder;
4import android.os.Parcel;
5import android.os.RemoteException;
6import com.xtremelabs.robolectric.WithTestDefaultsRunner;
7import org.junit.Test;
8import org.junit.runner.RunWith;
9
10import static junit.framework.Assert.assertTrue;
11import static org.hamcrest.CoreMatchers.equalTo;
12import static org.hamcrest.CoreMatchers.sameInstance;
13import static org.hamcrest.MatcherAssert.assertThat;
14
15@RunWith(WithTestDefaultsRunner.class)
16public class ShadowBinderTest {
17    @Test
18    public void transactCallsOnTransact() throws Exception {
19        TestBinder testBinder = new TestBinder();
20        Parcel data = Parcel.obtain();
21        Parcel reply = Parcel.obtain();
22        assertTrue(testBinder.transact(2, data, reply, 3));
23        assertThat(testBinder.code, equalTo(2));
24        assertThat(testBinder.data, sameInstance(data));
25        assertThat(testBinder.reply, sameInstance(reply));
26        assertThat(testBinder.flags, equalTo(3));
27    }
28
29    static class TestBinder extends Binder {
30        int code;
31        Parcel data;
32        Parcel reply;
33        int flags;
34
35        @Override
36        protected boolean onTransact(int code, Parcel data, Parcel reply, int flags) throws RemoteException {
37            this.code = code;
38            this.data = data;
39            this.reply = reply;
40            this.flags = flags;
41            return true;
42        }
43    }
44}
45