harmony-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Stepan Mishura" <stepan.mish...@gmail.com>
Subject Re: svn commit: r396013 - in /incubator/harmony/enhanced/classlib/trunk/modules/luni/src: main/java/java/net/Inet6Address.java main/java/java/net/InetAddress.java test/java/tests/api/java/net/Inet6AddressTest.java
Date Mon, 24 Apr 2006 07:22:49 GMT
Hi,

I thought that we agreed on utilizing JUnit's exception handling (see [1]).
So the next code from added unit test doesn't follow this convention. Also
why it checks the same code twice?

try {
    Inet6Address.getByAddress("123", addr2, 3);
} catch (UnknownHostException e) {
    fail("no exception should be thrown");
}
try {
    Inet6Address.getByAddress("123", addr2, 3);
} catch (UnknownHostException e) {
    fail("no exception should be thrown");
}


Thanks,
Stepan.

[1] http://www.javaworld.com/javaworld/jw-12-2000/jw-1221-junit_p.html

>-----Original Message-----
>From: tellison@apache.org [mailto:tellison@apache.org]
>Sent: Saturday, April 22, 2006 4:52 AM
>To: harmony-commits@incubator.apache.org
>Subject: svn commit: r396013 - in
>/incubator/harmony/enhanced/classlib/trunk/modules/luni/src:
>main/java/java/net/Inet6Address.java main/java/java/net/InetAddress.java
>test/java/tests/api/java/net/Inet6AddressTest.java
>
>Author: tellison
>Date: Fri Apr 21 14:52:02 2006
>New Revision: 396013
>
>URL: http://svn.apache.org/viewcvs?rev=396013&view=rev
>Log:
>Apply patch HARMONY-360 (Java 5 Enhancement: One new method
>getByAddress(String, byte[], int) in class java.net.Inet6Address)
>
>Modified:
>
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/Inet6Address.java
>
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/InetAddress.java
>
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/
>api/java/net/Inet6AddressTest.java
>
>Modified:
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/Inet6Address.java
>URL:
>http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/mod
>ules/luni/src/main/java/java/net/Inet6Address.java?rev=396013&r1=396012&r2=
>396013&view=diff
>===========================================================================
>===
>---
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/Inet6Address.java (original)
>+++
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/Inet6Address.java Fri Apr 21 14:52:02 2006
>@@ -1,4 +1,4 @@
>-/* Copyright 2003, 2005 The Apache Software Foundation or its licensors,
>as applicable
>+/* Copyright 2003, 2006 The Apache Software Foundation or its licensors,
>as applicable
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>@@ -58,7 +58,7 @@
>   * @param address
>   *            network address
>   * @param name
>-  *            Name assocaited with the address
>+  *            Name associated with the address
>   * @param scope_id
>   *            The scope id for link or site local addresses
>   */
>@@ -71,6 +71,31 @@
>   }
>  }
>
>+ /**
>+  * Constructs an IPv6 address according to the given
><code>host</code>,
>+  * <code>addr</code> and <code>scope_id</code>.
>+  *
>+  * @param host
>+  *            hostname associated with the address
>+  * @param addr
>+  *            network address
>+  * @param scope_id
>+  *            the scope id for link or site local addresses
>+  * @return an Inet6Address instance
>+  * @throws UnknownHostException
>+  *             if the address is null or of invalid length
>+  */
>+ public static Inet6Address getByAddress(String host, byte[] addr,
>+   int scope_id) throws UnknownHostException {
>+  if (null == addr || 16 != addr.length) {
>+   throw new UnknownHostException("Illegal ipv6 address");
>+  }
>+  if(scope_id < 0){
>+   scope_id = 0;
>+  }
>+  return new Inet6Address(addr, host, scope_id);
>+ }
>+
>  /**
>   * Constructs an InetAddress, representing the <code>address</code>
>and
>   * <code>hostName</code> and <code>scope_id</code>
>
>Modified:
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/InetAddress.java
>URL:
>http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/mod
>ules/luni/src/main/java/java/net/InetAddress.java?rev=396013&r1=396012&r2=3
>96013&view=diff
>===========================================================================
>===
>---
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/InetAddress.java (original)
>+++
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/main/java/java/n
>et/InetAddress.java Fri Apr 21 14:52:02 2006
>@@ -1,4 +1,4 @@
>-/* Copyright 1998, 2005 The Apache Software Foundation or its licensors,
>as applicable
>+/* Copyright 1998, 2006 The Apache Software Foundation or its licensors,
>as applicable
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>@@ -813,7 +813,7 @@
>    throws UnknownHostException {
>   // just call the method by the same name passing in a default
>scope id
>   // of 0
>-  return getByAddress(hostName, ipAddress, 0);
>+  return getByAddressInternal(hostName, ipAddress, 0);
>  }
>
>  /**
>@@ -837,7 +837,7 @@
>   *
>   * @throws   UnknownHostException
>   */
>- static InetAddress getByAddress(String hostName, byte[] ipAddress,
>+ static InetAddress getByAddressInternal(String hostName, byte[]
>ipAddress,
>    int scope_id) throws UnknownHostException {
>   byte[] copy_address;
>   if (ipAddress != null && ipAddress.length == 4) {
>
>Modified:
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/
>api/java/net/Inet6AddressTest.java
>URL:
>http://svn.apache.org/viewcvs/incubator/harmony/enhanced/classlib/trunk/mod
>ules/luni/src/test/java/tests/api/java/net/Inet6AddressTest.java?rev=396013
>&r1=396012&r2=396013&view=diff
>===========================================================================
>===
>---
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/
>api/java/net/Inet6AddressTest.java (original)
>+++
>incubator/harmony/enhanced/classlib/trunk/modules/luni/src/test/java/tests/
>api/java/net/Inet6AddressTest.java Fri Apr 21 14:52:02 2006
>@@ -1,4 +1,4 @@
>-/* Copyright 2003, 2005 The Apache Software Foundation or its licensors,
>as applicable
>+/* Copyright 2003, 2006 The Apache Software Foundation or its licensors,
>as applicable
>  *
>  * Licensed under the Apache License, Version 2.0 (the "License");
>  * you may not use this file except in compliance with the License.
>@@ -825,6 +825,40 @@
>    }
>    ;
>
>+  }
>+ }
>+
>+ /**
>+  * @tests java.net.Inet6Address#getByAddress(String, byte[], int)
>+  */
>+ public void test_getByAddressLString$BI(){
>+  try {
>+   Inet6Address.getByAddress("123", null, 0);
>+   fail("should throw UnknownHostException");
>+  } catch (UnknownHostException uhe) {
>+   // expected
>+  }
>+  byte[] addr1 = { (byte) 127, 0, 0, 1 };
>+  try {
>+   Inet6Address.getByAddress("123", addr1, 0);
>+   fail("should throw UnknownHostException");
>+  } catch (UnknownHostException uhe) {
>+   // expected
>+  }
>+
>+  byte[] addr2 = { (byte) 0xFE, (byte) 0x80, 0, 0, 0, 0, 0, 0,
>0x02,
>+    0x11, 0x25, (byte) 0xFF, (byte) 0xFE, (byte) 0xF8,
>(byte) 0x7C,
>+    (byte) 0xB2 };
>+
>+  try {
>+   Inet6Address.getByAddress("123", addr2, 3);
>+  } catch (UnknownHostException e) {
>+   fail("no exception should be thrown");
>+  }
>+  try {
>+   Inet6Address.getByAddress("123", addr2, 3);
>+  } catch (UnknownHostException e) {
>+   fail("no exception should be thrown");
>   }
>  }
>


--
Thanks,
Stepan Mishura
Intel Middleware Products Division

------------------------------------------------------
Terms of use : http://incubator.apache.org/harmony/mailing.html
To unsubscribe, e-mail: harmony-dev-unsubscribe@incubator.apache.org
For additional commands, e-mail: harmony-dev-help@incubator.apache.org

Mime
  • Unnamed multipart/alternative (inline, None, 0 bytes)
View raw message