Author: sebb
Date: Tue Nov  9 02:24:21 2010
New Revision: 1032816

URL: http://svn.apache.org/viewvc?rev=1032816&view=rev
Log:
NET-262 - add Javadoc and some extra tests

Modified:
    
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
    
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java

Modified: 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java?rev=1032816&r1=1032815&r2=1032816&view=diff
==============================================================================
--- 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
 (original)
+++ 
commons/proper/net/trunk/src/main/java/org/apache/commons/net/util/SubnetUtils.java
 Tue Nov  9 02:24:21 2010
@@ -45,6 +45,8 @@ public class SubnetUtils {
     /**
      * Constructor that takes a CIDR-notation string, e.g. "192.168.0.1/16"
      * @param cidrNotation A CIDR-notation string, e.g. "192.168.0.1/16"
+     * @throws IllegalArgumentException if the parameter is invalid, 
+     * i.e. does not match n.n.n.n/m where n=1-3 decimal digits, m = 1-3 
decimal digits in range 1-32
      */
     public SubnetUtils(String cidrNotation) {
         calculate(cidrNotation);
@@ -54,6 +56,8 @@ public class SubnetUtils {
      * Constructor that takes a dotted decimal address and a dotted decimal 
mask.
      * @param address An IP address, e.g. "192.168.0.1"
      * @param mask A dotted decimal netmask e.g. "255.255.0.0"
+     * @throws IllegalArgumentException if the address or mask is invalid, 
+     * i.e. does not match n.n.n.n where n=1-3 decimal digits and the mask is 
not all zeros
      */
     public SubnetUtils(String address, String mask) {
         calculate(toCidrNotation(address, mask));

Modified: 
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
URL: 
http://svn.apache.org/viewvc/commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java?rev=1032816&r1=1032815&r2=1032816&view=diff
==============================================================================
--- 
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
 (original)
+++ 
commons/proper/net/trunk/src/test/java/org/apache/commons/net/SubnetUtilsTest.java
 Tue Nov  9 02:24:21 2010
@@ -223,5 +223,25 @@ public class SubnetUtilsTest extends Tes
         info = utils.getInfo();
         assertEquals("255.255.255.255",info.getNetmask());
         assertEquals(1, info.getAddressCount());
+        
+        new SubnetUtils("192.168.0.1/1");
+    }
+    
+    public void testInvalidMasks(){
+        try {
+            new SubnetUtils("192.168.0.1/33");
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+        }
+        try {
+            new SubnetUtils("192.168.0.1/0");
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+        }
+        try {
+            new SubnetUtils("192.168.0.1","0.0.0.0");
+            fail("Should have thrown IllegalArgumentException");
+        } catch (IllegalArgumentException expected) {
+        }
     }
 }


Reply via email to