FileDocCategorySizeDatePackage
TestDay.javaAPI DocApache Axis 1.44580Sat Apr 22 18:57:26 BST 2006test.types

TestDay

public class TestDay extends TestCase
Test validation of types.Day

Fields Summary
Constructors Summary
public TestDay(String name)

        super(name);
    
Methods Summary
private voidrunFailTest(int day, java.lang.String tz)
Run a failure test. values should be invalid.

        Day oDay = null;
        try {
            oDay = new Day(day, tz);
        }
        catch (Exception e) { // catch the validation exception
        }
        // object is not instantiated on bad data value
        assertNull("validation restriction failed [ day=" + String.valueOf(day) + 
                   ",tz=" + tz + "]. did not restrict bad value.", oDay);
    
private voidrunFailTest(java.lang.String source)

        Day oDay = null;
        try {
            oDay = new Day(source);
        }
        catch (Exception e) { // catch the validation exception
        }
        // object is not instantiated on bad data value
        assertNull("validation restriction failed [ " + source +
                 "]. did not restrict bad value.", oDay);
    
private voidrunPassTest(int day, java.lang.String tz)
Run a successful test. values should be valid.

        Day oDay = null;
        try {
            oDay = new Day(day, tz);
        }
        catch (Exception e) { // catch the validation exception
            assertTrue("Validation exception thrown on valid input", false);
        }
        assertEquals("Day day not equal", day, oDay.getDay());
        assertEquals("Day timezone not equal", tz, oDay.getTimezone());
    
private voidrunPassTest(java.lang.String source)

        Day oDay = null;
        try {
            oDay = new Day(source);
        }
        catch (Exception e) { // catch the validation exception
            assertTrue("Validation exception thrown on valid input", false);
        }
        assertEquals("Day.toString() not equal", source, oDay.toString());
    
public voidtestBadDay()
Test that a bad day fails

        runFailTest(32, null);
    
public voidtestBadDayString()

        runFailTest("---32");
    
public voidtestBadDayString2()

        runFailTest("---1");
    
public voidtestBadString()
Test that badly formatted strings fail

        runFailTest("13Z");
        runFailTest("-13");
        runFailTest("--13");
        runFailTest("xxx13");
        runFailTest("garbage");
    
public voidtestBadTimezone()
Test that a bad timezone fails

        runFailTest( 31, "badzone");
    
public voidtestBadTimezoneString()

        runFailTest("---23+EDT");
    
public voidtestNormal()
Test that a normal date succeeeds

        // test all days
        for (int d=1; d < 32; d++) {
            runPassTest(d, null);
        }
    
public voidtestNormalNegativeTimezone()

        runPassTest("---11-11:00");
    
public voidtestNormalPositiveTimezone()

        runPassTest("---11+05:00");
    
public voidtestNormalString()

        // test all 31 days
        // use NumberFormat to ensure leading zeros
        NumberFormat nf = NumberFormat.getInstance();
        nf.setMinimumIntegerDigits(2);
        for (int d=1; d < 13; d++) {
            String s = "---" + nf.format(d);
            runPassTest(s);
        }
    
public voidtestNormalString2()

        // check for leading zeros in toString().
        runPassTest("---01");
    
public voidtestNormalTimezone()

        runPassTest("---01Z");