Example usage for android.os Parcel obtain

List of usage examples for android.os Parcel obtain

Introduction

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

Prototype

public static Parcel obtain() 

Source Link

Document

Retrieve a new Parcel object from the pool.

Usage

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

@Test
public void testNestDeviceToParcel() {
    try {/*from   ww w  .j a v a  2s  . c om*/
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_DEVICE_JSON), "utf-8");
        Device device = mapper.readValue(json, Device.class);

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

        parcel.setDataPosition(0);

        Device deviceFromParcel = Device.CREATOR.createFromParcel(parcel);
        assertEquals(device, deviceFromParcel);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

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

@Test
public void testMetadataToParcel() {
    try {/*w  w w.  j  av  a  2 s. co m*/
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_METADATA_JSON), "utf-8");
        Metadata metadata = mapper.readValue(json, Metadata.class);

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

        parcel.setDataPosition(0);

        Metadata metadataFromParcel = Metadata.CREATOR.createFromParcel(parcel);
        assertEquals(metadata, metadataFromParcel);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

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

@Test
public void testThermostatToParcel() {
    try {/*from w  ww.  jav  a2 s  .  co m*/
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_THERMOSTAT_JSON), "utf-8");
        Thermostat thermostat = mapper.readValue(json, Thermostat.class);

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

        parcel.setDataPosition(0);

        Thermostat thermostatFromParcel = Thermostat.CREATOR.createFromParcel(parcel);
        assertEquals(thermostat, thermostatFromParcel);

    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:com.clover.sdk.v3.apps.AppNotificationTest.java

/**
 * Tests serializing to and from a {@code Parcel}.
 *//*w ww  .  ja v a 2 s. co  m*/
public void testParcelable() throws Exception {
    AppNotification expected = new AppNotification("sale", "Sunday");
    Parcel p = Parcel.obtain();
    expected.writeToParcel(p, 0);

    p.setDataPosition(0);
    AppNotification actual = AppNotification.CREATOR.createFromParcel(p);
    Assert.assertEquals(expected, actual);
}

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

@Test
public void testSmokeCoAlarmToParcel() {
    try {/*from ww w.j  av a 2s .c  o  m*/
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_SMOKE_ALARM_JSON), "utf-8");
        SmokeCOAlarm smokeCOAlarm = mapper.readValue(json, SmokeCOAlarm.class);

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

        parcel.setDataPosition(0);

        SmokeCOAlarm cameraFromParcel = SmokeCOAlarm.CREATOR.createFromParcel(parcel);
        assertEquals(smokeCOAlarm, cameraFromParcel);
    } catch (IOException e) {
        e.printStackTrace();
        Assert.fail();
    }
}

From source file:jp.alessandro.android.iab.ItemParcelableTest.java

@Test
public void writeToParcel() throws JSONException {
    Item item = Item.parseJson(String.format(Locale.ENGLISH, DataConverter.SKU_SUBSCRIPTION_DETAILS_JSON, 0));

    // Obtain a Parcel object and write the parcelable object to it
    Parcel parcel = Parcel.obtain();
    item.writeToParcel(parcel, item.describeContents());

    // After you're done with writing, you need to reset the parcel for reading
    parcel.setDataPosition(0);/* w w  w .  ja va  2  s .  co m*/

    Item fromParcel = Item.CREATOR.createFromParcel(parcel);

    assertThat(item.getOriginalJson()).isEqualTo(fromParcel.getOriginalJson());
    assertThat(item.getSku()).isEqualTo(fromParcel.getSku());
    assertThat(item.getType()).isEqualTo(fromParcel.getType());
    assertThat(item.getTitle()).isEqualTo(fromParcel.getTitle());
    assertThat(item.getDescription()).isEqualTo(fromParcel.getDescription());
    assertThat(item.getCurrency()).isEqualTo(fromParcel.getCurrency());
    assertThat(item.getPrice()).isEqualTo(fromParcel.getPrice());
    assertThat(item.getPriceMicros()).isEqualTo(fromParcel.getPriceMicros());
    assertThat(item.getSubscriptionPeriod()).isEqualTo(fromParcel.getSubscriptionPeriod());
    assertThat(item.getFreeTrialPeriod()).isEqualTo(fromParcel.getFreeTrialPeriod());
    assertThat(item.getIntroductoryPrice()).isEqualTo(fromParcel.getIntroductoryPrice());
    assertThat(item.getIntroductoryPriceAmountMicros())
            .isEqualTo(fromParcel.getIntroductoryPriceAmountMicros());
    assertThat(item.getIntroductoryPricePeriod()).isEqualTo(fromParcel.getIntroductoryPricePeriod());
    assertThat(item.getIntroductoryPriceCycles()).isEqualTo(fromParcel.getIntroductoryPriceCycles());
}

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

@Test
public void testStructureToParcel() {
    try {//from   w  ww.j  a v  a  2  s .c om
        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.CreditCardTest.java

@SmallTest
public void testParcelWithMinimalModel() {
    final CreditCard card = CreditCardFixture.getMinimalModel(1);

    final Parcel parcel = Parcel.obtain();
    card.writeToParcel(parcel, 0);/*ww  w  .  jav  a2 s  .  c o m*/
    parcel.setDataPosition(0);

    final CreditCard card2 = CreditCard.CREATOR.createFromParcel(parcel);
    parcel.recycle();
    assertEquals(card, card2);
}

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 {/*from w ww .  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:com.scvngr.levelup.core.model.LoyaltyTest.java

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

    try {//  w ww . java2  s  .co  m
        loyalty.writeToParcel(parcel, 0);
        parcel.setDataPosition(0);

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