*/
public void Test4031438() {
String pattern1 = "Impossible {1} has occurred -- status code is {0} and message is {2}.";
String pattern2 = "Double '' Quotes {0} test and quoted '{1}' test plus 'other {2} stuff'.";
MessageFormat messageFormatter = new MessageFormat("");
try {
logln("Apply with pattern : " + pattern1);
messageFormatter.applyPattern(pattern1);
Object[] paramArray = {new Integer(7)};
String tempBuffer = messageFormatter.format(paramArray);
if (!tempBuffer.equals("Impossible {1} has occurred -- status code is 7 and message is {2}."))
errln("Tests arguments < substitution failed");
logln("Formatted with 7 : " + tempBuffer);
ParsePosition status = new ParsePosition(0);
Object[] objs = messageFormatter.parse(tempBuffer, status);
if (objs[paramArray.length] != null)
errln("Parse failed with more than expected arguments");
for (int i = 0; i < objs.length; i++) {
if (objs[i] != null && !objs[i].toString().equals(paramArray[i].toString())) {
errln("Parse failed on object " + objs[i] + " at index : " + i);
}
}
tempBuffer = messageFormatter.format(null);
if (!tempBuffer.equals("Impossible {1} has occurred -- status code is {0} and message is {2}."))
errln("Tests with no arguments failed");
logln("Formatted with null : " + tempBuffer);
logln("Apply with pattern : " + pattern2);
messageFormatter.applyPattern(pattern2);
tempBuffer = messageFormatter.format(paramArray);
if (!tempBuffer.equals("Double ' Quotes 7 test and quoted {1} test plus other {2} stuff."))
errln("quote format test (w/ params) failed.");
logln("Formatted with params : " + tempBuffer);
tempBuffer = messageFormatter.format(null);
if (!tempBuffer.equals("Double ' Quotes {0} test and quoted {1} test plus other {2} stuff."))
errln("quote format test (w/ null) failed.");
logln("Formatted with null : " + tempBuffer);
logln("toPattern : " + messageFormatter.toPattern());
} catch (Exception foo) {
warnln("Exception when formatting in bug 4031438. "+foo.getMessage());
}
}