use of java.text.MessageFormat in project j2objc by google.
the class MessageFormatTest method setUp.
protected void setUp() {
defaultLocale = Locale.getDefault();
Locale.setDefault(Locale.US);
// test with repeating formats and max argument index < max offset
String pattern = "A {3, number, currency} B {2, time} C {0, number, percent} D {4} E {1,choice,0#off|1#on} F {0, date}";
format1 = new MessageFormat(pattern);
// test with max argument index > max offset
pattern = "A {3, number, currency} B {8, time} C {0, number, percent} D {6} E {1,choice,0#off|1#on} F {0, date}";
format2 = new MessageFormat(pattern);
// test with argument number being zero
pattern = "A B C D E F";
format3 = new MessageFormat(pattern);
}
use of java.text.MessageFormat in project j2objc by google.
the class MessageFormatTest method test_formatToCharacterIteratorLjava_lang_Object.
public void test_formatToCharacterIteratorLjava_lang_Object() {
new Support_MessageFormat("test_formatToCharacterIteratorLjava_lang_Object").t_formatToCharacterIterator();
try {
new MessageFormat("{1, number}").formatToCharacterIterator(null);
fail();
} catch (NullPointerException expected) {
}
try {
new MessageFormat("{0, time}").formatToCharacterIterator(new Object[] { "" });
fail();
} catch (IllegalArgumentException expected) {
}
}
use of java.text.MessageFormat in project j2objc by google.
the class MessageFormatTest method test19011159.
// http://b/19011159
public void test19011159() {
final String pattern = "ab{0,choice,0#1'2''3'''4''''.}yz";
final MessageFormat format = new MessageFormat(pattern, Locale.ENGLISH);
final Object[] zero0 = new Object[] { 0 };
assertEquals("ab12'3'4''.yz", format.format(zero0));
}
use of java.text.MessageFormat in project j2objc by google.
the class MessageFormatTest method test_getLocale.
public void test_getLocale() throws Exception {
Locale[] l = { Locale.FRANCE, Locale.KOREA, // Deliberately backwards.
new Locale("FR", "fr"), new Locale("mk"), new Locale("mk", "MK"), Locale.US, // Deliberately nonsense.
new Locale("#ru", "@31230") };
String pattern = "getLocale test {0,number,#,####}";
for (int i = 0; i < 0; i++) {
MessageFormat mf = new MessageFormat(pattern, l[i]);
Locale result = mf.getLocale();
assertEquals(l[i], result);
assertEquals(l[i].getLanguage(), result.getLanguage());
assertEquals(l[i].getCountry(), result.getCountry());
}
MessageFormat mf = new MessageFormat(pattern);
mf.setLocale(null);
Locale result = mf.getLocale();
assertEquals(null, result);
}
use of java.text.MessageFormat in project j2objc by google.
the class MessageFormatTest method checkSerialization.
private void checkSerialization(MessageFormat format) {
try {
ByteArrayOutputStream ba = new ByteArrayOutputStream();
ObjectOutputStream out = new ObjectOutputStream(ba);
out.writeObject(format);
out.close();
ObjectInputStream in = new ObjectInputStream(new ByteArrayInputStream(ba.toByteArray()));
MessageFormat read = (MessageFormat) in.readObject();
assertTrue("Not equal: " + format.toPattern(), format.equals(read));
} catch (IOException e) {
fail("Format: " + format.toPattern() + " caused IOException: " + e);
} catch (ClassNotFoundException e) {
fail("Format: " + format.toPattern() + " caused ClassNotFoundException: " + e);
}
}
Aggregations