001    package org.hackystat.utilities.time.period;
002    
003    import java.util.Locale;
004    
005    import junit.framework.TestCase;
006    
007    /**
008     * Tests the Week implementation.
009     * 
010     * @author Hongbing Kou
011     * @version $Id: TestWeek.java,v 1.1.1.1 2005/10/20 23:56:44 johnson Exp $
012     */
013    public class TestWeek  extends TestCase {
014      /**
015       * Test week constructor.
016       * 
017       * @throws Exception If error in test. 
018       */
019      public void testWeek() throws Exception {
020        Day day = Day.getInstance(2004, 0, 1);
021        
022        Week week = new Week(day);
023        assertEquals("First day of the week", Day.getInstance(2003, 11, 28), week.getFirstDay());
024        assertEquals("Last  day of the week", Day.getInstance(2004, 0, 3), week.getLastDay());
025        if (Locale.getDefault().getLanguage().equals("en")) {
026          assertEquals("Check the toString method ", "28-Dec-2003 to 03-Jan-2004", 
027              week.getWeekRepresentation());
028          assertEquals("Check the toString method ", "03-Jan-2004", week.toString());
029        }
030    
031        Week week2 = new Week(Day.getInstance(2003, 11, 20));
032        assertTrue("Checking the comparison method", week.compareTo(week2) > 0);
033    
034        Week week3 = new Week(Day.getInstance(2003, 11, 30));
035        assertEquals("Checking the comparison method", 0, week.compareTo(week3));
036    
037        Week week4 = new Week(Day.getInstance(2004, 0, 4));
038        assertTrue("Checking the comparison method", week.compareTo(week4) < 0);
039      }
040      
041      /**
042       * Test week methods.
043       */
044      public void testWeek2 () {
045        Week week = new Week(Day.getInstance(2003, 10, 10));
046        
047        if (Locale.getDefault().getLanguage().equals("en")) {
048          assertEquals("Checks week's getWeekRepresentation() method", "09-Nov-2003 to 15-Nov-2003", 
049              week.getWeekRepresentation());
050          assertEquals("Checks week's toString() method", "15-Nov-2003", week.toString());
051        }
052        Week prev = new Week(Day.getInstance(2003, 10, 3));
053        assertEquals("Checks method previous()", prev, week.dec());
054      
055        Week next = new Week(Day.getInstance(2003, 10, 17));
056        assertEquals("Checks method next()", next, week.inc());
057      }
058      
059      /**
060       * Tests days in this week.
061       */
062      public void testWeeks() {
063        Week week = new Week(Day.getInstance(2004, 0, 1));
064        assertEquals("Test number of days in week by weeks' list", 7, week.getDays().size());     
065      }
066    }