Search in sources :

Example 1 with TimeUnitFormat

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

the class TimeUnitTest method TestStandInForMeasureFormat.

@Test
public void TestStandInForMeasureFormat() {
    TimeUnitFormat tuf = new TimeUnitFormat(ULocale.FRENCH, TimeUnitFormat.ABBREVIATED_NAME);
    Measure measure = new Measure(23, MeasureUnit.CELSIUS);
    assertEquals("23 °C", "23 °C", tuf.format(measure));
    tuf = new TimeUnitFormat(ULocale.FRENCH, TimeUnitFormat.FULL_NAME);
    assertEquals("70 pied et 5,3 pouces", "70 pieds et 5,3 pouces", tuf.formatMeasures(new Measure(70, MeasureUnit.FOOT), new Measure(5.3, MeasureUnit.INCH)));
    assertEquals("getLocale", ULocale.FRENCH, tuf.getLocale());
    assertEquals("getNumberFormat", ULocale.FRENCH, tuf.getNumberFormat().getLocale(ULocale.VALID_LOCALE));
    assertEquals("getWidth", MeasureFormat.FormatWidth.WIDE, tuf.getWidth());
}
Also used : TimeUnitFormat(android.icu.text.TimeUnitFormat) Measure(android.icu.util.Measure) Test(org.junit.Test)

Example 2 with TimeUnitFormat

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

the class TimeUnitTest method TestEqHashCode.

@Test
public void TestEqHashCode() {
    TimeUnitFormat tf = new TimeUnitFormat(ULocale.ENGLISH, TimeUnitFormat.FULL_NAME);
    MeasureFormat tfeq = new TimeUnitFormat(ULocale.ENGLISH, TimeUnitFormat.FULL_NAME);
    MeasureFormat tfne = new TimeUnitFormat(ULocale.ENGLISH, TimeUnitFormat.ABBREVIATED_NAME);
    MeasureFormat tfne2 = new TimeUnitFormat(ULocale.GERMAN, TimeUnitFormat.FULL_NAME);
    verifyEqualsHashCode(tf, tfeq, tfne);
    verifyEqualsHashCode(tf, tfeq, tfne2);
}
Also used : TimeUnitFormat(android.icu.text.TimeUnitFormat) MeasureFormat(android.icu.text.MeasureFormat) Test(org.junit.Test)

Example 3 with TimeUnitFormat

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

the class TimeUnitTest method TestGetLocale.

@Test
public void TestGetLocale() {
    TimeUnitFormat tf = new TimeUnitFormat(ULocale.GERMAN);
    assertEquals("", ULocale.GERMAN, tf.getLocale(ULocale.VALID_LOCALE));
}
Also used : TimeUnitFormat(android.icu.text.TimeUnitFormat) Test(org.junit.Test)

Example 4 with TimeUnitFormat

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

the class TimeUnitTest method TestSetNumberFormat.

/*
     * Tests the method public TimeUnitFormat setNumberFormat(NumberFormat format)
     */
@Test
public void TestSetNumberFormat() {
    TimeUnitFormat tuf = new TimeUnitFormat();
    // Tests when "if (format == this.format)" is false
    // Tests when "if ( format == null )" is false
    tuf.setNumberFormat(NumberFormat.getInstance());
    // Tests when "if (format == this.format)" is true
    if (!tuf.setNumberFormat(NumberFormat.getInstance()).equals(tuf)) {
        errln("TimeUnitFormat.setNumberFormat(NumberFormat) was suppose to " + "return the same object when the same NumberFormat is passed.");
    }
    // Tests when "if ( locale == null )" is true
    if (!tuf.setNumberFormat(null).equals(tuf)) {
        errln("TimeUnitFormat.setNumberFormat(NumberFormat) was suppose to " + "return the same object when null is passed.");
    }
    TimeUnitFormat tuf1 = new TimeUnitFormat(new ULocale("en_US"));
    // Tests when "if ( locale == null )" is false
    tuf1.setNumberFormat(NumberFormat.getInstance());
    tuf1.setNumberFormat(null);
}
Also used : ULocale(android.icu.util.ULocale) TimeUnitFormat(android.icu.text.TimeUnitFormat) Test(org.junit.Test)

Example 5 with TimeUnitFormat

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

the class TimeUnitTest method TestGreekWithSanitization.

/**
 * @bug9042
 * Performs tests for Greek.
 * This tests that if the plural count listed in time unit format does not
 * match those in the plural rules for the locale, those plural count in
 * time unit format will be ingored and subsequently, fall back will kick in
 * which is tested above.
 * Without data sanitization, setNumberFormat() would crash.
 * As of CLDR shiped in ICU4.8, Greek is one such language.
 */
@Test
public void TestGreekWithSanitization() {
    ULocale loc = new ULocale("el");
    NumberFormat numfmt = NumberFormat.getInstance(loc);
    TimeUnitFormat tuf = new TimeUnitFormat(loc);
    tuf.parseObject("", new ParsePosition(0));
    tuf.setNumberFormat(numfmt);
}
Also used : ULocale(android.icu.util.ULocale) TimeUnitFormat(android.icu.text.TimeUnitFormat) NumberFormat(android.icu.text.NumberFormat) ParsePosition(java.text.ParsePosition) Test(org.junit.Test)

Aggregations

TimeUnitFormat (android.icu.text.TimeUnitFormat)15 Test (org.junit.Test)15 ULocale (android.icu.util.ULocale)7 TimeUnitAmount (android.icu.util.TimeUnitAmount)5 NumberFormat (android.icu.text.NumberFormat)3 ParseException (java.text.ParseException)3 ParsePosition (java.text.ParsePosition)3 TimeUnit (android.icu.util.TimeUnit)2 Locale (java.util.Locale)2 MeasureFormat (android.icu.text.MeasureFormat)1 Measure (android.icu.util.Measure)1 Ignore (org.junit.Ignore)1