Harmony
  1. Harmony
  2. HARMONY-96

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

    Details

    • Type: Improvement Improvement
    • Status: Closed
    • Priority: Major 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

        Richard Liang created issue -
        Hide
        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 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); } }
        Richard Liang made changes -
        Field Original Value New Value
        Attachment charset_patch.txt [ 12323354 ]
        Tim Ellison made changes -
        Assignee Tim Ellison [ tellison ]
        Tim Ellison made changes -
        Status Open [ 1 ] In Progress [ 3 ]
        Hide
        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
        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.
        Tim Ellison made changes -
        Status In Progress [ 3 ] Resolved [ 5 ]
        Resolution Fixed [ 1 ]
        Hide
        Richard Liang added a comment -

        Tim,
        Looks good. Thanks a lot.

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

        Verified by Richard

        Show
        Tim Ellison added a comment - Verified by Richard
        Tim Ellison made changes -
        Status Resolved [ 5 ] Closed [ 6 ]
        Transition Time In Source Status Execution Times Last Executer Last Execution Date
        Open Open In Progress In Progress
        8d 1h 17m 1 Tim Ellison 24/Feb/06 19:03
        In Progress In Progress Resolved Resolved
        39m 34s 1 Tim Ellison 24/Feb/06 19:42
        Resolved Resolved Closed Closed
        3d 7m 1 Tim Ellison 27/Feb/06 19:50

          People

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

            Dates

            • Created:
              Updated:
              Resolved:

              Development