harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From py...@apache.org
Subject svn commit: r475333 - in /incubator/harmony/enhanced/classlib/trunk/modules/jndi/src: main/java/javax/naming/InitialContext.java test/java/org/apache/harmony/jndi/tests/javax/naming/InitialContextMockTest.java
Date Wed, 15 Nov 2006 17:55:37 GMT
Author: pyang
Date: Wed Nov 15 09:55:36 2006
New Revision: 475333

URL: http://svn.apache.org/viewvc?view=rev&rev=475333
Log:
Apply patch for HARMONY-1686 ([luni][jndi] javax.naming.directory.InitialContext.composeName(null,Name)
does not throw unspecified NPE)

Modified:
    incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
    incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/InitialContextMockTest.java

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java?view=diff&rev=475333&r1=475332&r2=475333
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/main/java/javax/naming/InitialContext.java
Wed Nov 15 09:55:36 2006
@@ -426,30 +426,44 @@
         return getURLOrDefaultInitCtx(name).getNameParser(name);
     }
 
+    /**
+     * Composes the name of this context with a name relative to this context.
+     * Because an initial context could not be named relative to any context
+     * except itself, the value of the prefix parameter must be an empty name.
+     * 
+     * @param name
+     *            a name relative to this context.
+     * @param prefix
+     *            the name of this context relative to one of its ancestors.
+     * 
+     * @return the composition of prefix and name.
+     * @throws NamingException
+     *             if a naming exception happens.
+     */
     public Name composeName(Name name, Name prefix) throws NamingException {
         if (null == name) {
-            // jndi.02=Invalid name.
-            throw new InvalidNameException(Messages.getString("jndi.02"));  //$NON-NLS-1$
+            throw new NullPointerException();
         }
-        if (prefix == null) {
-            prefix = new CompositeName(""); //$NON-NLS-1$
-        }
-        Name comName = (Name) prefix.clone();
-        comName.addAll(name);
-        return comName;
+        return (Name) name.clone();
     }
 
+    /**
+     * Composes the name of this context with a name relative to this context.
+     * Because an initial context could not be named relative to any context
+     * except itself, the value of the prefix parameter must be an empty name.
+     * 
+     * @param name
+     *            a name relative to this context.
+     * @param prefix
+     *            the name of this context relative to one of its ancestors.
+     * 
+     * @return the composition of prefix and name.
+     * @throws NamingException
+     *             if a naming exception happens.
+     */
     public String composeName(String name, String prefix)
-        throws NamingException {
-        if (null == name) {
-            // jndi.02=Invalid name.
-            throw new InvalidNameException(Messages.getString("jndi.02"));  //$NON-NLS-1$
-        }
-        if (prefix == null) {
-            prefix = ""; //$NON-NLS-1$
-        }
-        return composeName(new CompositeName(name), new CompositeName(prefix))
-            .toString();
+            throws NamingException {
+        return name;
     }
 
     public Object addToEnvironment(String propName, Object propVal)

Modified: incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/InitialContextMockTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/InitialContextMockTest.java?view=diff&rev=475333&r1=475332&r2=475333
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/InitialContextMockTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/jndi/src/test/java/org/apache/harmony/jndi/tests/javax/naming/InitialContextMockTest.java
Wed Nov 15 09:55:36 2006
@@ -178,17 +178,7 @@
         gContext.composeName(name, pfx);
         // assertTrue(InvokeRecord.equals(null, name, pfx));
     }
-
-    public void testComposeName_name_null() throws NamingException {
-        log.setMethod("testComposeName_name_null");
-        Name empty = new CompositeName("");
-        try {
-            gContext.composeName((Name) null, empty);
-            fail("Should throw InvalidNameException.");
-        } catch (InvalidNameException e) {}
-        // assertFalse(InvokeRecord.equals(null, null, empty));
-    }
-
+    
     public void testComposeName_name_pfx_null() throws NamingException {
         log.setMethod("testComposeName_name_pfx_null");
         Name name = new CompositeName("namepfxnull");
@@ -196,14 +186,76 @@
         // assertFalse(InvokeRecord.equals(null, name, null));
     }
 
-    public void testComposeName_string_null() throws NamingException {
-        log.setMethod("testComposeName_string_null");
-        String pfx = "";
+    /**
+     * @tests javax.naming.InitialContext#composeName(Name,Name)
+     */
+    public void testComposeNameLjavax_naming_NameLjavax_naming_Name()
+            throws NamingException {
+        log.setMethod("testComposeName_string_null"); //$NON-NLS-1$
+        InitialContext initialContext = new InitialContext();
+
+        try {
+            initialContext.composeName((CompositeName) null,
+                    (CompositeName) null);
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
         try {
-            gContext.composeName((String) null, pfx);
-            fail("Should throw InvalidNameException.");
-        } catch (InvalidNameException e) {}
-        // assertFalse(InvokeRecord.equals(null, null, pfx));
+            initialContext.composeName(null, new CompositeName("prefix")); //$NON-NLS-1$
+            fail("Should throw NullPointerException"); //$NON-NLS-1$
+        } catch (NullPointerException e) {
+            // expected
+        }
+        
+        Name result = initialContext.composeName(
+                new CompositeName("a/b/c"), (CompositeName) null); //$NON-NLS-1$
+        assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
+
+        result = initialContext.composeName(
+                new CompositeName("a/b/c"), new CompositeName("")); //$NON-NLS-1$//$NON-NLS-2$
+        assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
+        
+        result = initialContext.composeName(
+                new CompositeName("a/b/c"), new CompositeName("prefix")); //$NON-NLS-1$//$NON-NLS-2$
+        assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
+
+        result = initialContext.composeName(
+                new CompositeName("testString"), new CompositeName("a/b/c/d")); //$NON-NLS-1$//$NON-NLS-2$
+        assertEquals("testString", result.toString()); //$NON-NLS-1$
+        
+        CompositeName cn = new CompositeName("a/b/c"); //$NON-NLS-1$
+        result = initialContext.composeName(cn, new CompositeName("prefix")); //$NON-NLS-1$
+        cn.add("/d"); //$NON-NLS-1$
+        assertEquals("a/b/c", result.toString()); //$NON-NLS-1$
+    }
+    
+    /**
+     * @tests javax.naming.InitialContext#composeName(String,String)
+     */
+    public void testComposeNameLjava_lang_StringLjava_lang_String()
+            throws NamingException {
+        log.setMethod("testComposeName_string_null"); //$NON-NLS-1$
+        InitialContext initialContext = new InitialContext();
+
+        String result = initialContext.composeName((String) null, (String) null);
+        assertNull(result);
+
+        result = initialContext.composeName((String) null, ""); //$NON-NLS-1$
+        assertNull(result);
+
+        result = initialContext.composeName("a/b/c", (String) null); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("a/b/c", result); //$NON-NLS-1$
+        
+        result = initialContext.composeName("a/b/c", ""); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("a/b/c", result); //$NON-NLS-1$
+        
+        result = initialContext.composeName("a/b/c", "prefix"); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("a/b/c", result); //$NON-NLS-1$
+
+        result = initialContext.composeName("testString", "a/b/c/d"); //$NON-NLS-1$ //$NON-NLS-2$
+        assertEquals("testString", result); //$NON-NLS-1$
     }
 
     public void testComposeName_string_pfx_null() throws NamingException {



Mime
View raw message