Created
July 11, 2014 06:25
-
-
Save thuytrinh/d5c4394d8af56f3206d6 to your computer and use it in GitHub Desktop.
Unit test for parcelling a parcelable model in AndroidDev
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
public class ParcelableModelTest extends TestCase { | |
public void testShouldParcelProperly() { | |
/* Prepare data */ | |
ParcelableModel expectedModel = new ParcelableModel(); | |
expectedModel.setProperty0(123); | |
expectedModel.setProperty1("LOL"); | |
/* Perform parcelling */ | |
Parcel parcel = Parcel.obtain(); | |
expectedModel.writeToParcel(parcel, 0); | |
parcel.setDataPosition(0); | |
ParcelableModel parcelledModel = ParcelableModel.CREATOR.createFromParcel(parcel); | |
/* Verify result */ | |
assertNotNull(parcelledModel); | |
assertEquals(expectedModel.getProperty0(), parcelledModel.getProperty0()); | |
assertEquals(expectedModel.getProperty1(), parcelledModel.getProperty1()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment