BaggersListEntry implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { TextUtils.writeToParcel(name, dest, flags); TextUtils.writeToParcel(links, dest, flags); TextUtils.writeToParcel(sessions, dest, flags); TextUtils.writeToParcel(bio, dest, flags); TextUtils.writeToParcel(locations, dest, flags); dest.writeString(pictureUrl); dest.writeString(email); } BaggersListEntry(Context context, Bagger bagger); private  BaggersListEntry(Parcel in); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); final CharSequence name; final CharSequence links; final CharSequence sessions; final CharSequence bio; final CharSequence locations; final String pictureUrl; final String email; static final Parcelable.Creator<BaggersListEntry> CREATOR; }
@Test public void should_restore_from_parcelable() { String name = entry.name.toString(); String links = entry.links.toString(); String sessions = entry.sessions.toString(); String bio = entry.bio.toString(); String locations = entry.locations.toString(); String pictureUrl = entry.pictureUrl; String email = entry.email; Parcel parcel = Parcel.obtain(); entry.writeToParcel(parcel, 0); parcel.setDataPosition(0); BaggersListEntry fromParcel = BaggersListEntry.CREATOR.createFromParcel(parcel); Spanned htmlLocation = CompatibilityUtils.fromHtml(String.format(Locale.US, RuntimeEnvironment.application.getString(R.string.baggers_list_location), "Franconville")); assertThat(fromParcel.name.toString()).isEqualTo(name); assertThat(fromParcel.name.toString()).isEqualTo("Gautier"); assertThat(fromParcel.links.toString()).isEqualTo(links); assertThat(fromParcel.sessions.toString()).isEqualTo(sessions); assertThat(fromParcel.bio.toString()).isEqualTo(bio); assertThat(fromParcel.bio.toString()).isEqualTo("Software Craftsman"); assertThat(fromParcel.locations.toString()).isEqualTo(locations); assertThat(fromParcel.locations.toString()).isEqualTo(htmlLocation.toString()); assertThat(fromParcel.pictureUrl).isEqualTo(pictureUrl); assertThat(fromParcel.pictureUrl).isEqualTo("http: assertThat(fromParcel.email).isEqualTo(email); assertThat(fromParcel.email).isEqualTo("me@example.com"); }