use of java.text.ChoiceFormat in project j2objc by google.
the class ChoiceFormatTest method testToPatternWithInfinities.
// http://b/19149384
public void testToPatternWithInfinities() {
final ChoiceFormat fmt = new ChoiceFormat("-∞<are negative|0<are fractions|1#is one|1.0<is 1+|∞<are many.");
assertEquals("-∞<are negative|0.0<are fractions|1.0#is one|1.0<is 1+|∞<are many.", fmt.toPattern());
}
use of java.text.ChoiceFormat in project j2objc by google.
the class MessageFormatTest method test_setFormatByArgumentIndexILjava_text_Format.
public void test_setFormatByArgumentIndexILjava_text_Format() {
// test for method setFormatByArgumentIndex(int, Format)
MessageFormat f1 = (MessageFormat) format1.clone();
f1.setFormatByArgumentIndex(0, DateFormat.getTimeInstance());
f1.setFormatByArgumentIndex(4, new ChoiceFormat("1#few|2#ok|3#a lot"));
// test with repeating formats and max argument index < max offset
// compare getFormatsByArgumentIndex() results after calls to
// setFormatByArgumentIndex()
Format[] formats = f1.getFormatsByArgumentIndex();
Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") };
assertEquals("Test1A:Returned wrong number of formats:", correctFormats.length, formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
}
// compare getFormats() results after calls to
// setFormatByArgumentIndex()
formats = f1.getFormats();
correctFormats = new Format[] { NumberFormat.getCurrencyInstance(), DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), new ChoiceFormat("1#few|2#ok|3#a lot"), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance() };
assertEquals("Test1C:Returned wrong number of formats:", correctFormats.length, formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test1D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
}
// test setting argumentIndexes that are not used
MessageFormat f2 = (MessageFormat) format2.clone();
f2.setFormatByArgumentIndex(2, NumberFormat.getPercentInstance());
f2.setFormatByArgumentIndex(4, DateFormat.getTimeInstance());
formats = f2.getFormatsByArgumentIndex();
correctFormats = format2.getFormatsByArgumentIndex();
assertEquals("Test2A:Returned wrong number of formats:", correctFormats.length, formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test2B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
}
formats = f2.getFormats();
correctFormats = format2.getFormats();
assertEquals("Test2C:Returned wrong number of formats:", correctFormats.length, formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test2D:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
}
// test exceeding the argumentIndex number
MessageFormat f3 = (MessageFormat) format3.clone();
f3.setFormatByArgumentIndex(1, NumberFormat.getCurrencyInstance());
formats = f3.getFormatsByArgumentIndex();
assertEquals("Test3A:Returned wrong number of formats:", 0, formats.length);
formats = f3.getFormats();
assertEquals("Test3B:Returned wrong number of formats:", 0, formats.length);
}
use of java.text.ChoiceFormat in project j2objc by google.
the class NumberFormatTest method test_setRoundingMode_Normal.
public void test_setRoundingMode_Normal() {
try {
// Create a subclass ChoiceFormat which doesn't support
// RoundingMode
ChoiceFormat choiceFormat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
((NumberFormat) choiceFormat).setRoundingMode(RoundingMode.CEILING);
fail("UnsupportedOperationException expected");
} catch (UnsupportedOperationException e) {
// expected
}
}
use of java.text.ChoiceFormat in project j2objc by google.
the class NumberFormatTest method test_setCurrencyLjava_util_Currency.
/**
* @tests java.text.NumberFormat#setCurrency(java.util.Currency)
*/
public void test_setCurrencyLjava_util_Currency() {
// Test for method void setCurrency(java.util.Currency)
// a subclass that supports currency formatting
Currency currA = Currency.getInstance("ARS");
NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
format.setCurrency(currA);
assertSame("Returned incorrect currency", currA, format.getCurrency());
// a subclass that doesn't support currency formatting
ChoiceFormat cformat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
try {
((NumberFormat) cformat).setCurrency(currA);
fail("Expected UnsupportedOperationException");
} catch (UnsupportedOperationException e) {
}
}
use of java.text.ChoiceFormat in project robovm by robovm.
the class OldMessageFormatTest method test_setFormats$Ljava_text_Format.
public void test_setFormats$Ljava_text_Format() {
try {
MessageFormat f1 = (MessageFormat) format1.clone();
// case 1: Test with repeating formats and max argument index < max
// offset
// compare getFormats() results after calls to setFormats(Format[])
Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") };
f1.setFormats(correctFormats);
Format[] formats = f1.getFormats();
assertTrue("Test1A:Returned wrong number of formats:", correctFormats.length <= formats.length);
for (int i = 0; i < correctFormats.length; i++) {
assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
}
// case 2: Try to pass null argument to setFormats().
try {
f1.setFormats(null);
fail("Expected exception NullPointerException was not thrown");
} catch (NullPointerException e) {
// expected
}
} catch (Exception e) {
fail("Unexpected exception " + e.toString());
}
}
Aggregations