public void test_toPattern() { // Regression for HARMONY-59 ChoiceFormat cf = new ChoiceFormat(""); assertEquals("", "", cf.ToPattern()); cf = new ChoiceFormat("-1#NEGATIVE_ONE|0#ZERO|1#ONE|1<GREATER_THAN_ONE"); assertEquals("", "-1.0#NEGATIVE_ONE|0.0#ZERO|1.0#ONE|1.0<GREATER_THAN_ONE", cf.ToPattern()); MessageFormat mf = new MessageFormat("CHOICE {1,choice}"); String ptrn = mf.ToPattern(); assertEquals("Unused message format returning incorrect pattern", "CHOICE {1,choice,}", ptrn ); String pattern = f1.ToPattern(); assertTrue( "Wrong pattern: " + pattern, pattern .Equals("0.0#Less than one|1.0#one|1.0<Between one and two|2.0<Greater than two")); cf = new ChoiceFormat( "-1#is negative| 0#is zero or fraction | 1#is one |1.0<is 1+|2#is two |2<is more than 2."); String str = "org.apache.harmony.tests.java.lang.share.MyResources2"; cf.ApplyPattern(str); ptrn = cf.ToPattern(); assertEquals("Return value should be empty string for invalid pattern", 0, ptrn.Length); }
public void test_applyPatternLjava_lang_String() { // Test for method void // java.text.ChoiceFormat.applyPattern(java.lang.String) ChoiceFormat f = (ChoiceFormat)f1.Clone(); f.ApplyPattern("0#0|1#1"); assertTrue("Incorrect limits", Array.Equals(f.GetLimits(), new double[] { 0, 1 })); assertTrue("Incorrect formats", Array.Equals(f.GetFormats(), new string[] { "0", "1" })); //Regression for Harmony 540 double[] choiceLimits = { -1, 0, 1, ChoiceFormat.NextDouble(1) }; String[] choiceFormats = { "is negative", "is zero or fraction", "is one", "is more than 1" }; f = new ChoiceFormat(""); f.ApplyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1"); assertTrue("Incorrect limits", Array.Equals(f.GetLimits(), choiceLimits)); assertTrue("Incorrect formats", Array.Equals(f.GetFormats(), choiceFormats)); f = new ChoiceFormat(""); try { f.ApplyPattern("-1#is negative|0#is zero or fraction|-1#is one|1<is more than 1"); fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // Expected } f = new ChoiceFormat(""); try { f.ApplyPattern("-1is negative|0#is zero or fraction|1#is one|1<is more than 1"); fail("Expected IllegalArgumentException"); } catch (ArgumentException e) { // Expected } f = new ChoiceFormat(""); f.ApplyPattern("-1<is negative|0#is zero or fraction|1#is one|1<is more than 1"); choiceLimits[0] = ChoiceFormat.NextDouble(-1); assertTrue("Incorrect limits", Array.Equals(f.GetLimits(), choiceLimits)); assertTrue("Incorrect formats", Array.Equals(f.GetFormats(), choiceFormats)); f = new ChoiceFormat(""); f.ApplyPattern("-1#is negative|0#is zero or fraction|1#is one|1<is more than 1"); String str = "org.apache.harmony.tests.java.text.ChoiceFormat"; f.ApplyPattern(str); String ptrn = f.ToPattern(); assertEquals("Return value should be empty string for invalid pattern", 0, ptrn.Length); }