Example usage for android.os Parcel setDataPosition

List of usage examples for android.os Parcel setDataPosition

Introduction

In this page you can find the example usage for android.os Parcel setDataPosition.

Prototype

public final void setDataPosition(int pos) 

Source Link

Document

Move the current read/write position in the parcel.

Usage

From source file:com.scvngr.levelup.core.model.PaymentTokenTest.java

@SmallTest
public void testParcel() throws JSONException {
    final JSONObject object = PaymentTokenFixture.getFullJsonObject();

    final PaymentToken paymentToken = new PaymentTokenJsonFactory().from(object);
    final Parcel parcel = Parcel.obtain();
    paymentToken.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    final PaymentToken parceled = PaymentToken.CREATOR.createFromParcel(parcel);
    assertEquals(paymentToken, parceled);
}

From source file:com.bmd.android.collection.example.EnhancedArrayMapTest.java

public void testParcelable() {

    final Bundle bundle = new Bundle();
    bundle.putParcelable("array", mArray);

    final Parcel parcel = Parcel.obtain();
    bundle.writeToParcel(parcel, 0);/*from   www.  j a v  a 2 s  . c om*/

    parcel.setDataPosition(0);

    final Bundle out = parcel.readBundle();
    out.setClassLoader(AndroidCollections.class.getClassLoader());

    assertThat(out.getParcelable("array")).isEqualTo(mArray);
}

From source file:com.nestlabs.sdk.StructureAndroidTest.java

@Test
public void testStructureToParcel() {
    try {//from   w  w w.  jav  a 2  s. c  o  m
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_STRUCTURE_JSON), "utf-8");
        Structure structure = mapper.readValue(json, Structure.class);

        Parcel parcel = Parcel.obtain();
        structure.writeToParcel(parcel, 0);

        parcel.setDataPosition(0);

        Structure structureFromParcel = Structure.CREATOR.createFromParcel(parcel);
        assertEquals(structure, structureFromParcel);

        assertEquals(structureFromParcel.getStructureId(), "VqFabWH21nwVyd4RWgJgNb292wa7hG");
        assertEquals(structureFromParcel.getThermostats().size(), 1);
        assertEquals(structureFromParcel.getThermostats().get(0), "peyiJNo0IldT2YlIVtYaGQ");
        assertEquals(structureFromParcel.getSmokeCoAlarms().size(), 1);
        assertEquals(structureFromParcel.getSmokeCoAlarms().get(0), "RTMTKxsQTCxzVcsySOHPxKoF4OyCifrs");
        assertEquals(structureFromParcel.getCameras().size(), 1);
        assertEquals(structureFromParcel.getCameras().get(0), "awJo6rHX");
        assertEquals(structureFromParcel.getDevices().size(), 1);

        assertEquals(structureFromParcel.getAway(), "home");
        assertEquals(structureFromParcel.getName(), "Home");
        assertEquals(structureFromParcel.getCountryCode(), "US");
        assertEquals(structureFromParcel.getPostalCode(), "94304");
        assertEquals(structureFromParcel.getPeakPeriodStartTime(), "2015-10-31T23:59:59.000Z");
        assertEquals(structureFromParcel.getPeakPeriodEndTime(), "2015-10-31T23:59:59.000Z");
        assertEquals(structureFromParcel.getTimeZone(), "America/Los_Angeles");
        assertNotNull(structureFromParcel.getEta());

        Structure.ETA eta = structureFromParcel.getEta();
        assertEquals(eta.getTripId(), "myTripHome1024");
        assertEquals(eta.getEstimatedArrivalWindowBegin(), "2015-10-31T22:42:59.000Z");
        assertEquals(eta.getEstimatedArrivalWindowEnd(), "2015-10-31T23:59:59.000Z");

        assertEquals(structureFromParcel.getRhrEnrollment(), true);

        assertNotNull(structureFromParcel.getWheres());
        assertEquals(structureFromParcel.getWheres().size(), 1);

        Structure.Where where = structureFromParcel.getWheres().get("Fqp6wJIX");
        assertNotNull(where);
        assertEquals(where.getWhereId(), "Fqp6wJIX");
        assertEquals(where.getName(), "Bedroom");
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:com.scvngr.levelup.core.model.WebLinkTest.java

@SmallTest
public void testParcel_full() {
    final WebLink loyalty = WebLinkFixture.getFullModel(1);
    final Parcel parcel = Parcel.obtain();

    try {/*from   w w  w .  ja  v  a2 s .  c  om*/
        loyalty.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final WebLink parceled = WebLink.CREATOR.createFromParcel(parcel);
        assertEquals(loyalty, parceled);
    } finally {
        parcel.recycle();
    }
}

From source file:com.scvngr.levelup.core.model.WebLinkTest.java

@SmallTest
public void testParcel_minimal() {
    final WebLink loyalty = WebLinkFixture.getMinimalModel(1);
    final Parcel parcel = Parcel.obtain();

    try {/* ww  w.j a  v a2s.  c o  m*/
        loyalty.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final WebLink parceled = WebLink.CREATOR.createFromParcel(parcel);
        assertEquals(loyalty, parceled);
    } finally {
        parcel.recycle();
    }
}

From source file:cl.smartcities.isci.transportinspector.backend.BusTest.java

@Test
public void busParcelWriteReadTest() {
    Parcel parcel = Parcel.obtain();
    bus.writeToParcel(parcel, bus.describeContents());

    parcel.setDataPosition(0);

    Bus createdFromParcel = Bus.CREATOR.createFromParcel(parcel);

    assertThat(createdFromParcel.getService(), is(SERVICE));
    assertThat(createdFromParcel.getLicensePlate(), is(LICENSE_PLATE));
    assertThat(createdFromParcel.getActiveMapBusIcon(), is(bus.getActiveMapBusIcon()));
    assertThat(createdFromParcel.getBusIcon(), is(bus.getBusIcon()));
    assertThat(createdFromParcel.getDistance(), is(bus.getDistance()));
    assertThat(createdFromParcel.getTime(), is(bus.getTime()));
}

From source file:com.scvngr.levelup.core.model.LoyaltyTest.java

@SmallTest
public void testParcel_full() {
    final Loyalty loyalty = LoyaltyFixture.getFullModel(1);
    final Parcel parcel = Parcel.obtain();

    try {//from   w w w  .  j  av a 2 s  .  c  o  m
        loyalty.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final Loyalty parceled = Loyalty.CREATOR.createFromParcel(parcel);
        assertEquals(loyalty, parceled);
    } finally {
        parcel.recycle();
    }
}

From source file:com.scvngr.levelup.core.model.LoyaltyTest.java

@SmallTest
public void testParcel_minimal() {
    final Loyalty loyalty = LoyaltyFixture.getMinimalModel();
    final Parcel parcel = Parcel.obtain();

    try {// w  w w.  j av a 2s .com
        loyalty.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final Loyalty parceled = Loyalty.CREATOR.createFromParcel(parcel);
        assertEquals(loyalty, parceled);
    } finally {
        parcel.recycle();
    }
}

From source file:com.scvngr.levelup.core.model.UserTest.java

@SmallTest
public void testParcel_valid() throws JSONException {
    final JSONObject object = UserFixture.getMinimalJsonObject();

    object.remove(UserJsonFactory.JsonKeys.CUSTOM_ATTRIBUTES);
    final User user = new UserJsonFactory().from(object);
    final Parcel parcel = Parcel.obtain();
    try {//from   ww w  .  j a  va 2s  .c o m
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
    } finally {
        parcel.recycle();
    }
}

From source file:com.scvngr.levelup.core.model.UserTest.java

@SmallTest
public void testParcel_full() throws JSONException {
    {/*  ww w  .jav  a 2s  .  c o  m*/
        final JSONObject object = UserFixture.getFullJsonObject();

        final User user = new UserJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
        assertTrue(user.getCustomAttributes().containsKey("test_attr"));
        assertTrue(user.getCustomAttributes().containsKey("test_attr2"));
        assertEquals("0", user.getCustomAttributes().get("test_attr"));
        assertEquals("1", user.getCustomAttributes().get("test_attr2"));
    }

    {
        final JSONObject object = UserFixture.getMinimalJsonObject();

        final User user = new UserJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
    }

    {
        final JSONObject object = UserFixture.getFullJsonObject();

        object.remove(UserJsonFactory.JsonKeys.CUSTOM_ATTRIBUTES);
        final User user = new UserJsonFactory().from(object);
        final Parcel parcel = Parcel.obtain();
        user.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

        final User parceled = User.CREATOR.createFromParcel(parcel);
        assertEquals(user, parceled);
        assertNull(parceled.getCustomAttributes());
    }
}