Search in sources :

Example 6 with IllegalFormatConversionException

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());
}
Also used : IllegalFormatConversionException(java.util.IllegalFormatConversionException)

Example 7 with IllegalFormatConversionException

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());
}
Also used : IllegalFormatCodePointException(java.util.IllegalFormatCodePointException) FormatFlagsConversionMismatchException(java.util.FormatFlagsConversionMismatchException) IllegalFormatPrecisionException(java.util.IllegalFormatPrecisionException) Formatter(java.util.Formatter) IllegalFormatConversionException(java.util.IllegalFormatConversionException) Date(java.util.Date)

Example 8 with IllegalFormatConversionException

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) {
    }
}
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)

Aggregations

IllegalFormatConversionException (java.util.IllegalFormatConversionException)8 FormatFlagsConversionMismatchException (java.util.FormatFlagsConversionMismatchException)3 Formatter (java.util.Formatter)3 BigInteger (java.math.BigInteger)2 Date (java.util.Date)2 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)2 IllegalFormatPrecisionException (java.util.IllegalFormatPrecisionException)2 MissingFormatWidthException (java.util.MissingFormatWidthException)2 UnknownFormatConversionException (java.util.UnknownFormatConversionException)2 DatePickerDialog (android.app.DatePickerDialog)1 Context (android.content.Context)1 ContextWrapper (android.content.ContextWrapper)1 Resources (android.content.res.Resources)1 PrintWriter (java.io.PrintWriter)1 StringWriter (java.io.StringWriter)1 BigDecimal (java.math.BigDecimal)1 Calendar (java.util.Calendar)1 HashMap (java.util.HashMap)1 IllegalFormatCodePointException (java.util.IllegalFormatCodePointException)1 Map (java.util.Map)1