package edu.northwestern.bioinformatics.studycalendar.domain;

import junit.framework.TestCase;

/**
 * @author Moses Hohman
 */
public class PeriodTest extends TestCase {
    private Period period = new Period();

    public void testDurationNeverNull() {
        Period period = new Period();
        period.setDuration(null);
        assertNotNull(period.getDuration());
    }

    public void testEndDay() {
        assertNull("not null when startDay null", period.getEndDay());
        period.setStartDay(1);
        assertNull("not null when duration blank", period.getEndDay());
        period.setRepetitions(2);
        period.setDuration(new Duration(2, Duration.Unit.week));
        assertEquals(new Integer(28), period.getEndDay());
    }

    public void testAddPlannedEventMaintainsBidirectionality() throws Exception {
        PlannedEvent e = new PlannedEvent();
        assertNull(e.getPeriod());
        period.addPlannedEvent(e);
        assertSame(period, e.getPeriod());
    }

    public void testAddPlannedEventAdds() throws Exception {
        assertNull(period.getPlannedEvents());
        PlannedEvent e = new PlannedEvent();
        period.addPlannedEvent(e);

        assertEquals(1, period.getPlannedEvents().size());
        assertSame(e, period.getPlannedEvents().iterator().next());
    }
}

@@ -258,37 +258,32 @@
         Period p
-eriod
  = new Period();
@@ -284,37 +284,32 @@
 iod();%0A        p
-eriod
 .setDuration(nul
@@ -331,29 +331,24 @@
 ertNotNull(p
-eriod
 .getDuration
@@ -828,36 +828,47 @@
 lannedEvent e = 
-new 
+Fixtures.create
 PlannedEvent();%0A
@@ -856,32 +856,40 @@
 atePlannedEvent(
+%22Any%22, 5
 );%0A        asser
@@ -1070,21 +1070,26 @@
   assert
-Null(
+Equals(0, 
 period.g
@@ -1105,16 +1105,23 @@
 Events()
+.size()
 );%0A     
@@ -1140,20 +1140,31 @@
 ent e = 
-new 
+Fixtures.create
 PlannedE
@@ -1168,16 +1168,24 @@
 edEvent(
+%22Any%22, 5
 );%0A     

PlannedEvent comparator requires day to be non-null