harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r696207 - in /harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net: MulticastSocketTest.java NetworkInterfaceTest.java
Date Wed, 17 Sep 2008 09:03:42 GMT
Author: tellison
Date: Wed Sep 17 02:03:40 2008
New Revision: 696207

URL: http://svn.apache.org/viewvc?rev=696207&view=rev
Log:
Apply patch HARMONY-5984 ([classlib][luni] - Should use addresses.hasMoreElements() to test
whether the returned addresses are empty in MulticastSocketTest and NetworkInterfaceTest)

Modified:
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java
    harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetworkInterfaceTest.java

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java?rev=696207&r1=696206&r2=696207&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/MulticastSocketTest.java
Wed Sep 17 02:03:40 2008
@@ -194,7 +194,7 @@
                         // validate that we get the expected response when we set via
                         // setInterface
                         Enumeration addresses = networkInterface1.getInetAddresses();
-                        if (addresses != null) {
+                        if (addresses.hasMoreElements()) {
                                 InetAddress firstAddress = (InetAddress) addresses
                                                 .nextElement();
                                 mss.setInterface(firstAddress);
@@ -219,19 +219,20 @@
 	}
 
 	/**
-	 * @throws IOException 
+	 * @throws IOException
 	 * @tests java.net.MulticastSocket#getNetworkInterface()
 	 */
 	public void test_getNetworkInterface() throws IOException {
-		int groupPort = Support_PortManager.getNextPortForUDP();
-		if (atLeastOneInterface) {
+        int groupPort = Support_PortManager.getNextPortForUDP();
+        if (atLeastOneInterface) {
             // validate that we get the expected response when one was not
             // set
             mss = new MulticastSocket(groupPort);
             NetworkInterface theInterface = mss.getNetworkInterface();
-            assertNotNull(
+            assertTrue(
                     "network interface returned wrong network interface when not set:"
-                            + theInterface, theInterface.getInetAddresses());
+                            + theInterface, theInterface.getInetAddresses()
+                            .hasMoreElements());
             InetAddress firstAddress = (InetAddress) theInterface
                     .getInetAddresses().nextElement();
             // validate we the first address in the network interface is the
@@ -282,7 +283,7 @@
             groupPort = Support_PortManager.getNextPortForUDP();
             mss = new MulticastSocket(groupPort);
             Enumeration addresses = networkInterface1.getInetAddresses();
-            if (addresses != null) {
+            if (addresses.hasMoreElements()) {
                 firstAddress = (InetAddress) addresses.nextElement();
                 mss.setInterface(firstAddress);
                 assertTrue(
@@ -290,7 +291,7 @@
                         networkInterface1.equals(mss.getNetworkInterface()));
             }
         }
-	}
+    }
 
 	/**
 	 * @tests java.net.MulticastSocket#getTimeToLive()
@@ -475,8 +476,7 @@
 
                     NetworkInterface thisInterface = (NetworkInterface) theInterfaces
                             .nextElement();
-                    if ((thisInterface.getInetAddresses() != null && thisInterface
-                            .getInetAddresses().hasMoreElements())
+                    if (thisInterface.getInetAddresses().hasMoreElements()
                             && (Support_NetworkInterface
                                     .useInterface(thisInterface) == true)) {
                         // get the first address on the interface
@@ -488,7 +488,7 @@
 
                         NetworkInterface sendingInterface = null;
                         boolean isLoopback = false;
-                        if (addresses != null) {
+                        if (addresses.hasMoreElements()) {
                             InetAddress firstAddress = (InetAddress) addresses
                                     .nextElement();
                             if (firstAddress.isLoopbackAddress()) {
@@ -514,8 +514,7 @@
 
                         InetAddress useAddress = null;
                         addresses = sendingInterface.getInetAddresses();
-                        if ((addresses != null)
-                                && (addresses.hasMoreElements())) {
+                        if (addresses.hasMoreElements()) {
                             useAddress = (InetAddress) addresses.nextElement();
                         }
 
@@ -832,8 +831,7 @@
             while (theInterfaces.hasMoreElements()) {
                 NetworkInterface thisInterface = (NetworkInterface) theInterfaces
                         .nextElement();
-                if (thisInterface.getInetAddresses() != null
-                        && thisInterface.getInetAddresses().hasMoreElements()) {
+                if (thisInterface.getInetAddresses().hasMoreElements()) {
                     if ((!((InetAddress) thisInterface.getInetAddresses()
                             .nextElement()).isLoopbackAddress())
                             &&
@@ -1116,9 +1114,7 @@
                     && (atLeastOneInterface == false)) {
                 networkInterface1 = (NetworkInterface) theInterfaces
                         .nextElement();
-                if ((networkInterface1.getInetAddresses() != null)
-                        && networkInterface1.getInetAddresses()
-                                .hasMoreElements() &&
+                if (networkInterface1.getInetAddresses().hasMoreElements() &&
                         // we only want real interfaces
                         (Support_NetworkInterface
                                 .useInterface(networkInterface1) == true)) {
@@ -1132,9 +1128,8 @@
                         && (atLeastTwoInterfaces == false)) {
                     networkInterface2 = (NetworkInterface) theInterfaces
                             .nextElement();
-                    if ((networkInterface2.getInetAddresses() != null)
-                            && networkInterface2.getInetAddresses()
-                                    .hasMoreElements() &&
+                    if (networkInterface2.getInetAddresses().hasMoreElements()
+                            &&
                             // we only want real interfaces
                             (Support_NetworkInterface
                                     .useInterface(networkInterface2) == true)) {
@@ -1155,7 +1150,7 @@
 				NetworkInterface nextInterface = (NetworkInterface) theInterfaces
 						.nextElement();
 				addresses = nextInterface.getInetAddresses();
-				if (addresses != null) {
+				if (addresses.hasMoreElements()) {
 					while (addresses.hasMoreElements()) {
 						InetAddress nextAddress = (InetAddress) addresses
 								.nextElement();

Modified: harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetworkInterfaceTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetworkInterfaceTest.java?rev=696207&r1=696206&r2=696207&view=diff
==============================================================================
--- harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetworkInterfaceTest.java
(original)
+++ harmony/enhanced/classlib/trunk/modules/luni/src/test/api/common/org/apache/harmony/luni/tests/java/net/NetworkInterfaceTest.java
Wed Sep 17 02:03:40 2008
@@ -91,27 +91,21 @@
 		}
 
 		if (atLeastOneInterface) {
-			Enumeration theAddresses = networkInterface1.getInetAddresses();
-			if (theAddresses != null) {
-				while (theAddresses.hasMoreElements()) {
-					InetAddress theAddress = (InetAddress) theAddresses
-							.nextElement();
-					assertTrue("validate that address is not null",
-							null != theAddress);
-				}
-			}
-		}
+            Enumeration theAddresses = networkInterface1.getInetAddresses();
+            while (theAddresses.hasMoreElements()) {
+                InetAddress theAddress = (InetAddress) theAddresses
+                        .nextElement();
+                assertNotNull("validate that address is not null", theAddress);
+            }
+        }
 
 		if (atLeastTwoInterfaces) {
 			Enumeration theAddresses = networkInterface2.getInetAddresses();
-			if (theAddresses != null) {
-				while (theAddresses.hasMoreElements()) {
-					InetAddress theAddress = (InetAddress) theAddresses
-							.nextElement();
-					assertTrue("validate that address is not null",
-							null != theAddress);
-				}
-			}
+			while (theAddresses.hasMoreElements()) {
+                InetAddress theAddress = (InetAddress) theAddresses
+                        .nextElement();
+                assertNotNull("validate that address is not null", theAddress);
+            }
 		}
 
 		// create the list of ok and not ok addresses to return
@@ -120,7 +114,20 @@
 			Enumeration addresses = networkInterface1.getInetAddresses();
 			int index = 0;
 			ArrayList notOkAddresses = new ArrayList();
-			if (addresses != null) {
+			while (addresses.hasMoreElements()) {
+                InetAddress theAddress = (InetAddress) addresses.nextElement();
+                if (index != 0) {
+                    okAddresses.add(theAddress);
+                } else {
+                    notOkAddresses.add(theAddress);
+                }
+                index++;
+            }
+
+			// do the same for network interface 2 if it exists
+			if (atLeastTwoInterfaces) {
+				addresses = networkInterface2.getInetAddresses();
+				index = 0;
 				while (addresses.hasMoreElements()) {
 					InetAddress theAddress = (InetAddress) addresses
 							.nextElement();
@@ -133,24 +140,6 @@
 				}
 			}
 
-			// do the same for network interface 2 it it exists
-			if (atLeastTwoInterfaces) {
-				addresses = networkInterface2.getInetAddresses();
-				index = 0;
-				if (addresses != null) {
-					while (addresses.hasMoreElements()) {
-						InetAddress theAddress = (InetAddress) addresses
-								.nextElement();
-						if (index != 0) {
-							okAddresses.add(theAddress);
-						} else {
-							notOkAddresses.add(theAddress);
-						}
-						index++;
-					}
-				}
-			}
-
 			// set the security manager that will make the first address not
 			// visible
 			System.setSecurityManager(new mySecurityManager(notOkAddresses));
@@ -159,7 +148,15 @@
 			for (int i = 0; i < notOkAddresses.size(); i++) {
 				Enumeration reducedAddresses = networkInterface1
 						.getInetAddresses();
-				if (reducedAddresses != null) {
+				while (reducedAddresses.hasMoreElements()) {
+                    InetAddress nextAddress = (InetAddress) reducedAddresses
+                            .nextElement();
+                    assertTrue(
+                            "validate that address without permission is not returned",
+                            !nextAddress.equals(notOkAddresses.get(i)));
+                }
+				if (atLeastTwoInterfaces) {
+                    reducedAddresses = networkInterface2.getInetAddresses();
 					while (reducedAddresses.hasMoreElements()) {
 						InetAddress nextAddress = (InetAddress) reducedAddresses
 								.nextElement();
@@ -168,18 +165,6 @@
 								!nextAddress.equals(notOkAddresses.get(i)));
 					}
 				}
-				if (atLeastTwoInterfaces) {
-					reducedAddresses = networkInterface2.getInetAddresses();
-					if (reducedAddresses != null) {
-						while (reducedAddresses.hasMoreElements()) {
-							InetAddress nextAddress = (InetAddress) reducedAddresses
-									.nextElement();
-							assertTrue(
-									"validate that address without permission is not returned",
-									!nextAddress.equals(notOkAddresses.get(i)));
-						}
-					}
-				}
 			}
 
 			// validate that ok addresses are returned
@@ -187,7 +172,15 @@
 				boolean addressReturned = false;
 				Enumeration reducedAddresses = networkInterface1
 						.getInetAddresses();
-				if (reducedAddresses != null) {
+				while (reducedAddresses.hasMoreElements()) {
+                    InetAddress nextAddress = (InetAddress) reducedAddresses
+                            .nextElement();
+                    if (nextAddress.equals(okAddresses.get(i))) {
+                        addressReturned = true;
+                    }
+                }
+				if (atLeastTwoInterfaces) {
+					reducedAddresses = networkInterface2.getInetAddresses();
 					while (reducedAddresses.hasMoreElements()) {
 						InetAddress nextAddress = (InetAddress) reducedAddresses
 								.nextElement();
@@ -196,18 +189,6 @@
 						}
 					}
 				}
-				if (atLeastTwoInterfaces) {
-					reducedAddresses = networkInterface2.getInetAddresses();
-					if (reducedAddresses != null) {
-						while (reducedAddresses.hasMoreElements()) {
-							InetAddress nextAddress = (InetAddress) reducedAddresses
-									.nextElement();
-							if (nextAddress.equals(okAddresses.get(i))) {
-								addressReturned = true;
-							}
-						}
-					}
-				}
 				assertTrue("validate that address with permission is returned",
 						addressReturned);
 			}
@@ -215,22 +196,22 @@
 			// validate that we can get the interface by specifying the address.
 			// This is to be compatible
 			for (int i = 0; i < notOkAddresses.size(); i++) {
-                                assertNotNull(
-                                                "validate we cannot get the NetworkInterface
with an address for which we have no privs",
-                                                NetworkInterface
-                                                                .getByInetAddress((InetAddress)
notOkAddresses
-                                                                                .get(i)));
-			}
+                assertNotNull(
+                        "validate we cannot get the NetworkInterface with an address for
which we have no privs",
+                        NetworkInterface
+                                .getByInetAddress((InetAddress) notOkAddresses
+                                        .get(i)));
+            }
 
 			// validate that we can get the network interface for the good
 			// addresses
-                        for (int i = 0; i < okAddresses.size(); i++) {
-                                assertNotNull(
-                                                "validate we cannot get the NetworkInterface
with an address fro which we have no privs",
-                                                NetworkInterface
-                                                                .getByInetAddress((InetAddress)
okAddresses
-                                                                                .get(i)));
-                        }
+			for (int i = 0; i < okAddresses.size(); i++) {
+                assertNotNull(
+                        "validate we cannot get the NetworkInterface with an address fro
which we have no privs",
+                        NetworkInterface
+                                .getByInetAddress((InetAddress) okAddresses
+                                        .get(i)));
+            }
 
 			System.setSecurityManager(null);
 		}
@@ -274,10 +255,10 @@
 		if (atLeastOneInterface) {
 			String theName = networkInterface1.getName();
 			if (theName != null) {
-                                assertTrue("validate that Interface can be obtained with
its name",
-                                                NetworkInterface.getByName(theName).equals(
-                                                                networkInterface1));
-			}
+                assertEquals(
+                        "validate that Interface can be obtained with its name",
+                        networkInterface1, NetworkInterface.getByName(theName));
+            }
 		}
 
 		// validate that we get the right interface with the second interface as
@@ -285,10 +266,10 @@
 		if (atLeastTwoInterfaces) {
 			String theName = networkInterface2.getName();
 			if (theName != null) {
-				assertTrue("validate that Interface can be obtained with its name",
-                                                NetworkInterface.getByName(theName).equals(
-                                                                networkInterface2));
-			}
+                assertEquals(
+                        "validate that Interface can be obtained with its name",
+                        networkInterface2, NetworkInterface.getByName(theName));
+            }
 		}
 	}
 
@@ -319,30 +300,26 @@
 		// interface for that address
 		if (atLeastOneInterface) {
 			Enumeration addresses = networkInterface1.getInetAddresses();
-			if (addresses != null) {
-				while (addresses.hasMoreElements()) {
-					InetAddress theAddress = (InetAddress) addresses
-							.nextElement();
-                                        assertTrue("validate that Interface can be obtained
with any one of its addresses",
-                                                        NetworkInterface.getByInetAddress(theAddress)
-                                                                        .equals(networkInterface1));
-				}
-			}
+			while (addresses.hasMoreElements()) {
+                InetAddress theAddress = (InetAddress) addresses.nextElement();
+                assertEquals(
+                        "validate that Interface can be obtained with any one of its addresses",
+                        networkInterface1, NetworkInterface
+                                .getByInetAddress(theAddress));
+            }
 		}
 
 		// validate that we get the right interface with the second interface as
 		// well (ie we just don't always get the first interface
 		if (atLeastTwoInterfaces) {
 			Enumeration addresses = networkInterface2.getInetAddresses();
-			if (addresses != null) {
-				while (addresses.hasMoreElements()) {
-					InetAddress theAddress = (InetAddress) addresses
-							.nextElement();
-                                        assertTrue("validate that Interface can be obtained
with any one of its addresses",
-                                                        NetworkInterface.getByInetAddress(theAddress)
-                                                                        .equals(networkInterface2));
-				}
-			}
+			while (addresses.hasMoreElements()) {
+                InetAddress theAddress = (InetAddress) addresses.nextElement();
+                assertEquals(
+                        "validate that Interface can be obtained with any one of its addresses",
+                        networkInterface2, NetworkInterface
+                                .getByInetAddress(theAddress));
+            }
 		}
 	}
 
@@ -363,11 +340,10 @@
 		// Test for method boolean
 		// java.net.SocketPermission.equals(java.lang.Object)
 		if (atLeastOneInterface) {
-			assertTrue("If objects are the same true is returned",
-					networkInterface1.equals(sameAsNetworkInterface1));
-			assertFalse("Validate Null handled ok", networkInterface1
-					.equals(null));
-		}
+            assertEquals("If objects are the same true is returned",
+                    sameAsNetworkInterface1, networkInterface1);
+            assertNotNull("Validate Null handled ok", networkInterface1);
+        }
 		if (atLeastTwoInterfaces) {
 			assertFalse("If objects are different false is returned",
 					networkInterface1.equals(networkInterface2));
@@ -431,7 +407,7 @@
 					&& (atLeastOneInterface == false)) {
 				NetworkInterface theInterface = (NetworkInterface) theInterfaces
 						.nextElement();
-				if (theInterface.getInetAddresses() != null) {
+				if (theInterface.getInetAddresses().hasMoreElements()) {
 					// Ensure that the current NetworkInterface has at least
 					// one InetAddress bound to it.  
 					Enumeration addrs = theInterface.getInetAddresses();
@@ -446,7 +422,7 @@
 					&& (atLeastTwoInterfaces == false)) {
 				NetworkInterface theInterface = (NetworkInterface) theInterfaces
 						.nextElement();
-				if (theInterface.getInetAddresses() != null) {
+				if (theInterface.getInetAddresses().hasMoreElements()) {
 					// Ensure that the current NetworkInterface has at least
 					// one InetAddress bound to it.  
 					Enumeration addrs = theInterface.getInetAddresses();
@@ -461,7 +437,7 @@
 			// at least one good NetworkInterface
 			if (atLeastOneInterface) {
 				Enumeration addresses = networkInterface1.getInetAddresses();
-				if (addresses != null) {
+				if (addresses.hasMoreElements()) {
 					try {
 						if (addresses.hasMoreElements()) {
 							sameAsNetworkInterface1 = NetworkInterface



Mime
View raw message