java.text.ChoiceFormat Java Examples
The following examples show how to use
java.text.ChoiceFormat.
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example #1
Source File: NumberFormatTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * @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) { } }
Example #2
Source File: Bug4185816Test.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
private static void writeFormatToFile(final String name) { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(name)); MessageFormat fmt = new MessageFormat("The disk \"{1}\" contains {0}."); double[] filelimits = {0,1,2}; String[] filepart = {"no files","one file","{0,number} files"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); fmt.setFormat(1,fileform); // NOT zero, see below out.writeObject(fmt); out.close(); } catch (Exception e) { System.out.println(e); } }
Example #3
Source File: DiffSidebar.java From netbeans with Apache License 2.0 | 6 votes |
static String getShortDescription(Difference diff) { if (diff == null) { return null; } int n; switch (diff.getType()) { case Difference.ADD: n = diff.getSecondEnd() - diff.getSecondStart() + 1; return MessageFormat.format(new ChoiceFormat(NbBundle.getMessage(DiffSidebar.class, "TT_LinesAdded")).format(n), n); // NOI18N case Difference.CHANGE: n = diff.getFirstEnd() - diff.getFirstStart() + 1; return MessageFormat.format(new ChoiceFormat(NbBundle.getMessage(DiffSidebar.class, "TT_LinesChanged")).format(n), n); // NOI18N case Difference.DELETE: n = diff.getFirstEnd() - diff.getFirstStart() + 1; return MessageFormat.format(new ChoiceFormat(NbBundle.getMessage(DiffSidebar.class, "TT_LinesDeleted")).format(n), n); // NOI18N default: throw new IllegalStateException("Unknown difference type: " + diff.getType()); // NOI18N } }
Example #4
Source File: Bug4185732Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
/** * Create a data file for this test. The data file must be corrupted by hand. */ private static void prepTest() { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("Bug4185732.ser")); final double[] limits = {1,2,3,4,5,6,7}; final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; final ChoiceFormat fmt = new ChoiceFormat(limits, formats); out.writeObject(fmt); out.close(); System.out.println("You must invalidate the output file before running the test"); System.out.println("by modifying the length of one of the array"); } catch (Exception e) { System.out.println(e); } }
Example #5
Source File: Bug4185816Test.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
private static void writeFormatToFile(final String name) { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(name)); MessageFormat fmt = new MessageFormat("The disk \"{1}\" contains {0}."); double[] filelimits = {0,1,2}; String[] filepart = {"no files","one file","{0,number} files"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); fmt.setFormat(1,fileform); // NOT zero, see below out.writeObject(fmt); out.close(); } catch (Exception e) { System.out.println(e); } }
Example #6
Source File: Bug4387255.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings); ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern); if (!choiceFormat1.equals(choiceFormat2)) { System.out.println("choiceFormat1: " + choiceFormat1.toPattern()); System.out.println("choiceFormat2: " + choiceFormat2.toPattern()); throw new RuntimeException(); } for (int i = 0; i < doubles.length; i++) { String result = choiceFormat2.format(doubles[i]); if (!result.equals(strings[i])) { throw new RuntimeException("Wrong format result - expected " + strings[i] + ", got " + result); } } }
Example #7
Source File: Bug4185732Test.java From openjdk-jdk8u with GNU General Public License v2.0 | 6 votes |
/** * Create a data file for this test. The data file must be corrupted by hand. */ private static void prepTest() { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("Bug4185732.ser")); final double[] limits = {1,2,3,4,5,6,7}; final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; final ChoiceFormat fmt = new ChoiceFormat(limits, formats); out.writeObject(fmt); out.close(); System.out.println("You must invalidate the output file before running the test"); System.out.println("by modifying the length of one of the array"); } catch (Exception e) { System.out.println(e); } }
Example #8
Source File: Bug4185816Test.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
private static void writeFormatToFile(final String name) { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(name)); MessageFormat fmt = new MessageFormat("The disk \"{1}\" contains {0}."); double[] filelimits = {0,1,2}; String[] filepart = {"no files","one file","{0,number} files"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); fmt.setFormat(1,fileform); // NOT zero, see below out.writeObject(fmt); out.close(); } catch (Exception e) { System.out.println(e); } }
Example #9
Source File: Bug4387255.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings); ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern); if (!choiceFormat1.equals(choiceFormat2)) { System.out.println("choiceFormat1: " + choiceFormat1.toPattern()); System.out.println("choiceFormat2: " + choiceFormat2.toPattern()); throw new RuntimeException(); } for (int i = 0; i < doubles.length; i++) { String result = choiceFormat2.format(doubles[i]); if (!result.equals(strings[i])) { throw new RuntimeException("Wrong format result - expected " + strings[i] + ", got " + result); } } }
Example #10
Source File: Bug4185732Test.java From TencentKona-8 with GNU General Public License v2.0 | 6 votes |
/** * Create a data file for this test. The data file must be corrupted by hand. */ private static void prepTest() { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("Bug4185732.ser")); final double[] limits = {1,2,3,4,5,6,7}; final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; final ChoiceFormat fmt = new ChoiceFormat(limits, formats); out.writeObject(fmt); out.close(); System.out.println("You must invalidate the output file before running the test"); System.out.println("by modifying the length of one of the array"); } catch (Exception e) { System.out.println(e); } }
Example #11
Source File: Bug4185732Test.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
/** * Create a data file for this test. The data file must be corrupted by hand. */ private static void prepTest() { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("Bug4185732.ser")); final double[] limits = {1,2,3,4,5,6,7}; final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; final ChoiceFormat fmt = new ChoiceFormat(limits, formats); out.writeObject(fmt); out.close(); System.out.println("You must invalidate the output file before running the test"); System.out.println("by modifying the length of one of the array"); } catch (Exception e) { System.out.println(e); } }
Example #12
Source File: Bug4185816Test.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
private static void writeFormatToFile(final String name) { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(name)); MessageFormat fmt = new MessageFormat("The disk \"{1}\" contains {0}."); double[] filelimits = {0,1,2}; String[] filepart = {"no files","one file","{0,number} files"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); fmt.setFormat(1,fileform); // NOT zero, see below out.writeObject(fmt); out.close(); } catch (Exception e) { System.out.println(e); } }
Example #13
Source File: Bug4387255.java From openjdk-jdk9 with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings); ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern); if (!choiceFormat1.equals(choiceFormat2)) { System.out.println("choiceFormat1: " + choiceFormat1.toPattern()); System.out.println("choiceFormat2: " + choiceFormat2.toPattern()); throw new RuntimeException(); } for (int i = 0; i < doubles.length; i++) { String result = choiceFormat2.format(doubles[i]); if (!result.equals(strings[i])) { throw new RuntimeException("Wrong format result - expected " + strings[i] + ", got " + result); } } }
Example #14
Source File: TimeDescriptor.java From cron-utils with Apache License 2.0 | 6 votes |
private String describeEverySecond(final int second) { final double[] secondsLimit = {1, 2}; final String[] secondsStrings = { resourceBundle.getString("oneSecond"), resourceBundle.getString("multipleSeconds") }; final double[] everyLimit = {1,2}; final String[] everyStrings = { resourceBundle.getString("every_one"), resourceBundle.getString("every_multi") }; final ChoiceFormat secondsChoiceFormat = new ChoiceFormat(secondsLimit, secondsStrings); final ChoiceFormat everyChoiceFormat = new ChoiceFormat(everyLimit, everyStrings); final String pattern = resourceBundle.getString("pattern_every_seconds"); final MessageFormat messageFormat = new MessageFormat(pattern, Locale.UK); final Format[] formats = { everyChoiceFormat, secondsChoiceFormat, NumberFormat.getInstance() }; messageFormat.setFormats(formats); final Object[] messageArguments = {second, second, second }; final String result = messageFormat.format(messageArguments); return result; }
Example #15
Source File: Bug4185732Test.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
/** * Create a data file for this test. The data file must be corrupted by hand. */ private static void prepTest() { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream("Bug4185732.ser")); final double[] limits = {1,2,3,4,5,6,7}; final String[] formats = {"Sun","Mon","Tue","Wed","Thur","Fri","Sat"}; final ChoiceFormat fmt = new ChoiceFormat(limits, formats); out.writeObject(fmt); out.close(); System.out.println("You must invalidate the output file before running the test"); System.out.println("by modifying the length of one of the array"); } catch (Exception e) { System.out.println(e); } }
Example #16
Source File: Bug4387255.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings); ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern); if (!choiceFormat1.equals(choiceFormat2)) { System.out.println("choiceFormat1: " + choiceFormat1.toPattern()); System.out.println("choiceFormat2: " + choiceFormat2.toPattern()); throw new RuntimeException(); } for (int i = 0; i < doubles.length; i++) { String result = choiceFormat2.format(doubles[i]); if (!result.equals(strings[i])) { throw new RuntimeException("Wrong format result - expected " + strings[i] + ", got " + result); } } }
Example #17
Source File: Bug4185816Test.java From jdk8u_jdk with GNU General Public License v2.0 | 6 votes |
private static void writeFormatToFile(final String name) { try { ObjectOutputStream out = new ObjectOutputStream( new FileOutputStream(name)); MessageFormat fmt = new MessageFormat("The disk \"{1}\" contains {0}."); double[] filelimits = {0,1,2}; String[] filepart = {"no files","one file","{0,number} files"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); fmt.setFormat(1,fileform); // NOT zero, see below out.writeObject(fmt); out.close(); } catch (Exception e) { System.out.println(e); } }
Example #18
Source File: LocaleParserTest.java From ph-commons with Apache License 2.0 | 6 votes |
@Test public void testParseBigDecimal () { final BigDecimal aBD1M = StringParser.parseBigDecimal ("1000000"); assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1.000.000", L_DE, CGlobal.BIGDEC_MINUS_ONE)); assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", L_EN, CGlobal.BIGDEC_MINUS_ONE)); assertEquals (aBD1M, LocaleParser.parseBigDecimal ("1,000,000", (DecimalFormat) NumberFormat.getInstance (L_EN))); assertEquals (new BigDecimal ("1234567.8901"), LocaleParser.parseBigDecimal ("1.234.567,8901", L_DE, CGlobal.BIGDEC_MINUS_ONE)); assertEquals (CGlobal.BIGDEC_MINUS_ONE, LocaleParser.parseBigDecimal ("... und denken", L_EN, CGlobal.BIGDEC_MINUS_ONE)); final ChoiceFormat aCF = new ChoiceFormat ("-1#negative|0#zero|1.0#one"); assertEquals (BigDecimal.valueOf (0.0), LocaleParser.parseBigDecimal ("zero", aCF, CGlobal.BIGDEC_MINUS_ONE)); try { LocaleParser.parseBigDecimal ("0", (DecimalFormat) null); fail (); } catch (final NullPointerException ex) {} }
Example #19
Source File: Solution.java From JavaRush with MIT License | 6 votes |
private static void printStocks(List<Stock> stocks, Date actualDate) { SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-yyyy"); double[] filelimits = {0d, actualDate.getTime()}; String[] filepart = {"closed {4}", "open {2} and last {3}"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); Format[] testFormats = {null, null, dateFormat, fileform}; MessageFormat pattform = new MessageFormat("{0} {1} | {5} {6}"); pattform.setFormats(testFormats); for (Stock stock : stocks) { String name = ((String) stock.get("name")); String symbol = (String) stock.get("symbol"); double open = !stock.containsKey("open") ? 0 : ((double) stock.get("open")); double last = !stock.containsKey("last") ? 0 : ((double) stock.get("last")); double change = !stock.containsKey("change") ? 0 : ((double) stock.get("change")); Date date = (Date) stock.get("date"); Object[] testArgs = {name, symbol, open, last, change, date, date.getTime()}; System.out.println(pattform.format(testArgs)); } }
Example #20
Source File: ChoiceFormatTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * @tests java.text.ChoiceFormat#format(double) */ public void test_formatD() { ChoiceFormat fmt = new ChoiceFormat( "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); assertEquals("NEGATIVE_ONE", fmt.format(Double.NEGATIVE_INFINITY)); assertEquals("NEGATIVE_ONE", fmt.format(-999999999D)); assertEquals("NEGATIVE_ONE", fmt.format(-1.1)); assertEquals("NEGATIVE_ONE", fmt.format(-1.0)); assertEquals("NEGATIVE_ONE", fmt.format(-0.9)); assertEquals("ZERO", fmt.format(0.0)); assertEquals("ZERO", fmt.format(0.9)); assertEquals("ONE", fmt.format(1.0)); assertEquals("GREATER_THAN_ONE", fmt.format(1.1)); assertEquals("GREATER_THAN_ONE", fmt.format(999999999D)); assertEquals("GREATER_THAN_ONE", fmt.format(Double.POSITIVE_INFINITY)); }
Example #21
Source File: ExtendedMessageFormatTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test the built in choice format. */ public void testBuiltInChoiceFormat() { Object[] values = new Number[] {new Integer(1), new Double("2.2"), new Double("1234.5")}; String choicePattern = null; Locale[] availableLocales = ChoiceFormat.getAvailableLocales(); choicePattern = "{0,choice,1#One|2#Two|3#Many {0,number}}"; for (int i = 0; i < values.length; i++) { checkBuiltInFormat(values[i] + ": " + choicePattern, new Object[] {values[i]}, availableLocales); } choicePattern = "{0,choice,1#''One''|2#\"Two\"|3#''{Many}'' {0,number}}"; for (int i = 0; i < values.length; i++) { checkBuiltInFormat(values[i] + ": " + choicePattern, new Object[] {values[i]}, availableLocales); } }
Example #22
Source File: ExtendedMessageFormatTest.java From astor with GNU General Public License v2.0 | 6 votes |
/** * Test the built in choice format. */ public void testBuiltInChoiceFormat() { Object[] values = new Number[] {new Integer(1), new Double("2.2"), new Double("1234.5")}; String choicePattern = null; Locale[] availableLocales = ChoiceFormat.getAvailableLocales(); choicePattern = "{0,choice,1#One|2#Two|3#Many {0,number}}"; for (int i = 0; i < values.length; i++) { checkBuiltInFormat(values[i] + ": " + choicePattern, new Object[] {values[i]}, availableLocales); } choicePattern = "{0,choice,1#''One''|2#\"Two\"|3#''{Many}'' {0,number}}"; for (int i = 0; i < values.length; i++) { checkBuiltInFormat(values[i] + ": " + choicePattern, new Object[] {values[i]}, availableLocales); } }
Example #23
Source File: ChoiceFormatTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * @tests java.text.ChoiceFormat#parse(java.lang.String, * java.text.ParsePosition) */ public void test_parseLjava_lang_StringLjava_text_ParsePosition() { // Test for method java.lang.Number // java.text.ChoiceFormat.parse(java.lang.String, // java.text.ParsePosition) ChoiceFormat format = new ChoiceFormat("1#one|2#two|3#three"); assertEquals("Case insensitive", 0, format .parse("One", new ParsePosition(0)).intValue()); ParsePosition pos = new ParsePosition(0); Number result = f1.parse("Greater than two", pos); assertTrue("Not a Double1", result instanceof Double); assertTrue("Wrong value ~>2", result.doubleValue() == ChoiceFormat .nextDouble(2)); assertEquals("Wrong position ~16", 16, pos.getIndex()); pos = new ParsePosition(0); assertTrue("Incorrect result", Double.isNaN(f1.parse("12one", pos) .doubleValue())); assertEquals("Wrong position ~0", 0, pos.getIndex()); pos = new ParsePosition(2); result = f1.parse("12one and two", pos); assertTrue("Not a Double2", result instanceof Double); assertEquals("Ignored parse position", 1.0D, result.doubleValue(), 0.0D); assertEquals("Wrong position ~5", 5, pos.getIndex()); }
Example #24
Source File: MessageRegressionTest.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void Test4106661() { ChoiceFormat fmt = new ChoiceFormat( "-1#are negative| 0#are no or fraction | 1#is one |1.0<is 1+ |2#are two |2<are more than 2."); logln("Formatter Pattern : " + fmt.toPattern()); logln("Format with -INF : " + fmt.format(Double.NEGATIVE_INFINITY)); logln("Format with -1.0 : " + fmt.format(-1.0)); logln("Format with 0 : " + fmt.format(0)); logln("Format with 0.9 : " + fmt.format(0.9)); logln("Format with 1.0 : " + fmt.format(1)); logln("Format with 1.5 : " + fmt.format(1.5)); logln("Format with 2 : " + fmt.format(2)); logln("Format with 2.1 : " + fmt.format(2.1)); logln("Format with NaN : " + fmt.format(Double.NaN)); logln("Format with +INF : " + fmt.format(Double.POSITIVE_INFINITY)); }
Example #25
Source File: MessageRegressionTest.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void Test4094906() { ChoiceFormat fmt = new ChoiceFormat( "-\u221E<are negative|0<are no or fraction|1#is one|1.0<is 1+|\u221E<are many."); if (!fmt.toPattern().startsWith("-\u221E<are negative|0.0<are no or fraction|1.0#is one|1.0<is 1+|\u221E<are many.")) errln("Formatter Pattern : " + fmt.toPattern()); logln("Format with -INF : " + fmt.format(Double.NEGATIVE_INFINITY)); logln("Format with -1.0 : " + fmt.format(-1.0)); logln("Format with 0 : " + fmt.format(0)); logln("Format with 0.9 : " + fmt.format(0.9)); logln("Format with 1.0 : " + fmt.format(1)); logln("Format with 1.5 : " + fmt.format(1.5)); logln("Format with 2 : " + fmt.format(2)); logln("Format with +INF : " + fmt.format(Double.POSITIVE_INFINITY)); }
Example #26
Source File: MessageRegressionTest.java From j2objc with Apache License 2.0 | 6 votes |
@Test public void Test4105380() { String patternText1 = "The disk \"{1}\" contains {0}."; String patternText2 = "There are {0} on the disk \"{1}\""; MessageFormat form1 = new MessageFormat(patternText1); MessageFormat form2 = new MessageFormat(patternText2); double[] filelimits = {0,1,2}; String[] filepart = {"no files","one file","{0,number} files"}; ChoiceFormat fileform = new ChoiceFormat(filelimits, filepart); form1.setFormat(1, fileform); form2.setFormat(0, fileform); Object[] testArgs = {new Long(12373), "MyDisk"}; logln(form1.format(testArgs)); logln(form2.format(testArgs)); }
Example #27
Source File: NumberFormatTest.java From j2objc with Apache License 2.0 | 6 votes |
/** * @tests java.text.NumberFormat#getCurrency() */ public void test_getCurrency() { // Test for method java.util.Currency getCurrency() // a subclass that supports currency formatting Currency currH = Currency.getInstance("HUF"); NumberFormat format = NumberFormat.getInstance(new Locale("hu", "HU")); assertSame("Returned incorrect currency", currH, 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).getCurrency(); fail("Expected UnsupportedOperationException"); } catch (UnsupportedOperationException e) { } }
Example #28
Source File: Bug4387255.java From dragonwell8_jdk with GNU General Public License v2.0 | 6 votes |
public static void main(String[] args) throws Exception { ChoiceFormat choiceFormat1 = new ChoiceFormat(doubles, strings); ChoiceFormat choiceFormat2 = new ChoiceFormat(pattern); if (!choiceFormat1.equals(choiceFormat2)) { System.out.println("choiceFormat1: " + choiceFormat1.toPattern()); System.out.println("choiceFormat2: " + choiceFormat2.toPattern()); throw new RuntimeException(); } for (int i = 0; i < doubles.length; i++) { String result = choiceFormat2.format(doubles[i]); if (!result.equals(strings[i])) { throw new RuntimeException("Wrong format result - expected " + strings[i] + ", got " + result); } } }
Example #29
Source File: ChoiceFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests java.text.ChoiceFormat#format(long) */ public void test_formatL() { ChoiceFormat fmt = new ChoiceFormat( "-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); assertEquals("NEGATIVE_ONE", fmt.format(Long.MIN_VALUE)); assertEquals("NEGATIVE_ONE", fmt.format(-1)); assertEquals("ZERO", fmt.format(0)); assertEquals("ONE", fmt.format(1)); assertEquals("GREATER_THAN_ONE", fmt.format(Long.MAX_VALUE)); }
Example #30
Source File: ChoiceFormatTest.java From j2objc with Apache License 2.0 | 5 votes |
/** * @tests java.text.ChoiceFormat#format(double, java.lang.StringBuffer, * java.text.FieldPosition) */ public void test_formatDLjava_lang_StringBufferLjava_text_FieldPosition() { // Test for method java.lang.StringBuffer // java.text.ChoiceFormat.format(double, java.lang.StringBuffer, // java.text.FieldPosition) FieldPosition field = new FieldPosition(0); StringBuffer buf = new StringBuffer(); String r = f1.format(-1, buf, field).toString(); assertEquals("Wrong choice for -1", "Less than one", r); buf.setLength(0); r = f1.format(0, buf, field).toString(); assertEquals("Wrong choice for 0", "Less than one", r); buf.setLength(0); r = f1.format(1, buf, field).toString(); assertEquals("Wrong choice for 1", "one", r); buf.setLength(0); r = f1.format(2, buf, field).toString(); assertEquals("Wrong choice for 2", "Between one and two", r); buf.setLength(0); r = f1.format(3, buf, field).toString(); assertEquals("Wrong choice for 3", "Greater than two", r); // Regression test for HARMONY-1081 assertEquals(0, new ChoiceFormat("|").format(Double.NaN, new StringBuffer(), new FieldPosition(6)).length()); assertEquals(0, new ChoiceFormat("|").format(1, new StringBuffer(), new FieldPosition(6)).length()); assertEquals("Less than one", f1.format(Double.NaN, new StringBuffer(), field).toString()); }