Search in sources :

Example 11 with MessageFormat

use of java.text.MessageFormat in project robovm by robovm.

the class OldMessageFormatTest method test_setFormats$Ljava_text_Format.

public void test_setFormats$Ljava_text_Format() {
    try {
        MessageFormat f1 = (MessageFormat) format1.clone();
        // case 1: Test with repeating formats and max argument index < max
        // offset
        // compare getFormats() results after calls to setFormats(Format[])
        Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), new ChoiceFormat("0#off|1#on"), DateFormat.getTimeInstance(), NumberFormat.getCurrencyInstance(), new ChoiceFormat("1#few|2#ok|3#a lot") };
        f1.setFormats(correctFormats);
        Format[] formats = f1.getFormats();
        assertTrue("Test1A:Returned wrong number of formats:", correctFormats.length <= formats.length);
        for (int i = 0; i < correctFormats.length; i++) {
            assertEquals("Test1B:wrong format for argument index " + i + ":", correctFormats[i], formats[i]);
        }
        // case 2: Try to pass null argument to setFormats().
        try {
            f1.setFormats(null);
            fail("Expected exception NullPointerException was not thrown");
        } catch (NullPointerException e) {
        // expected
        }
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
}
Also used : Format(java.text.Format) NumberFormat(java.text.NumberFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ChoiceFormat(java.text.ChoiceFormat) DateFormat(java.text.DateFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ChoiceFormat(java.text.ChoiceFormat) ParseException(java.text.ParseException)

Example 12 with MessageFormat

use of java.text.MessageFormat in project robovm by robovm.

the class OldMessageFormatTest method test_setFormatILjava_text_Format.

/**
     * java.text.MessageFormat#setFormat(int, Format) Test of method
     *        java.text.MessageFormat#setFormat(int, Format). Case 1: Compare
     *        getFormats() results after calls to setFormat(). Case 2: Try to
     *        call setFormat() using incorrect index.
     */
public void test_setFormatILjava_text_Format() {
    try {
        // case 1: Compare getFormats() results after calls to setFormat()
        MessageFormat f1 = (MessageFormat) format1.clone();
        f1.setFormat(0, DateFormat.getTimeInstance());
        f1.setFormat(1, DateFormat.getTimeInstance());
        f1.setFormat(2, NumberFormat.getInstance());
        f1.setFormat(3, new ChoiceFormat("0#off|1#on"));
        f1.setFormat(4, new ChoiceFormat("1#few|2#ok|3#a lot"));
        f1.setFormat(5, DateFormat.getTimeInstance());
        Format[] formats = f1.getFormats();
        formats = f1.getFormats();
        Format[] correctFormats = new Format[] { DateFormat.getTimeInstance(), DateFormat.getTimeInstance(), NumberFormat.getInstance(), new ChoiceFormat("0#off|1#on"), new ChoiceFormat("1#few|2#ok|3#a lot"), DateFormat.getTimeInstance() };
        assertEquals("Test1A:Returned wrong number of formats:", correctFormats.length, formats.length);
        for (int i = 0; i < correctFormats.length; i++) {
            assertEquals("Test1B:wrong format for pattern index " + i + ":", correctFormats[i], formats[i]);
        }
        // case 2: Try to setFormat using incorrect index
        try {
            f1.setFormat(-1, DateFormat.getDateInstance());
            fail("Expected ArrayIndexOutOfBoundsException was not thrown");
            f1.setFormat(f1.getFormats().length, DateFormat.getDateInstance());
            fail("Expected ArrayIndexOutOfBoundsException was not thrown");
        } catch (ArrayIndexOutOfBoundsException e) {
        // expected
        }
    } catch (Exception e) {
        fail("Unexpected exception " + e.toString());
    }
}
Also used : Format(java.text.Format) NumberFormat(java.text.NumberFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ChoiceFormat(java.text.ChoiceFormat) DateFormat(java.text.DateFormat) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ChoiceFormat(java.text.ChoiceFormat) ParseException(java.text.ParseException)

Example 13 with MessageFormat

use of java.text.MessageFormat in project robovm by robovm.

the class OldMessageFormatTest method test_parseLjava_lang_StringLjava_text_ParsePosition.

public void test_parseLjava_lang_StringLjava_text_ParsePosition() {
    ParsePosition pos = new ParsePosition(2);
    MessageFormat mf = new MessageFormat("{0}; {0}; {0}");
    String parse = "a; b; c";
    try {
        mf.parse(parse, null);
        fail("NullPointerException was not thrown.");
    } catch (NullPointerException npe) {
    //expected
    }
    try {
        mf.parse(null, pos);
    } catch (NullPointerException npe) {
        fail("NullPointerException was thrown.");
    }
}
Also used : MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ParsePosition(java.text.ParsePosition)

Example 14 with MessageFormat

use of java.text.MessageFormat in project robovm by robovm.

the class OldMessageFormatTest method test_getLocale.

public void test_getLocale() {
    try {
        Locale[] l = { Locale.FRANCE, Locale.KOREA, new Locale(Locale.FRANCE.getCountry(), Locale.FRANCE.getLanguage()), new Locale("mk"), new Locale("mk", "MK"), Locale.US, new Locale("#ru", "@31230") };
        String pattern = "getLocale test {0,number,#,####}";
        MessageFormat mf;
        for (int i = 0; i < 0; i++) {
            mf = new MessageFormat(pattern, l[i]);
            Locale result = mf.getLocale();
            assertEquals("Returned local: " + result + " instead of " + l[i], l[i], result);
            assertEquals("Returned language: " + result.getLanguage() + " instead of " + l[i].getLanguage(), l[i].getLanguage(), result.getLanguage());
            assertEquals("Returned country: " + result.getCountry() + " instead of " + l[i].getCountry(), l[i].getCountry(), result.getCountry());
        }
        mf = new MessageFormat(pattern);
        mf.setLocale(null);
        Locale result = mf.getLocale();
        assertEquals("Returned local: " + result + " instead of null", null, result);
    } catch (Exception e) {
        fail("unexpected exception " + e.toString());
    }
}
Also used : Locale(java.util.Locale) MessageFormat(java.text.MessageFormat) Support_MessageFormat(tests.support.Support_MessageFormat) ParseException(java.text.ParseException)

Example 15 with MessageFormat

use of java.text.MessageFormat in project robovm by robovm.

the class Support_MessageFormat method t_format_with_FieldPosition.

public void t_format_with_FieldPosition() {
    String pattern = "On {4,date} at {3,time}, he ate {2,number, integer} hamburger{2,choice,1#|1<s} and drank {1, number} litres of coke. That was {0,choice,1#just enough|1<more than enough} food!";
    MessageFormat format = new MessageFormat(pattern, Locale.US);
    Date date = new GregorianCalendar(2005, 1, 28, 14, 20, 16).getTime();
    Integer hamburgers = new Integer(8);
    Object[] objects = new Object[] { hamburgers, new Double(3.5), hamburgers, date, date };
    super.text = "On Feb 28, 2005 at 2:20:16 PM, he ate 8 hamburgers and drank 3.5 litres of coke. That was more than enough food!";
    // test with MessageFormat.Field.ARGUMENT
    t_FormatWithField(1, format, objects, null, Field.ARGUMENT, 3, 15);
    // test other format fields that are included in the formatted text
    t_FormatWithField(2, format, objects, null, DateFormat.Field.AM_PM, 0, 0);
    t_FormatWithField(3, format, objects, null, NumberFormat.Field.FRACTION, 0, 0);
    // test fields that are not included in the formatted text
    t_FormatWithField(4, format, objects, null, DateFormat.Field.ERA, 0, 0);
    t_FormatWithField(5, format, objects, null, NumberFormat.Field.EXPONENT_SIGN, 0, 0);
}
Also used : MessageFormat(java.text.MessageFormat) GregorianCalendar(java.util.GregorianCalendar) Date(java.util.Date)

Aggregations

MessageFormat (java.text.MessageFormat)237 CertificateException (java.security.cert.CertificateException)27 KeyStoreException (java.security.KeyStoreException)23 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)22 UnrecoverableKeyException (java.security.UnrecoverableKeyException)22 Date (java.util.Date)22 UnrecoverableEntryException (java.security.UnrecoverableEntryException)21 CertStoreException (java.security.cert.CertStoreException)21 X509Certificate (java.security.cert.X509Certificate)17 File (java.io.File)14 ArrayList (java.util.ArrayList)14 IOException (java.io.IOException)13 Format (java.text.Format)12 Support_MessageFormat (tests.support.Support_MessageFormat)12 Certificate (java.security.cert.Certificate)10 ChoiceFormat (java.text.ChoiceFormat)10 DateFormat (java.text.DateFormat)10 MissingResourceException (java.util.MissingResourceException)10 SimpleDateFormat (java.text.SimpleDateFormat)9 OpenClinicaSystemException (org.akaza.openclinica.exception.OpenClinicaSystemException)9