Search in sources :

Example 6 with FormatFlagsConversionMismatchException

use of java.util.FormatFlagsConversionMismatchException 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) {
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) FormatFlagsConversionMismatchException(java.util.FormatFlagsConversionMismatchException) IllegalFormatPrecisionException(java.util.IllegalFormatPrecisionException) Formatter(java.util.Formatter) BigInteger(java.math.BigInteger) IllegalFormatFlagsException(java.util.IllegalFormatFlagsException) MissingFormatWidthException(java.util.MissingFormatWidthException) IllegalFormatConversionException(java.util.IllegalFormatConversionException)

Example 7 with FormatFlagsConversionMismatchException

use of java.util.FormatFlagsConversionMismatchException in project j2objc by google.

the class FormatterTest method test_formatLjava_lang_String$Ljava_lang_Object_GeneralConversionException.

/**
     * java.util.Formatter#format(String, Object...) for general
     * conversion exception
     */
public void test_formatLjava_lang_String$Ljava_lang_Object_GeneralConversionException() {
    final String[] flagMismatch = { "%#b", "%+b", "% b", "%0b", "%,b", "%(b", "%#B", "%+B", "% B", "%0B", "%,B", "%(B", "%#h", "%+h", "% h", "%0h", "%,h", "%(h", "%#H", "%+H", "% H", "%0H", "%,H", "%(H", "%+s", "% s", "%0s", "%,s", "%(s", "%+S", "% S", "%0S", "%,S", "%(S" };
    Formatter f = new Formatter(Locale.US);
    for (int i = 0; i < flagMismatch.length; i++) {
        try {
            f.format(flagMismatch[i], "something");
            fail("should throw FormatFlagsConversionMismatchException");
        } catch (FormatFlagsConversionMismatchException e) {
        // expected
        }
    }
    final String[] missingWidth = { "%-b", "%-B", "%-h", "%-H", "%-s", "%-S" };
    for (int i = 0; i < missingWidth.length; i++) {
        try {
            f.format(missingWidth[i], "something");
            fail("should throw MissingFormatWidthException");
        } catch (MissingFormatWidthException e) {
        // expected
        }
    }
    // Regression test
    f = new Formatter();
    try {
        f.format("%c", (byte) -0x0001);
        fail("Should throw IllegalFormatCodePointException");
    } catch (IllegalFormatCodePointException e) {
    // expected
    }
    f = new Formatter();
    try {
        f.format("%c", (short) -0x0001);
        fail("Should throw IllegalFormatCodePointException");
    } catch (IllegalFormatCodePointException e) {
    // expected
    }
    f = new Formatter();
    try {
        f.format("%c", -0x0001);
        fail("Should throw IllegalFormatCodePointException");
    } catch (IllegalFormatCodePointException e) {
    // expected
    }
}
Also used : IllegalFormatCodePointException(java.util.IllegalFormatCodePointException) FormatFlagsConversionMismatchException(java.util.FormatFlagsConversionMismatchException) Formatter(java.util.Formatter) MissingFormatWidthException(java.util.MissingFormatWidthException)

Example 8 with FormatFlagsConversionMismatchException

use of java.util.FormatFlagsConversionMismatchException 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
    }
}
Also used : UnknownFormatConversionException(java.util.UnknownFormatConversionException) FormatFlagsConversionMismatchException(java.util.FormatFlagsConversionMismatchException) Formatter(java.util.Formatter) IllegalFormatFlagsException(java.util.IllegalFormatFlagsException) MissingFormatWidthException(java.util.MissingFormatWidthException)

Aggregations

FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)8 Formatter (java.util.Formatter)8 MissingFormatWidthException (java.util.MissingFormatWidthException)6 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)5 UnknownFormatConversionException (java.util.UnknownFormatConversionException)5 BigInteger (java.math.BigInteger)4 IllegalFormatConversionException (java.util.IllegalFormatConversionException)3 IllegalFormatPrecisionException (java.util.IllegalFormatPrecisionException)3 BigDecimal (java.math.BigDecimal)2 Date (java.util.Date)2 IllegalFormatCodePointException (java.util.IllegalFormatCodePointException)2 Formattable (java.util.Formattable)1 Locale (java.util.Locale)1