Search in sources :

Example 1 with ChoiceFormat

use of java.text.ChoiceFormat 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 2 with ChoiceFormat

use of java.text.ChoiceFormat 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 3 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class NumberFormatTest method test_setRoundingMode_Normal.

public void test_setRoundingMode_Normal() {
    try {
        // Create a subclass ChoiceFormat which doesn't support
        // RoundingMode
        ChoiceFormat choiceFormat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
        ((NumberFormat) choiceFormat).setRoundingMode(RoundingMode.CEILING);
        fail("UnsupportedOperationException expected");
    } catch (UnsupportedOperationException e) {
    // expected
    }
}
Also used : ChoiceFormat(java.text.ChoiceFormat) NumberFormat(java.text.NumberFormat)

Example 4 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class NumberFormatTest method test_setCurrencyLjava_util_Currency.

/**
     * @tests java.text.NumberFormat#setCurrency(java.util.Currency)
     */
public void test_setCurrencyLjava_util_Currency() {
    // Test for method void setCurrency(java.util.Currency)
    // a subclass that supports currency formatting
    Currency currA = Currency.getInstance("ARS");
    NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU"));
    format.setCurrency(currA);
    assertSame("Returned incorrect currency", currA, format.getCurrency());
    // a subclass that doesn't support currency formatting
    ChoiceFormat cformat = new ChoiceFormat("0#Less than one|1#one|1<Between one and two|2<Greater than two");
    try {
        ((NumberFormat) cformat).setCurrency(currA);
        fail("Expected UnsupportedOperationException");
    } catch (UnsupportedOperationException e) {
    }
}
Also used : Locale(java.util.Locale) Currency(java.util.Currency) ChoiceFormat(java.text.ChoiceFormat) NumberFormat(java.text.NumberFormat)

Example 5 with ChoiceFormat

use of java.text.ChoiceFormat in project j2objc by google.

the class ChoiceFormatTest method test_ConstructorLjava_lang_String.

/**
     * @tests java.text.ChoiceFormat#ChoiceFormat(java.lang.String)
     */
public void test_ConstructorLjava_lang_String() {
    // Test for method java.text.ChoiceFormat(java.lang.String)
    String formattedString;
    String patternString = "-2#Inverted Orange| 0#No Orange| 0<Almost No Orange| 1#Normal Orange| 2#Expensive Orange";
    ChoiceFormat cf = new ChoiceFormat(patternString);
    formattedString = cf.format(Double.NEGATIVE_INFINITY);
    assertTrue("a) Incorrect format returned: " + formattedString, formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-3);
    assertTrue("b) Incorrect format returned: " + formattedString, formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-2);
    assertTrue("c) Incorrect format returned: " + formattedString, formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-1);
    assertTrue("d) Incorrect format returned: " + formattedString, formattedString.equals("Inverted Orange"));
    formattedString = cf.format(-0);
    assertTrue("e) Incorrect format returned: " + formattedString, formattedString.equals("No Orange"));
    formattedString = cf.format(0);
    assertTrue("f) Incorrect format returned: " + formattedString, formattedString.equals("No Orange"));
    formattedString = cf.format(0.1);
    assertTrue("g) Incorrect format returned: " + formattedString, formattedString.equals("Almost No Orange"));
    formattedString = cf.format(1);
    assertTrue("h) Incorrect format returned: " + formattedString, formattedString.equals("Normal Orange"));
    formattedString = cf.format(1.5);
    assertTrue("i) Incorrect format returned: " + formattedString, formattedString.equals("Normal Orange"));
    formattedString = cf.format(2);
    assertTrue("j) Incorrect format returned: " + formattedString, formattedString.equals("Expensive Orange"));
    formattedString = cf.format(3);
    assertTrue("k) Incorrect format returned: " + formattedString, formattedString.equals("Expensive Orange"));
    formattedString = cf.format(Double.POSITIVE_INFINITY);
    assertTrue("l) Incorrect format returned: " + formattedString, formattedString.equals("Expensive Orange"));
}
Also used : ChoiceFormat(java.text.ChoiceFormat)

Aggregations

ChoiceFormat (java.text.ChoiceFormat)33 NumberFormat (java.text.NumberFormat)15 MessageFormat (java.text.MessageFormat)11 Format (java.text.Format)10 DateFormat (java.text.DateFormat)9 DecimalFormat (java.text.DecimalFormat)7 SimpleDateFormat (java.text.SimpleDateFormat)7 DutySchedule (org.opennms.netmgt.config.users.DutySchedule)4 Currency (java.util.Currency)3 Locale (java.util.Locale)3 Vector (java.util.Vector)3 HttpSession (javax.servlet.http.HttpSession)3 FieldPosition (java.text.FieldPosition)2 ParseException (java.text.ParseException)2 RequestDispatcher (javax.servlet.RequestDispatcher)2 Support_MessageFormat (tests.support.Support_MessageFormat)2 ParsePosition (java.text.ParsePosition)1 ArrayList (java.util.ArrayList)1 Date (java.util.Date)1 ServletException (javax.servlet.ServletException)1