/**
  * Test method for {@link
  * de.unikassel.android.sdcframework.data.WeekdaySchedule#WeekdaySchedule(de.unikassel.android.sdcframework.data.Weekday)}
  * and {@link de.unikassel.android.sdcframework.data.WeekdaySchedule#getWeekday()} .
  */
 public final void testWeekdayScheduleWeekday() {
   for (Weekday weekday : Weekday.values()) {
     WeekdaySchedule daySchedule = new WeekdaySchedule(weekday);
     assertEquals("Unexpected weekday", weekday, daySchedule.getWeekday());
     assertNotNull("Expected entry list intitialized", daySchedule.getEntries());
     assertTrue("Expected entry list empty", daySchedule.getEntries().isEmpty());
   }
 }
 /**
  * Test method for {@link
  * de.unikassel.android.sdcframework.data.WeekdaySchedule#WeekdaySchedule(de.unikassel.android.sdcframework.data.Weekday,
  * java.util.List)} .
  */
 public final void testWeekdayScheduleWeekdayListOfWeekdayScheduleEntry() {
   List<WeekdayScheduleEntry> randomEntryList = createWeekdayScheduleEntriesForTest();
   Weekday randomWeekday = Weekday.valueOfOrdinal((int) (Math.random() * 7));
   WeekdaySchedule daySchedule = new WeekdaySchedule(randomWeekday, randomEntryList);
   assertEquals("Unexpected weekday", randomWeekday, daySchedule.getWeekday());
   assertNotNull("Expected entry list intitialized", daySchedule.getEntries());
   assertEquals(
       "Expected same entry count", randomEntryList.size(), daySchedule.getEntries().size());
   assertTrue("Expected all entries added", daySchedule.getEntries().containsAll(randomEntryList));
 }
  /**
   * Does create a weekday schedule for test purpose.
   *
   * @return a weekday schedule for test purpose.
   */
  public static WeekdaySchedule createWeekdayScheduleForTest() {
    WeekdaySchedule schedule =
        new WeekdaySchedule(Weekday.valueOfOrdinal((int) (Math.random() * 7)));
    List<WeekdayScheduleEntry> entries = createWeekdayScheduleEntriesForTest();

    for (WeekdayScheduleEntry entry : entries) {
      schedule.addEntry(entry);
    }
    return schedule;
  }
 /** Test method for {@link de.unikassel.android.sdcframework.data.WeekdaySchedule#toXML()}. */
 public final void testToXML() {
   WeekdaySchedule daySchedule = createWeekdayScheduleForTest();
   try {
     String xml = daySchedule.toXML();
     WeekdaySchedule dayScheduleFromXML = GlobalSerializer.fromXML(WeekdaySchedule.class, xml);
     assertEquals(
         "Expected deserialized day schedule equals original one",
         daySchedule,
         dayScheduleFromXML);
   } catch (Exception e) {
     fail("Unexpected serialization exception");
   }
 }
  /**
   * Test method for {@link
   * de.unikassel.android.sdcframework.data.WeekdaySchedule#writeToParcel(android.os.Parcel, int)}
   * and {@link
   * de.unikassel.android.sdcframework.data.WeekdaySchedule#WeekdaySchedule(android.os.Parcel)} .
   */
  @SuppressLint("Recycle")
  public final void testWriteToParcel() {
    WeekdaySchedule schedule = createWeekdayScheduleForTest();
    Parcel parcel = Parcel.obtain();
    schedule.writeToParcel(parcel, 0);
    parcel.setDataPosition(0);

    WeekdaySchedule scheduleFromParcel = WeekdaySchedule.CREATOR.createFromParcel(parcel);

    assertEquals(
        "Expected weekday schedule created from parcel equal to the original weekday schedule",
        schedule,
        scheduleFromParcel);
  }
  /** Test method for {@link de.unikassel.android.sdcframework.data.WeekdaySchedule#isValid()}. */
  public final void testIsValid() {
    WeekdaySchedule daySchedule = createWeekdayScheduleForTest();

    assertTrue("Expected new intialized day schedule valid", daySchedule.isValid());

    for (int i = 0; i < daySchedule.getEntries().size(); ++i) {
      WeekdayScheduleEntry entry = daySchedule.getEntries().get(i);
      assertTrue("Expected entry " + i + " valid", entry.isValid());
      if (i == 0) {
        entry.setValid(false);
      }
    }

    assertFalse(
        "Expected an weekday schedule with invalid entries is not valid", daySchedule.isValid());
  }
  /**
   * Test method for {@link
   * de.unikassel.android.sdcframework.data.WeekdaySchedule#equals(java.lang.Object)} .
   */
  public final void testEquals() {
    WeekdaySchedule daySchedule = createWeekdayScheduleForTest();
    WeekdaySchedule otherDaySchedule = new WeekdaySchedule(daySchedule.getWeekday());
    assertFalse("Expected unequal day schedules", otherDaySchedule.equals(daySchedule));

    for (WeekdayScheduleEntry entry : daySchedule.getEntries()) {
      otherDaySchedule.addEntry(new WeekdayScheduleEntry(entry));
    }

    assertTrue("Expected equal day schedules", otherDaySchedule.equals(daySchedule));
  }
  /**
   * Test method for {@link
   * de.unikassel.android.sdcframework.data.WeekdaySchedule#addEntry(de.unikassel.android.sdcframework.data.WeekdayScheduleEntry)}
   * and {@link de.unikassel.android.sdcframework.data.WeekdaySchedule#getEntries()} and {@link
   * de.unikassel.android.sdcframework.data.WeekdaySchedule#removeEntry(de.unikassel.android.sdcframework.data.WeekdayScheduleEntry)}
   * .
   */
  public final void testEntryList() {
    WeekdaySchedule daySchedule = new WeekdaySchedule(Weekday.Saturday);
    assertNotNull("Expected entry list available", daySchedule.getEntries());
    assertEquals("Expected entry list empty", 0, daySchedule.getEntries().size());

    List<WeekdayScheduleEntry> entries = createWeekdayScheduleEntriesForTest();
    int cnt = 0;
    for (WeekdayScheduleEntry entry : entries) {
      daySchedule.addEntry(entry);
      cnt++;
      assertTrue("Expected entry added", daySchedule.getEntries().contains(entry));
      assertEquals("Unexpected entry count", cnt, daySchedule.getEntries().size());
    }

    assertEquals("Expected same entry count", entries.size(), daySchedule.getEntries().size());
    assertTrue("Expected all entries added", daySchedule.getEntries().containsAll(entries));

    WeekdayScheduleEntry entryToRemove = entries.get(entries.size() >> 1);
    daySchedule.removeEntry(entryToRemove);
    assertFalse("Expected entry removed", daySchedule.getEntries().contains(entryToRemove));
    assertEquals("Unexpected entry count", entries.size() - 1, daySchedule.getEntries().size());
  }