/** * @tests java.text.MessageFormat#getLocale() Test of method java.text.MessageFormat#getLocale(). */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "getLocale", args = {}) public void test_getLocale() { try { Locale[] l = { Locale.FRANCE, Locale.KOREA, new Locale(Locale.FRANCE.getCountry(), Locale.FRANCE.getLanguage()), new Locale("mk"), new Locale("mk", "MK"), Locale.US, new Locale("#ru", "@31230") }; String pattern = "getLocale test {0,number,#,####}"; MessageFormat mf; for (int i = 0; i < 0; i++) { mf = new MessageFormat(pattern, l[i]); Locale result = mf.getLocale(); assertEquals("Returned local: " + result + " instead of " + l[i], l[i], result); assertEquals( "Returned language: " + result.getLanguage() + " instead of " + l[i].getLanguage(), l[i].getLanguage(), result.getLanguage()); assertEquals( "Returned country: " + result.getCountry() + " instead of " + l[i].getCountry(), l[i].getCountry(), result.getCountry()); } mf = new MessageFormat(pattern); mf.setLocale(null); Locale result = mf.getLocale(); assertEquals("Returned local: " + result + " instead of null", null, result); } catch (Exception e) { fail("unexpected exception " + e.toString()); } }
/** @tests java.text.MessageFormat#setLocale(java.util.Locale) */ @TestTargetNew( level = TestLevel.COMPLETE, notes = "", method = "setLocale", args = {java.util.Locale.class}) public void test_setLocaleLjava_util_Locale() { // Test for method void // java.text.MessageFormat.setLocale(java.util.Locale) MessageFormat format = new MessageFormat("date {0,date}"); format.setLocale(Locale.CHINA); assertEquals("Wrong locale1", Locale.CHINA, format.getLocale()); format.applyPattern("{1,date}"); assertEquals( "Wrong locale3", DateFormat.getDateInstance(DateFormat.DEFAULT, Locale.CHINA), format.getFormats()[0]); }
/** @tests java.text.MessageFormat#MessageFormat(java.lang.String, java.util.Locale) */ @TestTargetNew( level = TestLevel.PARTIAL_COMPLETE, notes = "IllegalArgumentException is not verified.", method = "MessageFormat", args = {java.lang.String.class, java.util.Locale.class}) public void test_ConstructorLjava_lang_StringLjava_util_Locale() { // Test for method java.text.MessageFormat(java.lang.String, // java.util.Locale) Locale mk = new Locale("mk", "MK"); MessageFormat format = new MessageFormat( "Date: {0,date} Currency: {1, number, currency} Integer: {2, number, integer}", mk); assertTrue("Wrong locale1", format.getLocale().equals(mk)); assertTrue( "Wrong locale2", format.getFormats()[0].equals(DateFormat.getDateInstance(DateFormat.DEFAULT, mk))); assertTrue( "Wrong locale3", format.getFormats()[1].equals(NumberFormat.getCurrencyInstance(mk))); assertTrue("Wrong locale4", format.getFormats()[2].equals(NumberFormat.getIntegerInstance(mk))); }
/** * Gets the locale that's used when creating or comparing subformats. * * @return the locale used when creating or comparing subformats */ public Locale getLocale() { return inner.getLocale(); }