@Test
public void testGetPreviousSessionDate() {

    //Test recession to preceding week
    DateTime testDate = new DateTime(2009, 5, 5, 0, 0, 0, 999);//Tuesday, May 5th
    TradingWeek tradingWeek = getTestTradingWeek(TEST3); //Trading Week includes only Tue, Wed, Thur
    Period tu = new Period(PeriodType.DAY, 1);
    DateTime previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    testDate = new DateTime(2009, 5, 4, 0, 0, 0, 999);//Monday, May 4th
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    testDate = new DateTime(2009, 5, 3, 0, 0, 0, 999);//Sunday, May 3rd
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    testDate = new DateTime(2009, 5, 2, 0, 0, 0, 999);//Saturday, May 2nd
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    testDate = new DateTime(2009, 5, 1, 0, 0, 0, 999);//Friday, May 1st
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    //Due to the test date being midnight, the last session of 04-30 doesn't contain
    //the time and so the previous session to that is returned. As opposed to the
    //test below which tests for an actual valid session time.
    assertEquals("2009-04-29T15:30:00.000", noZone(previousDate.toString()));
    
    //Adjustment which correlates to the discussion above
    testDate = new DateTime(2009, 5, 1, 12, 0, 0, 999);//Friday, May 1st
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    ///////////////////////////////////////////////////
    
    tradingWeek = getTestTradingWeek(TEST);
    
    testDate = new DateTime(2009, 5, 1, 12, 0, 0, 999);//Friday, May 1st
    
    tu = new Period(PeriodType.YEAR, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2008-12-31T15:30:00.000", noZone(previousDate.toString()));
    
    tu = new Period(PeriodType.QUARTER, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-03-31T15:30:00.000", noZone(previousDate.toString()));
    
    tu = new Period(PeriodType.MONTH, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    tu = new Period(PeriodType.WEEK, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    //Advances to the end of the week so not 04-24
    assertEquals("2009-04-25T15:30:00.000", noZone(previousDate.toString()));
    
    tu = new Period(PeriodType.DAY, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    testDate = new DateTime(2009, 5, 1, 8, 30, 0, 999);
    tu = new Period(PeriodType.HOUR, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    //Tests rollunder
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
    
    testDate = new DateTime(2009, 5, 1, 9, 30, 0, 999);
    tu = new Period(PeriodType.HOUR, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-05-01T08:30:00.000", noZone(previousDate.toString()));
    
    tu = new Period(PeriodType.MINUTE, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-05-01T09:29:00.000", noZone(previousDate.toString()));
    
    tu = new Period(PeriodType.SECOND, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-05-01T09:29:59.000", noZone(previousDate.toString()));
    
    //Test recession to preceding week
    testDate = new DateTime(2009, 5, 1, 12, 0, 0, 999);//Friday, May 1st
    tradingWeek = getTestTradingWeek(TEST3); //Trading Week includes only Tue, Wed, Thur
    tu = new Period(PeriodType.DAY, 1);
    previousDate = tradingWeek.getPreviousSessionDate(testDate, tu);
    assertEquals("2009-04-30T15:30:00.000", noZone(previousDate.toString()));
}