Uploaded image for project: 'Harmony'
  1. Harmony
  2. HARMONY-96

Two new methods need to be implemented by java.nio.charset.Charset

    Details

    • Type: Improvement
    • Status: Closed
    • Priority: Major
    • Resolution: Fixed
    • Affects Version/s: None
    • Fix Version/s: None
    • Component/s: Classlib
    • Labels:
      None

      Description

      There are two new methods added since Java 5.0
      1. public static Charset defaultCharset()
      2. public final int compareTo(Charset that)

      I'd like to implement the two methods and attach my code soon

      1. charset_patch.txt
        2 kB
        Richard Liang

        Activity

        Hide
        tellison Tim Ellison added a comment -

        Verified by Richard

        Show
        tellison Tim Ellison added a comment - Verified by Richard
        Hide
        richard_liang Richard Liang added a comment -

        Tim,
        Looks good. Thanks a lot.

        Show
        richard_liang Richard Liang added a comment - Tim, Looks good. Thanks a lot.
        Hide
        tellison Tim Ellison added a comment -

        Thanks for the patch Richard.

        Applied in NIO_CHAR module java.nio.charset.Charset at repo revision 380639.

        Please check that the patch was applied as you expected.

        Show
        tellison Tim Ellison added a comment - Thanks for the patch Richard. Applied in NIO_CHAR module java.nio.charset.Charset at repo revision 380639. Please check that the patch was applied as you expected.
        Hide
        richard_liang Richard Liang added a comment -

        Here is the test cases:

        /*

        • Test method defaultCharset()
          */
          public void testDefaultCharset_Normal()
          Unknown macro: { String charsetName = null; String defaultCharsetName = null; Properties oldProps = (Properties)System.getProperties().clone(); try{ charsetName = "UTF-8"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ defaultCharsetName = Charset.defaultCharset().name(); assertEquals(charsetName,defaultCharsetName); charsetName = "ISO-8859-1"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ defaultCharsetName = Charset.defaultCharset().name(); assertEquals(charsetName,defaultCharsetName); }finally{ System.setProperties(oldProps); }
          }

          /*
          * Test method defaultCharset()
          */
          public void testDefaultCharset_Unsupported(){
          String charsetName = null;
          String defaultCharsetName = null;
          Properties oldProps = (Properties)System.getProperties().clone();
          try{ charsetName = "IMPOSSIBLE-8"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ defaultCharsetName = Charset.defaultCharset().name(); assertEquals("UTF-8",defaultCharsetName); }finally{ System.setProperties(oldProps); } }

        /*

        • Test method defaultCharset()
          */
          public void testDefaultCharset_Null()
          Unknown macro: { Properties currentProps = System.getProperties(); Properties oldProps = (Properties)currentProps.clone(); try{ currentProps.remove("file.encoding");//$NON-NLS-1$ Charset.defaultCharset().name(); fail("Should throw illegal IllegalArgumentException");//$NON-NLS-1$ }catch(IllegalArgumentException e){ // expected }finally{ System.setProperties(oldProps); }
          }

          /*
          * Test method defaultCharset()
          */
          public void testDefaultCharset_IllegalCharsetName(){
          String charsetName = null;
          Properties oldProps = (Properties)System.getProperties().clone();
          try{ charsetName = "IMP~~OSSIBLE-8"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ Charset.defaultCharset().name(); fail("Should throw IllegalCharsetNameException");//$NON-NLS-1$ }catch(IllegalCharsetNameException e){ // expected }finally{ System.setProperties(oldProps); } }
        Show
        richard_liang Richard Liang added a comment - Here is the test cases: /* Test method defaultCharset() */ public void testDefaultCharset_Normal() Unknown macro: { String charsetName = null; String defaultCharsetName = null; Properties oldProps = (Properties)System.getProperties().clone(); try{ charsetName = "UTF-8"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ defaultCharsetName = Charset.defaultCharset().name(); assertEquals(charsetName,defaultCharsetName); charsetName = "ISO-8859-1"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ defaultCharsetName = Charset.defaultCharset().name(); assertEquals(charsetName,defaultCharsetName); }finally{ System.setProperties(oldProps); } } /* * Test method defaultCharset() */ public void testDefaultCharset_Unsupported(){ String charsetName = null; String defaultCharsetName = null; Properties oldProps = (Properties)System.getProperties().clone(); try{ charsetName = "IMPOSSIBLE-8"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ defaultCharsetName = Charset.defaultCharset().name(); assertEquals("UTF-8",defaultCharsetName); }finally{ System.setProperties(oldProps); } } /* Test method defaultCharset() */ public void testDefaultCharset_Null() Unknown macro: { Properties currentProps = System.getProperties(); Properties oldProps = (Properties)currentProps.clone(); try{ currentProps.remove("file.encoding");//$NON-NLS-1$ Charset.defaultCharset().name(); fail("Should throw illegal IllegalArgumentException");//$NON-NLS-1$ }catch(IllegalArgumentException e){ // expected }finally{ System.setProperties(oldProps); } } /* * Test method defaultCharset() */ public void testDefaultCharset_IllegalCharsetName(){ String charsetName = null; Properties oldProps = (Properties)System.getProperties().clone(); try{ charsetName = "IMP~~OSSIBLE-8"; //$NON-NLS-1$ System.setProperty("file.encoding",charsetName);//$NON-NLS-1$ Charset.defaultCharset().name(); fail("Should throw IllegalCharsetNameException");//$NON-NLS-1$ }catch(IllegalCharsetNameException e){ // expected }finally{ System.setProperties(oldProps); } }

          People

          • Assignee:
            tellison Tim Ellison
            Reporter:
            richard_liang Richard Liang
          • Votes:
            0 Vote for this issue
            Watchers:
            0 Start watching this issue

            Dates

            • Created:
              Updated:
              Resolved:

              Development