Index: modules/beans/make/common/build.xml =================================================================== --- modules/beans/make/common/build.xml (revision 415638) +++ modules/beans/make/common/build.xml (working copy) @@ -1,219 +1,216 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - beans - - - - beans - - - - - - - - - - - - - - - - - + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + beans + + + + beans + + + + + + + + + + + + + + + + + Index: modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java =================================================================== --- modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java (revision 415638) +++ modules/beans/src/main/java/org/apache/harmony/beans/java_lang_ClassPersistenceDelegate.java (working copy) @@ -33,7 +33,7 @@ */ public class java_lang_ClassPersistenceDelegate extends PersistenceDelegate { - + protected Expression instantiate(Object oldInstance, Encoder out) { Class value = (Class) oldInstance; Field fld = null; @@ -59,26 +59,33 @@ fld = Boolean.class.getField(TYPE); } } catch (NoSuchFieldException e) { - // impossible situation for valid java.lang classes - // implementation with version >= 1.1 + // impossible situation for valid java.lang classes + // implementation with version >= 1.1 } if (fld != null) { - // we have primitive type + // we have primitive type result = new Expression(oldInstance, fld, "get", - new Object[] {null}); + new Object[] {null}); } else { result = new Expression(oldInstance, Class.class, "forName", - new Object[] { new String(value.getName()) }); + new Object[] { new String(value.getName()) }); } return result; } - - protected void initialize( - Class type, Object oldInstance, Object newInstance, Encoder out) { - } - - // Added for testing purposes + + protected void initialize(Class type, Object oldInstance, + Object newInstance, Encoder out) {} + protected boolean mutatesTo(Object oldInstance, Object newInstance) { + if (oldInstance instanceof Class && newInstance instanceof Class) { + Class c1 = (Class) oldInstance; + Class c2 = (Class) newInstance; + + if (c1.getName().equals(c2.getName())) { + return true; + } + return false; + } return super.mutatesTo(oldInstance, newInstance); } } Index: modules/beans/src/main/java/org/apache/harmony/beans/java_lang_StringPersistenceDelegate.java =================================================================== --- modules/beans/src/main/java/org/apache/harmony/beans/java_lang_StringPersistenceDelegate.java (revision 415638) +++ modules/beans/src/main/java/org/apache/harmony/beans/java_lang_StringPersistenceDelegate.java (working copy) @@ -30,19 +30,21 @@ */ public class java_lang_StringPersistenceDelegate extends PersistenceDelegate { - + protected Expression instantiate(Object oldInstance, Encoder out) { String value = (String) oldInstance; + return new Expression(oldInstance, String.class, "new", - new Object[] { new String(value) }); + new Object[] {new String(value)}); } - - protected void initialize( - Class type, Object oldInstance, Object newInstance, Encoder out) { - } - - // Added for testing purposes + + protected void initialize(Class type, Object oldInstance, + Object newInstance, Encoder out) {} + protected boolean mutatesTo(Object oldInstance, Object newInstance) { + if (oldInstance instanceof String && newInstance instanceof String) { + return newInstance.equals(oldInstance); + } return super.mutatesTo(oldInstance, newInstance); } } Index: modules/beans/src/test/java-internal/org/apache/harmony/beans/ClassPersistenceDelegateTest.java =================================================================== --- modules/beans/src/test/java-internal/org/apache/harmony/beans/ClassPersistenceDelegateTest.java (revision 415639) +++ modules/beans/src/test/java-internal/org/apache/harmony/beans/ClassPersistenceDelegateTest.java (working copy) @@ -1,11 +1,11 @@ /* Copyright 2005 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,47 +25,52 @@ */ public class ClassPersistenceDelegateTest extends TestCase { - private java_lang_ClassPersistenceDelegate pd = null; + private java_lang_ClassPersistenceDelegate pd = null; - protected void setUp() throws Exception { - super.setUp(); - pd = new java_lang_ClassPersistenceDelegate(); - } + protected void setUp() throws Exception { + super.setUp(); + pd = new java_lang_ClassPersistenceDelegate(); + } - public void testMutates() { - assertFalse(pd.mutatesTo(Class.class, null)); - assertFalse(pd.mutatesTo(null, null)); - assertFalse(pd.mutatesTo(Class.class, String.class)); - assertTrue(pd.mutatesTo(String.class, String.class)); - } + public void testMutates() { + assertFalse(pd.mutatesTo(Class.class, null)); + assertFalse(pd.mutatesTo(null, null)); + assertFalse(pd.mutatesTo(Class.class, String.class)); + assertTrue(pd.mutatesTo(String.class, String.class)); + } - public void testInitialize() { - pd.initialize(null, null, null, null); - } + public void testInitialize() { + pd.initialize(null, null, null, null); + } - public void testInstantiate_Normal() throws Exception { - Expression exp = pd.instantiate(Integer.class, new Encoder()); - assertSame(Integer.class, exp.getValue()); - assertTrue(exp.getTarget() instanceof Class); - assertEquals("forName", exp.getMethodName()); - assertEquals(1, exp.getArguments().length); - assertEquals("java.lang.Integer", exp.getArguments()[0]); - } + public void testInstantiate_Normal() throws Exception { + Expression exp = pd.instantiate(Integer.class, new Encoder()); - public void testInstantiate_Class() throws Exception { - Expression exp = pd.instantiate(Class.class, new Encoder()); - assertSame(Class.class, exp.getValue()); - assertTrue(exp.getTarget() instanceof Class); - assertEquals("forName", exp.getMethodName()); - assertEquals(1, exp.getArguments().length); - assertEquals("java.lang.Class", exp.getArguments()[0]); - } + assertSame(Integer.class, exp.getValue()); + assertTrue(exp.getTarget() instanceof Class); + assertEquals("forName", exp.getMethodName()); + assertEquals(1, exp.getArguments().length); + assertEquals("java.lang.Integer", exp.getArguments()[0]); + } - public void testInstantiate_String() throws Exception { - Expression exp = pd.instantiate(String.class, new Encoder()); - assertSame(String.class, exp.getValue()); - assertSame("", exp.getTarget()); - assertEquals("getClass", exp.getMethodName()); - assertEquals(0, exp.getArguments().length); - } + public void testInstantiate_Primitive() throws Exception { + Expression exp = pd.instantiate(Integer.TYPE, new Encoder()); + + assertSame(Integer.TYPE, exp.getValue()); + assertTrue(exp.getTarget() instanceof java.lang.reflect.Field); + assertEquals("get", exp.getMethodName()); + assertEquals(1, exp.getArguments().length); + assertNull(exp.getArguments()[0]); + } + + + public void testInstantiate_Class() throws Exception { + Expression exp = pd.instantiate(Class.class, new Encoder()); + + assertSame(Class.class, exp.getValue()); + assertTrue(exp.getTarget() instanceof Class); + assertEquals("forName", exp.getMethodName()); + assertEquals(1, exp.getArguments().length); + assertEquals("java.lang.Class", exp.getArguments()[0]); + } } Index: modules/beans/src/test/java-internal/org/apache/harmony/beans/StringPersistenceDelegateTest.java =================================================================== --- modules/beans/src/test/java-internal/org/apache/harmony/beans/StringPersistenceDelegateTest.java (revision 415639) +++ modules/beans/src/test/java-internal/org/apache/harmony/beans/StringPersistenceDelegateTest.java (working copy) @@ -1,11 +1,11 @@ /* Copyright 2005 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. * You may obtain a copy of the License at - * + * * http://www.apache.org/licenses/LICENSE-2.0 - * + * * Unless required by applicable law or agreed to in writing, software * distributed under the License is distributed on an "AS IS" BASIS, * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. @@ -25,30 +25,31 @@ */ public class StringPersistenceDelegateTest extends TestCase { - private java_lang_StringPersistenceDelegate pd = null; + private java_lang_StringPersistenceDelegate pd = null; - protected void setUp() throws Exception { - super.setUp(); - pd = new java_lang_StringPersistenceDelegate(); - } + protected void setUp() throws Exception { + super.setUp(); + pd = new java_lang_StringPersistenceDelegate(); + } - public void testMutates() { - assertFalse(pd.mutatesTo("", null)); - assertFalse(pd.mutatesTo(null, null)); - assertFalse(pd.mutatesTo("str1", "str2")); - assertTrue(pd.mutatesTo("str1", "str2")); - } + public void testMutates() { + assertFalse(pd.mutatesTo("", null)); + assertFalse(pd.mutatesTo(null, null)); + assertFalse(pd.mutatesTo("str1", "str2")); + assertTrue(pd.mutatesTo("str1", "str1")); + } - public void testInitialize() { - pd.initialize(null, null, null, null); - } + public void testInitialize() { + pd.initialize(null, null, null, null); + } - public void testInstantiate_Normal() throws Exception { - Expression exp = pd.instantiate("str", new Encoder()); - assertSame("str", exp.getValue()); - assertSame(String.class, exp.getTarget()); - assertEquals("new", exp.getMethodName()); - assertEquals(1, exp.getArguments().length); - assertEquals("str", exp.getArguments()[0]); - } + public void testInstantiate_Normal() throws Exception { + Expression exp = pd.instantiate("str", new Encoder()); + + assertSame("str", exp.getValue()); + assertSame(String.class, exp.getTarget()); + assertEquals("new", exp.getMethodName()); + assertEquals(1, exp.getArguments().length); + assertEquals("str", exp.getArguments()[0]); + } }