geronimo-scm mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From jboy...@apache.org
Subject cvs commit: incubator-geronimo/specs/javamail/src/test/javax/mail URLNameTest.java
Date Tue, 19 Aug 2003 02:39:02 GMT
jboynes     2003/08/18 19:39:02

  Modified:    specs/javamail/src/java/javax/mail URLName.java
               specs/javamail/src/test/javax/mail URLNameTest.java
  Log:
  Fix problem with hashCode
  Add tests to clarify null protocol behaviour
  
  Revision  Changes    Path
  1.4       +5 -2      incubator-geronimo/specs/javamail/src/java/javax/mail/URLName.java
  
  Index: URLName.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/java/javax/mail/URLName.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- URLName.java	18 Aug 2003 20:53:05 -0000	1.3
  +++ URLName.java	19 Aug 2003 02:39:02 -0000	1.4
  @@ -77,6 +77,7 @@
       private String ref;
       private String username;
       protected String fullURL;
  +    private int hashCode;
   
       public URLName(String url) {
           parseString(url);
  @@ -184,6 +185,7 @@
       }
   
       private void updateFullURL() {
  +        hashCode = 0;
           StringBuffer buf = new StringBuffer(100);
           if (protocol != null) {
               buf.append(protocol).append(':');
  @@ -203,6 +205,7 @@
                   if (file != null) {
                       buf.append(file);
                   }
  +                hashCode = buf.toString().hashCode();
                   if (ref != null) {
                       buf.append('#').append(ref);
                   }
  @@ -238,7 +241,7 @@
       }
   
       public int hashCode() {
  -        return fullURL.hashCode();
  +        return hashCode;
       }
   
       public String toString() {
  
  
  
  1.3       +31 -1     incubator-geronimo/specs/javamail/src/test/javax/mail/URLNameTest.java
  
  Index: URLNameTest.java
  ===================================================================
  RCS file: /home/cvs/incubator-geronimo/specs/javamail/src/test/javax/mail/URLNameTest.java,v
  retrieving revision 1.2
  retrieving revision 1.3
  diff -u -r1.2 -r1.3
  --- URLNameTest.java	18 Aug 2003 20:53:05 -0000	1.2
  +++ URLNameTest.java	19 Aug 2003 02:39:02 -0000	1.3
  @@ -368,4 +368,34 @@
           assertEquals(new URLName("http://www.apache.org"), new URLName("http", "www.apache.org",
-1, null, null, "doe"));
       }
   
  +    public void testHashCode() {
  +        URLName name1 = new URLName("http://www.apache.org/file");
  +        URLName name2 = new URLName("http://www.apache.org/file#ref");
  +        assertTrue(name1.equals(name2));
  +        assertTrue(name1.hashCode() == name2.hashCode());
  +    }
  +
  +    public void testNullProtocol() {
  +        URLName name1 = new URLName(null, "www.apache.org", -1, null, null, null);
  +        assertTrue(!name1.equals(name1));
  +    }
  +
  +    public void testOpaqueSchemes() {
  +        String s;
  +        URLName name;
  +
  +        // not strictly opaque but no protocol handler installed
  +        s = "foo://jdoe@apache.org/INBOX";
  +        name = new URLName(s);
  +        assertEquals(s, name.toString());
  +        assertEquals("foo", name.getProtocol());
  +        assertEquals("apache.org", name.getHost());
  +        assertEquals(-1, name.getPort());
  +        assertEquals("/INBOX", name.getFile());
  +        assertNull(name.getRef());
  +        assertEquals("jdoe", name.getUsername());
  +        assertNull(name.getPassword());
  +
  +        // TBD as I am not sure what other URL formats to use
  +    }
   }
  
  
  

Mime
View raw message