ScheduleSlot implements Parcelable { @Override public void writeToParcel(Parcel dest, int flags) { dest.writeSerializable(time); dest.writeTypedList(sessions); } ScheduleSlot(LocalDateTime time, List<Session> sessions); protected  ScheduleSlot(Parcel in); @Override int describeContents(); @Override void writeToParcel(Parcel dest, int flags); static final Parcelable.Creator<ScheduleSlot> CREATOR; }
@Test public void should_restore_from_parcelable() { LocalDateTime time = LocalDateTime.now(); List<Session> sessions = Arrays.asList(new Session(1, null, null, null, null, null, null), new Session(2, null, null, null, null, null, null), new Session(3, null, null, null, null, null, null)); ScheduleSlot slot = new ScheduleSlot(time, sessions); Parcel parcel = Parcel.obtain(); slot.writeToParcel(parcel, 0); parcel.setDataPosition(0); ScheduleSlot fromParcel = ScheduleSlot.CREATOR.createFromParcel(parcel); assertThat(fromParcel.getTime()).isEqualTo(time); assertThat(fromParcel.getSessions()).hasSize(3); }