Search in sources :

Example 1 with FormatterClosedException

use of java.util.FormatterClosedException in project robovm by robovm.

the class OldFormatterTest method test_formatLjava_util_LocaleLjava_lang_StringLjava_lang_Object.

public void test_formatLjava_util_LocaleLjava_lang_StringLjava_lang_Object() {
    Double val = new Double(3.14);
    Calendar cal = Calendar.getInstance();
    Formatter fLoc = null;
    Formatter fNoL = null;
    cal.set(2008, Calendar.SEPTEMBER, 23, 18, 30);
    fLoc = new Formatter(Locale.GERMAN);
    fNoL = new Formatter(Locale.GERMAN);
    fLoc.format(Locale.US, "%f", val);
    fNoL.format("%f", val);
    assertFalse(fLoc.toString().equals(fNoL.toString()));
    fLoc = new Formatter(Locale.FRANCE);
    fNoL = new Formatter(Locale.FRANCE);
    fLoc.format(Locale.US, "%f", val);
    fNoL.format("%f", val);
    assertFalse(fLoc.toString().equals(fNoL.toString()));
    fLoc = new Formatter(Locale.US);
    fNoL = new Formatter(Locale.US);
    fLoc.format(Locale.US, "%f", val);
    fNoL.format("%f", val);
    assertTrue(fLoc.toString().equals(fNoL.toString()));
    fLoc = new Formatter(Locale.GERMAN);
    fNoL = new Formatter(Locale.GERMAN);
    fLoc.format(Locale.US, "%tA %tB %td %tT", cal, cal, cal, cal);
    fNoL.format("%tA %tB %td %tT", cal, cal, cal, cal);
    assertFalse(fLoc.toString().equals(fNoL.toString()));
    fLoc = new Formatter(Locale.FRANCE);
    fNoL = new Formatter(Locale.FRANCE);
    fLoc.format(Locale.US, "%tA %tB %td %tT", cal, cal, cal, cal);
    fNoL.format("%tA %tB %td %tT", cal, cal, cal, cal);
    assertFalse(fLoc.toString().equals(fNoL.toString()));
    fLoc = new Formatter(Locale.US);
    fNoL = new Formatter(Locale.US);
    fLoc.format(Locale.US, "%tA %tB %td %tT", cal, cal, cal, cal);
    fNoL.format("%tA %tB %td %tT", cal, cal, cal, cal);
    assertTrue(fLoc.toString().equals(fNoL.toString()));
    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 {
            fLoc = new Formatter(Locale.US);
            fLoc.format(Locale.FRANCE, illFlags[i], 1.23d);
            fail("should throw IllegalFormatFlagsException");
        } catch (IllegalFormatFlagsException expected) {
        }
        try {
            fLoc = new Formatter(Locale.CANADA);
            fLoc.format(Locale.GERMAN, illFlags[i], (Double) null);
            fail("should throw IllegalFormatFlagsException");
        } catch (IllegalFormatFlagsException expected) {
        }
    }
    fLoc.close();
    try {
        fLoc.format(Locale.GERMAN, "%f", val);
        fail();
    } catch (FormatterClosedException expected) {
    }
}
Also used : Formatter(java.util.Formatter) Calendar(java.util.Calendar) FormatterClosedException(java.util.FormatterClosedException) IllegalFormatFlagsException(java.util.IllegalFormatFlagsException)

Example 2 with FormatterClosedException

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

the class FormatterTest method test_toString.

/**
 * java.util.Formatter#toString()
 */
public void test_toString() {
    Formatter f = new Formatter();
    assertNotNull(f.toString());
    assertEquals(f.out().toString(), f.toString());
    f.close();
    try {
        f.toString();
        fail("should throw FormatterClosedException");
    } catch (FormatterClosedException e) {
    // expected
    }
}
Also used : Formatter(java.util.Formatter) FormatterClosedException(java.util.FormatterClosedException)

Example 3 with FormatterClosedException

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

the class FormatterTest method test_locale.

/**
 * java.util.Formatter#locale()
 */
public void test_locale() {
    Formatter f = null;
    f = new Formatter((Locale) null);
    assertNull(f.locale());
    f.close();
    try {
        f.locale();
        fail("should throw FormatterClosedException");
    } catch (FormatterClosedException e) {
    // expected
    }
}
Also used : Locale(java.util.Locale) Formatter(java.util.Formatter) FormatterClosedException(java.util.FormatterClosedException)

Example 4 with FormatterClosedException

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

the class FormatterTest method test_out.

/**
 * java.util.Formatter#out()
 */
public void test_out() {
    Formatter f = null;
    f = new Formatter();
    assertNotNull(f.out());
    assertTrue(f.out() instanceof StringBuilder);
    f.close();
    try {
        f.out();
        fail("should throw FormatterClosedException");
    } catch (FormatterClosedException e) {
    // expected
    }
}
Also used : Formatter(java.util.Formatter) FormatterClosedException(java.util.FormatterClosedException)

Example 5 with FormatterClosedException

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

the class FormatterTest method test_flush.

/**
 * java.util.Formatter#flush()
 */
public void test_flush() throws IOException {
    Formatter f = null;
    f = new Formatter(notExist);
    assertTrue(f instanceof Flushable);
    f.close();
    try {
        f.flush();
        fail("should throw FormatterClosedException");
    } catch (FormatterClosedException e) {
    // expected
    }
    f = new Formatter();
    // For destination that does not implement Flushable
    // No exception should be thrown
    f.flush();
}
Also used : Formatter(java.util.Formatter) FormatterClosedException(java.util.FormatterClosedException) Flushable(java.io.Flushable)

Aggregations

Formatter (java.util.Formatter)5 FormatterClosedException (java.util.FormatterClosedException)5 Flushable (java.io.Flushable)1 Calendar (java.util.Calendar)1 IllegalFormatFlagsException (java.util.IllegalFormatFlagsException)1 Locale (java.util.Locale)1