From 53e36c62b64cb320185fbe1c80bb09c9098cd4c2 Mon Sep 17 00:00:00 2001 From: Travis Keep Date: Thu, 30 Jan 2014 18:21:57 +0000 Subject: [PATCH] ICU-10640 Add tests to be sure that TimeUnitFormat and CurrencyFormat are stand-ins for MeasureFormat. X-SVN-Rev: 35037 --- .../icu/dev/test/format/MeasureUnitTest.java | 14 ++++++++++++++ .../ibm/icu/dev/test/format/TimeUnitTest.java | 18 ++++++++++++++++++ 2 files changed, 32 insertions(+) diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MeasureUnitTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MeasureUnitTest.java index 842acf478e..6fa0625439 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MeasureUnitTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/MeasureUnitTest.java @@ -28,6 +28,7 @@ import com.ibm.icu.dev.test.serializable.SerializableTest; import com.ibm.icu.impl.Utility; import com.ibm.icu.math.BigDecimal; import com.ibm.icu.text.MeasureFormat; +import com.ibm.icu.text.TimeUnitFormat; import com.ibm.icu.text.MeasureFormat.FormatWidth; import com.ibm.icu.text.NumberFormat; import com.ibm.icu.util.Currency; @@ -562,6 +563,19 @@ public class MeasureUnitTest extends TestFmwk { assertEquals("FormatWidth.NUMERIC", 3, FormatWidth.NUMERIC.ordinal()); } + public void testCurrencyFormatStandInForMeasureFormat() { + MeasureFormat mf = MeasureFormat.getCurrencyFormat(ULocale.ENGLISH); + assertEquals( + "70 feet, 5.3 inches", + "70 feet, 5.3 inches", + mf.formatMeasures( + new Measure(70, MeasureUnit.FOOT), + new Measure(5.3, MeasureUnit.INCH))); + assertEquals("getLocale", ULocale.ENGLISH, mf.getLocale()); + assertEquals("getNumberFormat", ULocale.ENGLISH, mf.getNumberFormat().getLocale(ULocale.VALID_LOCALE)); + assertEquals("getWidth", MeasureFormat.FormatWidth.WIDE, mf.getWidth()); + } + static void generateCXXHConstants() { Map seen = new HashMap(); TreeMap> allUnits = new TreeMap>(); diff --git a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java index 674fa1192e..b7096e9099 100644 --- a/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java +++ b/icu4j/main/tests/core/src/com/ibm/icu/dev/test/format/TimeUnitTest.java @@ -15,6 +15,8 @@ import com.ibm.icu.math.BigDecimal; import com.ibm.icu.text.MeasureFormat; import com.ibm.icu.text.NumberFormat; import com.ibm.icu.text.TimeUnitFormat; +import com.ibm.icu.util.Measure; +import com.ibm.icu.util.MeasureUnit; import com.ibm.icu.util.TimeUnit; import com.ibm.icu.util.TimeUnitAmount; import com.ibm.icu.util.ULocale; @@ -379,6 +381,22 @@ public class TimeUnitTest extends TestFmwk { tuf1.parseObject("", new ParsePosition(0)); } + 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()); + } + private void verifyEqualsHashCode(Object o, Object eq, Object ne) { assertEquals("verifyEqualsHashCodeSame", o, o); assertEquals("verifyEqualsHashCodeEq", o, eq);