Session implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeInt(id); dest.writeString(room); dest.writeTypedList(speakers); dest.writeString(title); dest.writeString(description); dest.writeSerializable(fromTime); dest.writeSerializable(toTime); } Session(int id, String room, List<Speaker> speakers, String title, String description, LocalDateTime fromTime, LocalDateTime toTime); protected  Session(Parcel in); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Parcelable.Creator<Session> CREATOR; }
@Test public void should_restore_from_parcelable() { List<Speaker> speakers = singletonList(new Speaker(1, null, null, null, null, null, null, null)); LocalDateTime fromTime = LocalDateTime.now().minusDays(1); LocalDateTime toTime = fromTime.plusMinutes(45); Session session = new Session(42, "ROOM1", speakers, "TITLE", "DESCRIPTION", fromTime, toTime); Parcel parcel = Parcel.obtain(); session.writeToParcel(parcel, 0); parcel.setDataPosition(0); Session fromParcel = Session.CREATOR.createFromParcel(parcel); assertThat(fromParcel.getId()).isEqualTo(42); assertThat(fromParcel.getRoom()).isEqualTo("ROOM1"); assertThat(fromParcel.getSpeakers()).hasSize(1); assertThat(fromParcel.getTitle()).isEqualTo("TITLE"); assertThat(fromParcel.getDescription()).isEqualTo("DESCRIPTION"); assertThat(fromParcel.getFromTime()).isEqualTo(fromTime); assertThat(fromParcel.getToTime()).isEqualTo(toTime); }