use of java.util.IllegalFormatConversionException in project j2objc by google.
the class IllegalFormatConversionExceptionTest method test_getMessage.
/**
* java.util.IllegalFormatConversionException#getMessage()
*/
public void test_getMessage() {
char c = '*';
Class<String> argClass = String.class;
IllegalFormatConversionException illegalFormatConversionException = new IllegalFormatConversionException(c, argClass);
assertTrue(null != illegalFormatConversionException.getMessage());
}
use of java.util.IllegalFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_CharacterConversion.
/**
* java.util.Formatter#format(String, Object...) for Character
* conversion
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_CharacterConversion() {
Formatter f = new Formatter(Locale.US);
final Object[] illArgs = { Boolean.TRUE, new Float(1.1f), new Double(1.1d), "string content", new Float(1.1f), new Date() };
for (int i = 0; i < illArgs.length; i++) {
try {
f.format("%c", illArgs[i]);
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
}
try {
f.format("%c", Integer.MAX_VALUE);
fail("should throw IllegalFormatCodePointException");
} catch (IllegalFormatCodePointException e) {
// expected
}
try {
f.format("%#c", 'c');
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
final Object[][] triple = { { 'c', "%c", "c" }, { 'c', "%-2c", "c " }, { '\u0123', "%c", "\u0123" }, { '\u0123', "%-2c", "\u0123 " }, { (byte) 0x11, "%c", "\u0011" }, { (byte) 0x11, "%-2c", "\u0011 " }, { (short) 0x1111, "%c", "\u1111" }, { (short) 0x1111, "%-2c", "\u1111 " }, { 0x11, "%c", "\u0011" }, { 0x11, "%-2c", "\u0011 " } };
final int input = 0;
final int pattern = 1;
final int output = 2;
for (int i = 0; i < triple.length; i++) {
f = new Formatter(Locale.US);
f.format((String) triple[i][pattern], triple[i][input]);
assertEquals(triple[i][output], f.toString());
}
f = new Formatter(Locale.US);
f.format("%c", 0x10000);
assertEquals(0x10000, f.toString().codePointAt(0));
try {
f.format("%2.2c", 'c');
fail("should throw IllegalFormatPrecisionException");
} catch (IllegalFormatPrecisionException e) {
// expected
}
f = new Formatter(Locale.US);
f.format("%C", 'w');
// error on RI, throw UnknownFormatConversionException
// RI do not support converter 'C'
assertEquals("W", f.toString());
f = new Formatter(Locale.JAPAN);
f.format("%Ced", 0x1111);
// error on RI, throw UnknownFormatConversionException
// RI do not support converter 'C'
assertEquals("\u1111ed", f.toString());
}
use of java.util.IllegalFormatConversionException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerExceptionOrder.
/**
* java.util.Formatter#format(String, Object...) for BigInteger
* exception throwing order
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_BigIntegerExceptionOrder() {
Formatter f = null;
BigInteger big = new BigInteger("100");
/*
* Order summary: UnknownFormatConversionException >
* MissingFormatWidthException > IllegalFormatFlagsException >
* IllegalFormatPrecisionException > IllegalFormatConversionException >
* FormatFlagsConversionMismatchException
*
*/
f = new Formatter(Locale.US);
try {
f.format("%(o", false);
fail();
} catch (FormatFlagsConversionMismatchException expected) {
} catch (IllegalFormatConversionException expected) {
}
try {
f.format("%.4o", false);
fail();
} catch (IllegalFormatPrecisionException expected) {
} catch (IllegalFormatConversionException expected) {
}
try {
f.format("%+ .4o", big);
fail();
} catch (IllegalFormatPrecisionException expected) {
} catch (IllegalFormatFlagsException expected) {
}
try {
f.format("%+ -o", big);
fail();
} catch (MissingFormatWidthException expected) {
} catch (IllegalFormatFlagsException expected) {
}
try {
f.format("%-O", big);
fail();
} catch (MissingFormatWidthException expected) {
} catch (UnknownFormatConversionException expected) {
}
}
Aggregations