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.CreditCardTest.java

@SmallTest
public void testParcel() {
    final CreditCard card = CreditCardFixture.getFullModel(0);

    final Parcel parcel = Parcel.obtain();
    card.writeToParcel(parcel, 0);//w w w.  j a v  a  2  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.CreditCardTest.java

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

    final Parcel parcel = Parcel.obtain();
    card.writeToParcel(parcel, 0);/*from www .  j a  v  a  2  s  . c  o  m*/
    parcel.setDataPosition(0);

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

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

@Test
public void testCameraToParcel() {
    try {//from w  ww.j  a  v a  2 s .c o m
        String json = IOUtils.toString(this.getClass().getResourceAsStream(TEST_CAMERA_JSON), "utf-8");
        Camera camera = mapper.readValue(json, Camera.class);

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

        parcel.setDataPosition(0);

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

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

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

@Test
public void testSmokeCoAlarmToParcel() {
    try {//from ww w .  ja v a  2 s.c  om
        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:com.nestlabs.sdk.ThermostatAndroidTest.java

@Test
public void testThermostatToParcel() {
    try {/*w  w  w . jav a 2 s  .  com*/
        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.nestlabs.sdk.NestConfigAndroidTest.java

@Test
public void testNestConfigToParcel() {
    String testClientId = "test-id";
    String testClientSecret = "test-secret";
    String testRedirectURL = "test-redirect-url";

    NestConfig config = new NestConfig.Builder().clientID(testClientId).clientSecret(testClientSecret)
            .redirectURL(testRedirectURL).build();

    Parcel parcel = Parcel.obtain();
    config.writeToParcel(parcel, 0);/*w ww.j  ava2  s. co  m*/

    parcel.setDataPosition(0);

    NestConfig configFromParcel = NestConfig.CREATOR.createFromParcel(parcel);
    assertEquals(config, configFromParcel);
}

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

@SmallTest
public void testParcel() {
    final CauseAffiliation causeAffiliation = CauseAffiliationFixture.getFullModel();

    final Parcel parcel = Parcel.obtain();
    causeAffiliation.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    final CauseAffiliation causeAffiliation2 = CauseAffiliation.CREATOR.createFromParcel(parcel);
    parcel.recycle();/*from   w w w .  ja  va  2 s. c om*/
    assertEquals(causeAffiliation, causeAffiliation2);
}

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

@SmallTest
public void testParcel_nullId() {
    final CauseAffiliation causeAffiliation = CauseAffiliationFixture.getFullModel(null);

    final Parcel parcel = Parcel.obtain();
    causeAffiliation.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    final CauseAffiliation causeAffiliation2 = CauseAffiliation.CREATOR.createFromParcel(parcel);
    parcel.recycle();//from  www . j a  v  a2s. c o m
    assertEquals(causeAffiliation, causeAffiliation2);
}