Code example for ChoiceFormat

Methods: format

0
     */ 
    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"));
 
    }