Search in sources :

Example 11 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestCheckFrozen.

/* Tests the method
     *    private void checkFrozen()
     * from public void setDateTimeFormat(String dateTimeFormat)
     */
@Test
public void TestCheckFrozen() {
    // Tests when "if (isFrozen())" is true
    DateTimePatternGenerator dt = DateTimePatternGenerator.getInstance();
    try {
        dt.freeze();
        dt.setDateTimeFormat("MMDDYYYY");
        errln("DateTimePatternGenerator.checkFrozen() was suppose to " + "return an exception when trying to setDateTimeFormat " + "for a frozen object.");
    } catch (Exception e) {
    }
    dt = dt.cloneAsThawed();
}
Also used : DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Example 12 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestGetBaseSkeleton.

/* Tests the method
     *        public String getBaseSkeleton(String pattern)
     */
@Test
public void TestGetBaseSkeleton() {
    DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance();
    String[] cases = { "MMDD", "MMMDD", "MMM-DD", "DD/MMM", "ddM", "MMMMd" };
    String[] results = { "MD", "MMMD", "MMMD", "MMMD", "Md", "MMMMd" };
    for (int i = 0; i < cases.length; i++) {
        if (!dtpg.getBaseSkeleton(cases[i]).equals(results[i])) {
            errln("DateTimePatternGenerator.getSkeleton(String) did " + "return the expected result when passing " + cases[i] + " and expected " + results[i] + " but got " + dtpg.getBaseSkeleton(cases[i]));
        }
    }
}
Also used : DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Example 13 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestGetRedundants.

/* Tests the method
     *        public Collection<String> getRedundants(Collection<String> output)
     */
@Test
public void TestGetRedundants() {
    DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance();
    // Tests when "if (output == null)" is true
    try {
        dtpg.getRedundants(null);
    } catch (Exception e) {
        errln("DateTimeGenerator.getRedundants was not supposed to return " + "an exception when passing a null parameter: " + e);
    }
    // Tests when "if (output == null)" is false
    try {
        Collection<String> out = new LinkedHashSet<String>();
        dtpg.getRedundants(out);
    } catch (Exception e) {
        errln("DateTimeGenerator.getRedundants was not supposed to return " + "an exception when passing a new LinkedHashSet<String>() parameter: " + e);
    }
}
Also used : LinkedHashSet(java.util.LinkedHashSet) DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Example 14 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestClone.

/* Tests the method
     *    public Object clone()
     */
@Test
public void TestClone() {
    DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance();
    DateTimePatternGenerator dtpg2 = (DateTimePatternGenerator) dtpg.clone();
    dtpg = (DateTimePatternGenerator) dtpg2.clone();
}
Also used : DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator) Test(org.junit.Test)

Example 15 with DateTimePatternGenerator

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

the class DateTimeGeneratorTest method TestGetCanonicalSkeletonAllowingDuplicates.

/* Tests the method
     *        public String getCanonicalSkeletonAllowingDuplicates(String pattern)
     */
public void TestGetCanonicalSkeletonAllowingDuplicates() {
    DateTimePatternGenerator dtpg = DateTimePatternGenerator.getInstance();
    String[] cases = { "GyQMwEdaHmsSv", "LegH", "Legh" };
    String[] results = { "GyQMwEdHmsSv", "MEdH", "MEdh" };
    for (int i = 0; i < cases.length; i++) {
        if (!dtpg.getCanonicalSkeletonAllowingDuplicates(cases[i]).equals(results[i])) {
            errln("DateTimePatternGenerator.getCanonicalSkeletonAllowingDuplicates(String) did " + "return the expected result when passing " + cases[i] + " and expected " + results[i] + " but got " + dtpg.getCanonicalSkeletonAllowingDuplicates(cases[i]));
        }
    }
}
Also used : DateTimePatternGenerator(android.icu.text.DateTimePatternGenerator)

Aggregations

DateTimePatternGenerator (android.icu.text.DateTimePatternGenerator)28 Test (org.junit.Test)27 SimpleDateFormat (android.icu.text.SimpleDateFormat)6 ULocale (android.icu.util.ULocale)6 SimpleTimeZone (android.icu.util.SimpleTimeZone)3 TimeZone (android.icu.util.TimeZone)3 Date (java.util.Date)3 LinkedHashSet (java.util.LinkedHashSet)2 Calendar (android.icu.util.Calendar)1 GregorianCalendar (android.icu.util.GregorianCalendar)1 ParsePosition (java.text.ParsePosition)1 HashSet (java.util.HashSet)1 LinkedHashMap (java.util.LinkedHashMap)1