/*
 * Created on Nov 2, 2003
 *
 * To change the template for this generated file go to
 * Window&gt;Preferences&gt;Java&gt;Code Generation&gt;Code and Comments
 */
package jrequest.test;

import java.text.*;
import java.util.Date;

import jrequest.base.User;
import junit.framework.TestCase;

/**
 * UserTest
 * 
 * @author oliver
 * @since  Nov 2, 2003
 */
public class UserTest extends TestCase {
    
    private User hugo;

    public static void main(String[] args) {
        junit.textui.TestRunner.run(UserTest.class);
    }
    
    public void setUp() throws Exception {
        super.setUp();
        hugo = new User("Hugo");
    }

    public void testUser() {
        User oliver = new User("Oliver");
        assertEquals("Oliver", oliver.getName());
    }

    public void testSetName() {
        User brutus = new User("Julius");
        brutus.setName("Brutus");
        assertEquals("Brutus", brutus.getName());
    }
    
    public void testBirthWithDate() {
        Date date = new Date(1L);
        hugo.setBirth(date);
        assertEquals(date, hugo.getBirth());
    }
    
    public void testBirthWithString() throws ParseException {
        String date = "24.02.1961";
        hugo.setBirth(date);
        assertEquals(new SimpleDateFormat("dd.MM.yyyy").parse(date), hugo.getBirth());
    }
    
    public void testBirthWithLong() {
        long time = 500;
        hugo.setBirth(time);
        assertEquals(new Date(time), hugo.getBirth());
    }
    
    public void testBirthWithYearMonthDay() throws ParseException {
        hugo.setBirth(1970, 1, 31);
        User nobody = new User("Nobody");
        nobody.setBirth("31.01.1970");
        assertEquals(nobody.getBirth(), hugo.getBirth());
    }
    
    public void testBirthWithTime() throws ParseException {
        hugo.setBirth(1972, 2, 29, 11, 55);
        assertEquals(
            new SimpleDateFormat("dd.MM.yyyy HH:mm").parse("29.02.1972 11:55"),
            hugo.getBirth());
    }
    
    public void testToString() {
        User cicero = new User("Cicero");
        assertNotNull(cicero.toString());
    }
    
    public void testCompareTo() {
        assertEquals(0, hugo.compareTo("Hugo"));
        assertTrue(hugo.compareTo("Goofy") > 0);
        assertTrue(hugo.compareTo("Micky") < 0);
    }

}
