use of java.util.MissingFormatWidthException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalConversionException.
/**
* java.util.Formatter#format(String, Object...) for exceptions in
* Float/Double/BigDecimal conversion type 'e', 'E', 'g', 'G', 'f', 'a', 'A'
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalConversionException() {
Formatter f = null;
final char[] conversions = { 'e', 'E', 'g', 'G', 'f', 'a', 'A' };
final Object[] illArgs = { false, (byte) 1, (short) 2, 3, (long) 4, new BigInteger("5"), new Character('c'), new Object(), new Date() };
for (int i = 0; i < illArgs.length; i++) {
for (int j = 0; j < conversions.length; j++) {
try {
f = new Formatter(Locale.UK);
f.format("%" + conversions[j], illArgs[i]);
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
}
}
try {
f = new Formatter(Locale.UK);
f.format("%a", new BigDecimal(1));
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
try {
f = new Formatter(Locale.UK);
f.format("%A", new BigDecimal(1));
fail("should throw IllegalFormatConversionException");
} catch (IllegalFormatConversionException e) {
// expected
}
final String[] flagsConversionMismatches = { "%,e", "%,E", "%#g", "%#G", "%,a", "%,A", "%(a", "%(A" };
for (int i = 0; i < flagsConversionMismatches.length; i++) {
try {
f = new Formatter(Locale.CHINA);
f.format(flagsConversionMismatches[i], new BigDecimal(1));
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
f = new Formatter(Locale.JAPAN);
f.format(flagsConversionMismatches[i], (BigDecimal) null);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
}
final String[] missingFormatWidths = { "%-0e", "%0e", "%-e", "%-0E", "%0E", "%-E", "%-0g", "%0g", "%-g", "%-0G", "%0G", "%-G", "%-0f", "%0f", "%-f", "%-0a", "%0a", "%-a", "%-0A", "%0A", "%-A" };
for (int i = 0; i < missingFormatWidths.length; i++) {
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], 1f);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
try {
f = new Formatter(Locale.KOREA);
f.format(missingFormatWidths[i], (Float) null);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
}
final String[] illFlags = { "%+ e", "%+ E", "%+ g", "%+ G", "%+ f", "%+ a", "%+ A", "%-03e", "%-03E", "%-03g", "%-03G", "%-03f", "%-03a", "%-03A" };
for (int i = 0; i < illFlags.length; i++) {
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], 1.23d);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
f = new Formatter(Locale.CANADA);
f.format(illFlags[i], (Double) null);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
}
f = new Formatter(Locale.US);
try {
f.format("%F", 1);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
use of java.util.MissingFormatWidthException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_BigDecimalExceptionOrder.
/**
* java.util.Formatter#format(String, Object...) for BigDecimal
* exception throwing order
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_BigDecimalExceptionOrder() {
Formatter f = null;
BigDecimal bd = new BigDecimal("1.0");
/*
* Summary: UnknownFormatConversionException >
* MissingFormatWidthException > IllegalFormatFlagsException >
* FormatFlagsConversionMismatchException >
* IllegalFormatConversionException
*
*/
try {
// compare FormatFlagsConversionMismatchException and
// IllegalFormatConversionException
f = new Formatter(Locale.US);
f.format("%,e", (byte) 1);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
// compare IllegalFormatFlagsException and
// FormatFlagsConversionMismatchException
f = new Formatter(Locale.US);
f.format("%+ ,e", bd);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
// compare MissingFormatWidthException and
// IllegalFormatFlagsException
f = new Formatter(Locale.US);
f.format("%+ -e", bd);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
// MissingFormatWidthException
try {
f = new Formatter(Locale.US);
f.format("%-F", bd);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
use of java.util.MissingFormatWidthException in project j2objc by google.
the class MissingFormatWidthExceptionTest method test_getMessage.
/**
* java.util.MissingFormatWidthException#getMessage()
*/
public void test_getMessage() {
String s = "MYTESTSTRING";
MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(s);
assertTrue(null != missingFormatWidthException.getMessage());
}
use of java.util.MissingFormatWidthException in project j2objc by google.
the class MissingFormatWidthExceptionTest method test_getFormatSpecifier.
/**
* java.util.MissingFormatWidthException#getFormatSpecifier()
*/
public void test_getFormatSpecifier() {
String s = "MYTESTSTRING";
MissingFormatWidthException missingFormatWidthException = new MissingFormatWidthException(s);
assertEquals(s, missingFormatWidthException.getFormatSpecifier());
}
use of java.util.MissingFormatWidthException in project j2objc by google.
the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalExceptionOrder.
/**
* java.util.Formatter#format(String, Object...) for
* Float/Double/BigDecimal exception throwing order
*/
public void test_formatLjava_lang_String$Ljava_lang_Object_FloatDoubleBigDecimalExceptionOrder() {
Formatter f = null;
/*
* Summary: UnknownFormatConversionException >
* MissingFormatWidthException > IllegalFormatFlagsException >
* FormatFlagsConversionMismatchException >
* IllegalFormatConversionException
*
*/
try {
// compare FormatFlagsConversionMismatchException and
// IllegalFormatConversionException
f = new Formatter(Locale.US);
f.format("%,e", (byte) 1);
fail("should throw FormatFlagsConversionMismatchException");
} catch (FormatFlagsConversionMismatchException e) {
// expected
}
try {
// compare IllegalFormatFlagsException and
// FormatFlagsConversionMismatchException
f = new Formatter(Locale.US);
f.format("%+ ,e", 1f);
fail("should throw IllegalFormatFlagsException");
} catch (IllegalFormatFlagsException e) {
// expected
}
try {
// compare MissingFormatWidthException and
// IllegalFormatFlagsException
f = new Formatter(Locale.US);
f.format("%+ -e", 1f);
fail("should throw MissingFormatWidthException");
} catch (MissingFormatWidthException e) {
// expected
}
try {
// compare UnknownFormatConversionException and
// MissingFormatWidthException
f = new Formatter(Locale.US);
f.format("%-F", 1f);
fail("should throw UnknownFormatConversionException");
} catch (UnknownFormatConversionException e) {
// expected
}
}
Aggregations