wink-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From b...@apache.org
Subject svn commit: r903956 - in /incubator/wink/trunk/wink-common/src: main/java/org/apache/wink/common/internal/UriBuilderImpl.java test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
Date Thu, 28 Jan 2010 04:55:35 GMT
Author: bluk
Date: Thu Jan 28 04:55:33 2010
New Revision: 903956

URL: http://svn.apache.org/viewvc?rev=903956&view=rev
Log:
Throw IllegalArgException in UriBuilder port/host

See [WINK-249]

Modified:
    incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
    incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java

Modified: incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java?rev=903956&r1=903955&r2=903956&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
(original)
+++ incubator/wink/trunk/wink-common/src/main/java/org/apache/wink/common/internal/UriBuilderImpl.java
Thu Jan 28 04:55:33 2010
@@ -399,6 +399,10 @@
 
     @Override
     public UriBuilder host(String host) throws IllegalArgumentException {
+        // null unsets the host so don't check that
+        if ("".equals(host)) {
+            throw new IllegalArgumentException();
+        }
         this.host = host;
         return this;
     }
@@ -509,6 +513,10 @@
 
     @Override
     public UriBuilder port(int port) throws IllegalArgumentException {
+        // -1 unsets the port so don't worry about that
+        if (port < -1) {
+            throw new IllegalArgumentException();
+        }
         this.port = port;
         return this;
     }

Modified: incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
URL: http://svn.apache.org/viewvc/incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java?rev=903956&r1=903955&r2=903956&view=diff
==============================================================================
--- incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
(original)
+++ incubator/wink/trunk/wink-common/src/test/java/org/apache/wink/common/internal/UriBuilderImplTest.java
Thu Jan 28 04:55:33 2010
@@ -314,4 +314,34 @@
             assertTrue(uri.toString().equals(uris));
         }
     }
+
+    public void testInvalidPort() {
+        UriBuilder builder = UriBuilder.fromUri("http://localhost/");
+        try {
+            builder.port(-2);
+        } catch (IllegalArgumentException e) {
+            /* expected */
+        }
+        builder.port(1);
+        builder.port(-1);
+        URI uri = builder.build();
+        assertEquals("http://localhost/", uri.toASCIIString());
+    }
+
+    public void testInvalidHost() {
+        UriBuilder builder = UriBuilder.fromUri("http://localhost/");
+        builder.host("abcd");
+        try {
+            builder.host("");
+        } catch (IllegalArgumentException e) {
+            /* expected */
+        }
+        URI uri = builder.build();
+        assertEquals("http://abcd/", uri.toASCIIString());
+       
+        builder = UriBuilder.fromUri("http://localhost");
+        builder.host(null);
+        uri = builder.build();
+        assertEquals("http:/", uri.toASCIIString());
+    }
 }



Mime
View raw message