Search in sources :

Example 16 with DateIntervalInfo

use of android.icu.text.DateIntervalInfo in project j2objc by google.

the class DateIntervalFormatTest method TestSetFallbackIntervalPattern.

/* Tests the method
     *      public void setFallbackIntervalPattern(String fallbackPattern)
     */
@Test
public void TestSetFallbackIntervalPattern() {
    DateIntervalInfo dii = new DateIntervalInfo(new ULocale("en_US"));
    // Tests when "if ( frozen )" is true
    try {
        dii.freeze();
        dii.setFallbackIntervalPattern("");
        errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " + "was suppose to return an exception for a frozen object.");
    } catch (Exception e) {
    }
    // Tests when "if ( firstPatternIndex == -1 || secondPatternIndex == -1 )" is true
    dii = (DateIntervalInfo) dii.cloneAsThawed();
    try {
        dii.setFallbackIntervalPattern("");
        errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " + "was suppose to return an exception for a string object of ''.");
    } catch (Exception e) {
    }
    try {
        dii.setFallbackIntervalPattern("0");
        errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " + "was suppose to return an exception for a string object of 0.");
    } catch (Exception e) {
    }
    // Tests when "if ( firstPatternIndex > secondPatternIndex )" is true
    dii.setFallbackIntervalPattern("{1}{0}");
    if (dii.getDefaultOrder() != true)
        errln("DateIntervalInfo.setFallbackIntervalPattern(String fallbackPattern) " + "was suppose to change the variable 'fFirstDateInPtnIsLaterDate' " + "to true.");
}
Also used : ULocale(android.icu.util.ULocale) DateIntervalInfo(android.icu.text.DateIntervalInfo) ParseException(java.text.ParseException) Test(org.junit.Test)

Example 17 with DateIntervalInfo

use of android.icu.text.DateIntervalInfo in project j2objc by google.

the class DateIntervalFormatTest method TestT6396.

/*
     * Ticket#6396 DateIntervalInfo of ICU4J 4.0d3 throw NullPointerException 
     */
@Test
public void TestT6396() {
    DateIntervalInfo dii = new DateIntervalInfo(new ULocale("th_TH"));
    try {
        // ticket#6396 reported toString() throws NullPointerException
        String diiStr = dii.toString();
        logln("new DateIntervalInfo(new ULocale(\"th_TH\")).toString() - " + diiStr);
        // equals also had the similar problem
        DateIntervalInfo dii1 = (DateIntervalInfo) dii.clone();
        if (!dii.equals(dii1)) {
            errln("FAIL: Cloned DateIntervalInfo is not equal to the source");
        }
    } catch (Exception e) {
        errln("FAIL: Exception - " + e.getClass().getName());
    }
}
Also used : ULocale(android.icu.util.ULocale) DateIntervalInfo(android.icu.text.DateIntervalInfo) ParseException(java.text.ParseException) Test(org.junit.Test)

Aggregations

DateIntervalInfo (android.icu.text.DateIntervalInfo)17 Test (org.junit.Test)15 DateIntervalFormat (android.icu.text.DateIntervalFormat)9 ULocale (android.icu.util.ULocale)8 Calendar (android.icu.util.Calendar)7 ParseException (java.text.ParseException)7 DateInterval (android.icu.util.DateInterval)6 FieldPosition (java.text.FieldPosition)4 SimpleDateFormat (android.icu.text.SimpleDateFormat)3 DateFormat (android.icu.text.DateFormat)2 PatternInfo (android.icu.text.DateIntervalInfo.PatternInfo)2 Date (java.util.Date)2 Output (android.icu.util.Output)1 ParsePosition (java.text.ParsePosition)1