// test with repeating formats and max argument index < max offset
// compare getFormatsByArgumentIndex() results after calls to
// setFormatsByArgumentIndex(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.setFormatsByArgumentIndex(correctFormats);
Format[] formats = f1.getFormatsByArgumentIndex();
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();
Format[] inputFormats = new Format[] { DateFormat.getDateInstance(),
new ChoiceFormat("0#off|1#on"),
NumberFormat.getPercentInstance(),
NumberFormat.getCurrencyInstance(),
DateFormat.getTimeInstance(), null, null, null,
DateFormat.getTimeInstance() };
f2.setFormatsByArgumentIndex(inputFormats);
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 = new Format[] { NumberFormat.getCurrencyInstance(),
DateFormat.getTimeInstance(), DateFormat.getDateInstance(),
null, new ChoiceFormat("0#off|1#on"),
DateFormat.getDateInstance() };
assertEquals("Test2C:Returned wrong number of formats:",
correctFormats.length, formats.length);
for (int i = 0; i < correctFormats.length; i++) {