You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@harmony.apache.org by py...@apache.org on 2007/07/19 10:09:59 UTC
svn commit: r557518 [2/2] - in
/harmony/enhanced/classlib/branches/java6/modules:
awt/src/main/java/common/org/apache/harmony/awt/gl/font/
awt/src/main/java/common/org/apache/harmony/awt/gl/font/fontlib/
awt/src/main/native/fontlib/shared/ beans/META-I...
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/PropertyEditorManager.java Thu Jul 19 01:09:53 2007
@@ -54,8 +54,14 @@
PropertyEditor editor = null;
editorClass = registeredEditors.get(targetType);
-
- if (editorClass == null) {
+ if (editorClass != null) {
+ try {
+ editor = (PropertyEditor) editorClass.newInstance();
+ } catch (Exception e) {
+ }
+ }
+
+ if (editor == null) {
String editorClassName = targetType.getName() + "Editor"; //$NON-NLS-1$
ClassLoader loader = targetType.getClassLoader();
@@ -65,6 +71,7 @@
try {
editorClass = Class.forName(editorClassName, true, loader);
+ return (PropertyEditor) editorClass.newInstance();
} catch (ClassNotFoundException cnfe) {
String shortEditorClassName = editorClassName
.substring(editorClassName.lastIndexOf(".") + 1); //$NON-NLS-1$
@@ -81,21 +88,22 @@
try {
editorClass = Class.forName(editorClassName, true,
loader);
+ editorClass.asSubclass(PropertyEditorSupport.class);
break;
} catch (Exception e) {
}
}
} catch (Exception e) {
}
- }
-
- if (editorClass != null) {
- try {
- editor = (PropertyEditor) editorClass.newInstance();
- } catch (Exception e) {
+ if(editorClass != null){
+ try {
+ //FIXME: cache is still needed, but need more investigation to make tests pass
+// registeredEditors.put(targetType, editorClass);
+ editor = (PropertyEditor) editorClass.newInstance();
+ } catch (Exception e) {
+ }
}
}
-
return editor;
}
@@ -113,6 +121,6 @@
}
public static synchronized String[] getEditorSearchPath() {
- return path;
+ return path.clone();
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/VetoableChangeSupport.java Thu Jul 19 01:09:53 2007
@@ -26,19 +26,17 @@
import java.util.Iterator;
import java.util.List;
-//FIXME: obviously need synchronization, when access listeners
+// FIXME: obviously need synchronization, when access listeners
public class VetoableChangeSupport implements Serializable {
private static final long serialVersionUID = -5090210921595982017l;
private Hashtable<String, VetoableChangeSupport> children = new Hashtable<String, VetoableChangeSupport>();
-
+
private transient ArrayList<VetoableChangeListener> globalListeners = new ArrayList<VetoableChangeListener>();
-
- private Object source;
- private int vetoableChangeSupportSerializedDataVersion = 2;
+ private Object source;
public VetoableChangeSupport(Object sourceBean) {
if (sourceBean == null) {
@@ -50,8 +48,7 @@
public synchronized void removeVetoableChangeListener(String propertyName,
VetoableChangeListener listener) {
if ((propertyName != null) && (listener != null)) {
- VetoableChangeSupport listeners = children
- .get(propertyName);
+ VetoableChangeSupport listeners = children.get(propertyName);
if (listeners != null) {
listeners.removeVetoableChangeListener(listener);
@@ -62,8 +59,7 @@
public synchronized void addVetoableChangeListener(String propertyName,
VetoableChangeListener listener) {
if (propertyName != null && listener != null) {
- VetoableChangeSupport listeners = children
- .get(propertyName);
+ VetoableChangeSupport listeners = children.get(propertyName);
if (listeners == null) {
listeners = new VetoableChangeSupport(source);
@@ -87,8 +83,7 @@
public synchronized boolean hasListeners(String propertyName) {
boolean result = globalListeners.size() > 0;
if (!result && propertyName != null) {
- VetoableChangeSupport listeners = children
- .get(propertyName);
+ VetoableChangeSupport listeners = children.get(propertyName);
if (listeners != null) {
result = listeners.globalListeners.size() > 0;
}
@@ -105,7 +100,7 @@
public synchronized void addVetoableChangeListener(
VetoableChangeListener listener) {
- if(listener != null){
+ if (listener != null) {
if (listener instanceof VetoableChangeListenerProxy) {
VetoableChangeListenerProxy proxy = (VetoableChangeListenerProxy) listener;
addVetoableChangeListener(proxy.getPropertyName(),
@@ -140,7 +135,8 @@
private void writeObject(ObjectOutputStream oos) throws IOException {
oos.defaultWriteObject();
- VetoableChangeListener[] copy = new VetoableChangeListener[globalListeners.size()];
+ VetoableChangeListener[] copy = new VetoableChangeListener[globalListeners
+ .size()];
globalListeners.toArray(copy);
for (VetoableChangeListener listener : copy) {
if (listener instanceof Serializable) {
@@ -152,7 +148,6 @@
}
-
private void readObject(ObjectInputStream ois) throws IOException,
ClassNotFoundException {
ois.defaultReadObject();
@@ -167,7 +162,7 @@
addVetoableChangeListener((VetoableChangeListener) listener);
} while (listener != null);
}
-
+
public void fireVetoableChange(String propertyName, boolean oldValue,
boolean newValue) throws PropertyVetoException {
PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
@@ -181,14 +176,14 @@
oldValue, newValue);
doFirePropertyChange(event);
}
-
+
public void fireVetoableChange(String propertyName, Object oldValue,
Object newValue) throws PropertyVetoException {
PropertyChangeEvent event = createPropertyChangeEvent(propertyName,
oldValue, newValue);
doFirePropertyChange(event);
}
-
+
public void fireVetoableChange(PropertyChangeEvent event)
throws PropertyVetoException {
doFirePropertyChange(event);
@@ -196,8 +191,7 @@
private PropertyChangeEvent createPropertyChangeEvent(String propertyName,
Object oldValue, Object newValue) {
- return new PropertyChangeEvent(source, propertyName, oldValue,
- newValue);
+ return new PropertyChangeEvent(source, propertyName, oldValue, newValue);
}
private void doFirePropertyChange(PropertyChangeEvent event)
@@ -219,7 +213,7 @@
listensToAll = globalListeners
.toArray(new VetoableChangeListener[0]);
String propertyName = event.getPropertyName();
- if(propertyName != null){
+ if (propertyName != null) {
listeners = children.get(propertyName);
}
}
@@ -240,7 +234,7 @@
}
throw pve;
}
- if(listeners != null){
+ if (listeners != null) {
listeners.fireVetoableChange(event);
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/java/beans/XMLEncoder.java Thu Jul 19 01:09:53 2007
@@ -28,7 +28,6 @@
import java.lang.reflect.Proxy;
import java.util.ArrayList;
import java.util.Collections;
-import java.util.IdentityHashMap;
import java.util.Iterator;
import java.util.List;
@@ -93,7 +92,7 @@
private Object owner = null;
- private IdentityHashMap records = new IdentityHashMap();
+ private ReferenceMap records = new ReferenceMap();
private boolean writingObject = false;
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/ColorEditor.java Thu Jul 19 01:09:53 2007
@@ -68,6 +68,17 @@
}
}
+ public String getAsText(){
+ Color c = (Color)getValue();
+ StringBuilder sb = new StringBuilder(14);
+ sb.append(c.getRed());
+ sb.append(",");
+ sb.append(c.getGreen());
+ sb.append(",");
+ sb.append(c.getBlue());
+ return sb.toString();
+ }
+
@Override
public void setAsText(String text) {
if (null == text) {
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/main/java/org/apache/harmony/beans/editors/FontEditor.java Thu Jul 19 01:09:53 2007
@@ -20,66 +20,126 @@
import java.awt.Component;
import java.awt.Font;
import java.awt.Graphics;
+import java.awt.Panel;
import java.awt.Rectangle;
-import java.beans.PropertyEditorSupport;
-
-public class FontEditor extends PropertyEditorSupport {
-
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
+import java.beans.PropertyEditor;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.List;
+
+public class FontEditor extends Panel implements PropertyEditor {
+
+ List<PropertyChangeListener> listeners = new ArrayList<PropertyChangeListener>();
+
+ private Font value;
+
+ private Object source;
+
public FontEditor(Object source) {
- super(source);
+ if(source== null){
+ throw new NullPointerException();
+ }
+ this.source = (Font)source;
}
public FontEditor() {
super();
}
- @Override
public Component getCustomEditor() {
- return null;
+ return this;
}
- @Override
public boolean supportsCustomEditor() {
return true;
}
- @Override
public String getJavaInitializationString() {
String result = null;
- Font font = (Font) getValue();
- if (font != null) {
- String name = font.getName();
- int style = font.getStyle();
- int size = font.getSize();
+ if (value!= null) {
+ String name = value.getName();
+ int style = value.getStyle();
+ int size = value.getSize();
result = "new Font(" + name + "," + style + "," + size + ")"; //$NON-NLS-1$ //$NON-NLS-2$ //$NON-NLS-3$ //$NON-NLS-4$
}
return result;
}
- @Override
public String[] getTags() {
return null;
}
- @Override
- public void setValue(Object value) {
- if (value instanceof Font) {
- super.setValue(value);
+ public void setValue(Object newValue) {
+ if(newValue == null){
+ throw new NullPointerException();
+ }
+ Object oldValue = value;
+ value = (Font)newValue;
+ PropertyChangeEvent changeAllEvent = new PropertyChangeEvent(this,
+ "value", oldValue, value);
+ PropertyChangeListener[] copy = new PropertyChangeListener[listeners.size()];
+ listeners.toArray(copy);
+ for (PropertyChangeListener listener : copy) {
+ listener.propertyChange(changeAllEvent);
}
}
- @Override
public boolean isPaintable() {
return true;
}
- @Override
public void paintValue(Graphics gfx, Rectangle box) {
Font font = (Font) getValue();
if (font != null) {
gfx.setFont(font);
gfx.drawBytes("Hello".getBytes(), box.x, box.y, box.x + box.width, //$NON-NLS-1$
box.y + box.height);
+ }
+ }
+
+ public String getAsText() {
+ return null;
+ }
+
+ public Object getValue() {
+ return value;
+ }
+
+ public void setAsText(String text) throws IllegalArgumentException {
+ throw new IllegalArgumentException(text==null?text:value.toString());
+ }
+
+ public synchronized void removePropertyChangeListener(
+ PropertyChangeListener listener) {
+ if (listeners != null) {
+ listeners.remove(listener);
+ }
+ }
+
+ public synchronized void addPropertyChangeListener(
+ PropertyChangeListener listener) {
+ listeners.add(listener);
+ }
+
+ public void firePropertyChange() {
+ if (listeners.isEmpty()) {
+ return;
+ }
+
+ List<PropertyChangeListener> copy = new ArrayList<PropertyChangeListener>(
+ listeners.size());
+ synchronized (listeners) {
+ copy.addAll(listeners);
+ }
+
+ PropertyChangeEvent changeAllEvent = new PropertyChangeEvent(source,
+ null, null, null);
+ for (Iterator<PropertyChangeListener> listenersItr = copy.iterator(); listenersItr
+ .hasNext();) {
+ PropertyChangeListener listna = listenersItr.next();
+ listna.propertyChange(changeAllEvent);
}
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/DefaultPersistenceDelegateTest.java Thu Jul 19 01:09:53 2007
@@ -26,27 +26,27 @@
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
import java.beans.Statement;
-
-import java.util.Vector;
import java.util.Iterator;
+import java.util.Vector;
import junit.framework.TestCase;
import junit.framework.TestSuite;
import org.apache.harmony.beans.tests.support.mock.MockFoo;
import org.apache.harmony.beans.tests.support.mock.MockFoo2;
-import org.apache.harmony.beans.tests.support.mock.MockFooStop;
import org.apache.harmony.beans.tests.support.mock.MockFooLabel;
+import org.apache.harmony.beans.tests.support.mock.MockFooStop;
import tests.util.CallVerificationStack;
/**
- * Tests the class java.beans.DefaultPersistenceDelegate
- * TODO refactor the class and remove all references to CallVerificationStack
+ * Tests the class java.beans.DefaultPersistenceDelegate TODO refactor the class
+ * and remove all references to CallVerificationStack
*/
public class DefaultPersistenceDelegateTest extends TestCase {
-
- public DefaultPersistenceDelegateTest() {}
+
+ public DefaultPersistenceDelegateTest() {
+ }
public DefaultPersistenceDelegateTest(String s) {
super(s);
@@ -61,13 +61,13 @@
Introspector.flushCaches();
CallVerificationStack.getInstance().clear();
}
-
+
public static TestSuite suite() {
-// TestSuite suite = new TestSuite();
+ // TestSuite suite = new TestSuite();
TestSuite suite = new TestSuite(DefaultPersistenceDelegateTest.class);
-
-// suite.addTest(new DefaultPersistenceDelegateTest(
-// "testInitialize_NotRegularGetter"));
+
+ // suite.addTest(new DefaultPersistenceDelegateTest(
+ // "testInitialize_NotRegularGetter"));
return suite;
}
@@ -158,12 +158,13 @@
"prop1", null });
MockBean b = new MockBean();
b.setAll("bean1", 2);
- try {
- pd.instantiate(b, new Encoder());
- fail("Should throw NullPointerException!");
- } catch (NullPointerException ex) {
- // expected
- }
+ pd.instantiate(b, new Encoder());
+
+ pd = new MockPersistenceDelegate(new String[] {
+ "prop1", null, "prop2"});
+ MockBean b2 = new MockBean();
+ b2.setAll("bean1", 2);
+ pd.instantiate(b2, new Encoder());
}
/*
@@ -174,12 +175,7 @@
"prop1", "" });
MockBean b = new MockBean();
b.setAll("bean1", 2);
- try {
- pd.instantiate(b, null);
- fail("Should throw NullPointerException!");
- } catch (NullPointerException ex) {
- // expected
- }
+ pd.instantiate(b, null);
}
/*
@@ -366,8 +362,8 @@
* method, defined by its beaninfo.
*/
public void testInstantiate_NotRegularGetter() throws Exception {
- MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[] {
- "prop"});
+ MockPersistenceDelegate pd = new MockPersistenceDelegate(
+ new String[] { "prop" });
MockFoo2 b = new MockFoo2(2);
Expression e = pd.instantiate(b, new Encoder());
@@ -375,16 +371,15 @@
assertSame(MockFoo2.class, e.getTarget());
assertEquals("new", e.getMethodName());
assertEquals(1, e.getArguments().length);
- assertEquals(new Integer(2), e.getArguments()[0]);
+ assertNull(e.getArguments()[0]);
}
-
/*
* Tests mutatesTo() under normal conditions without any properties.
*/
public void testMutatesTo_NormalNoProperty() {
MockPersistenceDelegate pd = new MockPersistenceDelegate();
-
+
assertTrue(pd.mutatesTo("test1", "test1"));
assertFalse(pd.mutatesTo(new Object(), new Object() {
@Override
@@ -428,7 +423,7 @@
*/
public void testMutatesTo_NormalWithEmptyPropertyPublicEqualMethod() {
MockPersistenceDelegate pd = new MockPersistenceDelegate(new String[0]);
-
+
assertTrue(pd.mutatesTo("test1", "test1"));
}
@@ -487,6 +482,31 @@
assertTrue(o1.equalsCalled);
}
+ public void test_mutatesTo_Object() {
+ Object o1 = new Object();
+ Object o2 = new Object();
+ MockPersistenceDelegate mockPersistenceDelegate = new MockPersistenceDelegate();
+ assertTrue(mockPersistenceDelegate.mutatesTo(o1, o2));
+ }
+
+ public void test_initialize() {
+ MockBean3 bean1 = new MockBean3();
+ bean1.setValue("bean1");
+ MockBean3 bean2 = new MockBean3();
+ bean2.setValue("bean2");
+
+ // clear flags
+ bean1.setValueCalled = false;
+ bean2.setValueCalled = false;
+
+ MockPersistenceDelegate mockPersistenceDelegate = new MockPersistenceDelegate();
+ mockPersistenceDelegate.initialize(MockBean3.class, bean1, bean2,
+ new Encoder());
+ assertEquals("bean1", bean1.getValue());
+ assertEquals("bean2", bean2.getValue());
+ assertFalse(bean1.setValueCalled);
+ assertFalse(bean2.setValueCalled);
+ }
public void test_mutates_with_equals_false() {
MyObjectEqualsFalse o1 = new MyObjectEqualsFalse();
@@ -579,12 +599,12 @@
pd.writeObject(oldBean, enc);
enc.clearCache();
pd.initialize(MockFoo.class, oldBean, new MockFoo(), enc);
-
+
assertNotNull(findStatement(enc.statements(), oldBean, "setName",
new Object[] { oldBean.getName() }));
assertNotNull(findStatement(enc.statements(), oldBean, "setLabel",
new Object[] { oldBean.getLabel() }));
-
+
enc = new CollectingEncoder();
oldBean = new MockFoo();
oldBean.setComplexLabel(new MockFooLabel("myComplexLabel"));
@@ -613,34 +633,32 @@
pd.initialize(MockFoo2.class, b, b2, enc);
// XXX RI stores much more statements to the stream
- iter = enc.statements();
-// assertNotNull("required statement not found",
-// findStatement(iter, b, "myget", null));
- assertNotNull("required statement not found",
- findStatement(iter, null, "myset",
- new Object[] {new Integer(2)}));
+ iter = enc.statements();
+ // assertNotNull("required statement not found",
+ // findStatement(iter, b, "myget", null));
+ assertNotNull("required statement not found", findStatement(iter, null,
+ "myset", new Object[] { new Integer(2) }));
}
/*
- * Test initialize() when oldInstance == newInstance.
- * XXX The current implementation outputs nothing to the stream. And this
- * seems to be correct from the spec point of view since we need not to do
- * any actions to convert the object to itself. However, RI outputs a lot
- * of stuff to the stream here.
- */
-// public void testInitialize_SameInstance() throws Exception {
-// CollectingEncoder enc = new CollectingEncoder();
-// MockPersistenceDelegate pd = new MockPersistenceDelegate();
-// MockFoo b = new MockFoo();
-// Iterator<Statement> iter;
-//
-// b.setName("mymyName");
-// // b.setLabel("myLabel");
-//
-// pd.initialize(MockFoo.class, b, b, enc);
-//
-// }
-
+ * Test initialize() when oldInstance == newInstance. XXX The current
+ * implementation outputs nothing to the stream. And this seems to be
+ * correct from the spec point of view since we need not to do any actions
+ * to convert the object to itself. However, RI outputs a lot of stuff to
+ * the stream here.
+ */
+ // public void testInitialize_SameInstance() throws Exception {
+ // CollectingEncoder enc = new CollectingEncoder();
+ // MockPersistenceDelegate pd = new MockPersistenceDelegate();
+ // MockFoo b = new MockFoo();
+ // Iterator<Statement> iter;
+ //
+ // b.setName("mymyName");
+ // // b.setLabel("myLabel");
+ //
+ // pd.initialize(MockFoo.class, b, b, enc);
+ //
+ // }
/*
* Test initialize() with a bean with a transient property.
*/
@@ -648,14 +666,14 @@
CollectingEncoder enc = new CollectingEncoder();
MockPersistenceDelegate pd = new MockPersistenceDelegate();
MockTransientBean b = new MockTransientBean();
-
+
b.setName("myName");
pd.writeObject(b, enc);
enc.clearCache();
pd.initialize(MockTransientBean.class, b, new MockTransientBean(), enc);
- assertFalse("transient fields should not be affected",
- enc.statements().hasNext());
-
+ assertFalse("transient fields should not be affected", enc.statements()
+ .hasNext());
+
// set transient to false
Introspector.flushCaches();
MockTransientBeanBeanInfo.setTransient(false);
@@ -1061,7 +1079,9 @@
/**
* Searches for the statement with given parameters.
- * @param iter iterator to search through, null means ignore this parameter
+ *
+ * @param iter
+ * iterator to search through, null means ignore this parameter
* @param target
* @param methodName
* @param args
@@ -1072,29 +1092,26 @@
while (iter.hasNext()) {
Statement stmt = iter.next();
-
+
if (target != null && stmt.getTarget() != target) {
continue;
}
-
- if (methodName != null && !methodName.equals(stmt.getMethodName()))
- {
+
+ if (methodName != null && !methodName.equals(stmt.getMethodName())) {
continue;
}
if (args != null) {
- if ((stmt.getArguments() != null &&
- args.length != stmt.getArguments().length)
- || stmt.getArguments() == null)
- {
+ if ((stmt.getArguments() != null && args.length != stmt
+ .getArguments().length)
+ || stmt.getArguments() == null) {
continue;
- }
-
+ }
+
for (int i = 0; i < args.length; i++) {
- if ((args[i] == null && stmt.getArguments()[i] != null) ||
- (args[i] != null && stmt.getArguments()[i] == null) ||
- !args[i].equals(stmt.getArguments()[i]))
- {
+ if ((args[i] == null && stmt.getArguments()[i] != null)
+ || (args[i] != null && stmt.getArguments()[i] == null)
+ || !args[i].equals(stmt.getArguments()[i])) {
continue;
}
}
@@ -1102,13 +1119,13 @@
return stmt;
}
-
+
return null;
}
-
+
public static class CollectingEncoder extends Encoder {
private Vector<Statement> statements = new Vector<Statement>();
-
+
@Override
public void writeExpression(Expression exp) {
statements.add(exp);
@@ -1120,13 +1137,29 @@
statements.add(stm);
super.writeStatement(stm);
}
-
+
public Iterator<Statement> statements() {
return statements.iterator();
}
-
+
public void clearCache() {
statements = new Vector<Statement>();
+ }
+ }
+
+ public static class MockBean3
+ {
+ public boolean setValueCalled = false;
+
+ public String value;
+
+ public String getValue() {
+ return value;
+ }
+
+ public void setValue(String value) {
+ this.value = value;
+ setValueCalled = true;
}
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/IntrospectorTest.java Thu Jul 19 01:09:53 2007
@@ -17,6 +17,8 @@
package org.apache.harmony.beans.tests.java.beans;
+import java.awt.Image;
+import java.awt.image.BufferedImage;
import java.beans.BeanDescriptor;
import java.beans.BeanInfo;
import java.beans.EventSetDescriptor;
@@ -24,8 +26,10 @@
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.MethodDescriptor;
+import java.beans.PropertyChangeListener;
import java.beans.PropertyDescriptor;
import java.beans.SimpleBeanInfo;
+import java.io.Serializable;
import java.lang.reflect.Method;
import java.security.Permission;
import java.util.ArrayList;
@@ -49,6 +53,7 @@
import org.apache.harmony.beans.tests.support.mock.FakeFox011;
import org.apache.harmony.beans.tests.support.mock.FakeFox01BeanInfo;
import org.apache.harmony.beans.tests.support.mock.FakeFox02;
+import org.apache.harmony.beans.tests.support.mock.FakeFox031;
import org.apache.harmony.beans.tests.support.mock.MockButton;
import org.apache.harmony.beans.tests.support.mock.MockFoo;
import org.apache.harmony.beans.tests.support.mock.MockFooButton;
@@ -57,6 +62,7 @@
import org.apache.harmony.beans.tests.support.mock.MockFooSub;
import org.apache.harmony.beans.tests.support.mock.MockFooSubSub;
import org.apache.harmony.beans.tests.support.mock.MockJavaBean;
+import org.apache.harmony.beans.tests.support.mock.MockSubClass;
/**
* Unit test for Introspector.
@@ -125,9 +131,6 @@
MethodDescriptor[] mds = info.getMethodDescriptors();
assertNotNull(mds);
assertEquals(11, mds.length);
- assertEquals("wait", mds[8].getName());
- assertEquals("wait", mds[9].getName());
- assertEquals("wait", mds[10].getName());
}
/**
@@ -279,9 +282,10 @@
*/
public void testAdditionalBeanInfo() throws IntrospectionException {
BeanInfo info = Introspector.getBeanInfo(StandardBean2.class);
+ assertNull(info.getAdditionalBeanInfo());
PropertyDescriptor[] pds = info.getPropertyDescriptors();
- assertEquals(1, pds.length);
- assertEquals("grannyText", pds[0].getName());
+ assertEquals(2, pds.length);
+ assertEquals("class", pds[0].getName());
}
/**
@@ -437,6 +441,11 @@
assertTrue(contains("setName", mds));
assertTrue(contains("getComplexLabel", mds));
assertTrue(contains("setComplexLabel", mds));
+ try {
+ Introspector.getBeanInfo(MockFoo.class, Serializable.class);
+ fail("Shoule throw exception, stopclass must be superclass of given bean");
+ } catch (IntrospectionException e) {
+ }
}
public void testGetBeanInfoClassClass_StopNull()
@@ -666,11 +675,28 @@
assertEquals(pds[i], pds2[i]);
}
}
+
+ public void testSetBeanInfoSearchPath_null() throws IntrospectionException{
+ String[] oldPath = Introspector.getBeanInfoSearchPath();
+ try{
+ Introspector.setBeanInfoSearchPath(null);
+ try{
+ Introspector.getBeanInfoSearchPath();
+ fail("should throw NPE");
+ }catch(NullPointerException e){
+ }
+ String[] newPath = new String[]{"mock", null, ""};
+ Introspector.setBeanInfoSearchPath(newPath);
+ Introspector.getBeanInfo(this.getClass());
+ }finally{
+ Introspector.setBeanInfoSearchPath(oldPath);
+ }
+ }
public void testGetBeanInfoSearchPath() {
String[] path = Introspector.getBeanInfoSearchPath();
assertEquals(1, path.length);
- assertEquals("org.apache.harmony.beans.infos", path[0]);
+ assertTrue(path[0].endsWith("beans.infos"));
}
public void testGetBeanInfoSearchPath_Default()
@@ -679,11 +705,11 @@
PropertyDescriptor[] pds = info.getPropertyDescriptors();
BeanDescriptor beanDesc;
- assertEquals(1, pds.length);
- assertEquals("text.MockFooButtonBeanInfo", pds[0].getName());
+ assertEquals(2, pds.length);
+ assertEquals("class", pds[0].getName());
beanDesc = info.getBeanDescriptor();
- assertEquals("MockFooButton.MockFooButtonBeanInfo", beanDesc.getName());
+ assertEquals("MockFooButton", beanDesc.getName());
}
public void testSetBeanInfoSearchPath() throws IntrospectionException {
@@ -809,10 +835,10 @@
assertNotNull(element.getReadMethod());
} else {
assertEquals("fox301", element.getName());
- assertEquals(String.class.getName(), element
+ assertEquals(Integer.class.getName(), element
.getPropertyType().getName());
- assertNotNull(element.getWriteMethod());
- assertNull(element.getReadMethod());
+ assertNull(element.getWriteMethod());
+ assertNotNull(element.getReadMethod());
}
}
}
@@ -1256,6 +1282,41 @@
assertNotNull(pds[1].getWriteMethod());
}
+ public void testGetBeanInfoComplexHierarchy() throws Exception {
+ Introspector.flushCaches();
+ BeanInfo subinfo = Introspector.getBeanInfo(MockSubClass.class);
+ PropertyDescriptor[] allProps = subinfo.getPropertyDescriptors();
+ boolean propFound = false;
+ for (int i = 0; i < allProps.length; i++) {
+ if (allProps[i].getName().equals("value")) {
+ assertTrue(allProps[i].isExpert());
+ assertTrue(allProps[i].isHidden());
+ assertTrue(allProps[i].isBound());
+ assertFalse(allProps[i].isConstrained());
+ assertEquals("adddisplay", allProps[i].getDisplayName());
+ assertEquals("subdesc", allProps[i].getShortDescription());
+ propFound = true;
+ break;
+ }
+ }
+ assertTrue(propFound);
+
+ boolean eventFound = false;
+ EventSetDescriptor[] events = subinfo.getEventSetDescriptors();
+ for (int i = 0; i < events.length; i++) {
+ if (events[i].getName().equals("mockPropertyChange")) {
+ assertTrue(events[i].isExpert());
+ assertTrue(events[i].isHidden());
+ assertFalse(events[i].isUnicast());
+ assertFalse(events[i].isInDefaultEventSet());
+ assertEquals("adddisplay", events[i].getDisplayName());
+ assertEquals("subdesc", events[i].getShortDescription());
+ eventFound = true;
+ break;
+ }
+ }
+ assertTrue(eventFound);
+ }
static class FakeFoxInfo {
public int getProp6(boolean i) {
@@ -1992,5 +2053,185 @@
}
return new MethodDescriptor[] { md };
}
+ }
+ public void testProperty() throws IntrospectionException {
+ Class<MockSubClassForPorpertiesStandard> beanClass = MockSubClassForPorpertiesStandard.class;
+ BeanInfo info = Introspector.getBeanInfo(beanClass);
+ assertEquals(-1, info.getDefaultEventIndex());
+ assertEquals(-1, info.getDefaultPropertyIndex());
+ PropertyDescriptor[] pds = info.getPropertyDescriptors();
+ for (PropertyDescriptor pd : pds) {
+ assertFalse(pd.isBound());
+ assertFalse(pd.isConstrained());
+ assertFalse(pd.isExpert());
+ assertFalse(pd.isHidden());
+ assertFalse(pd.isPreferred());
+ }
+ assertEquals(2, info.getPropertyDescriptors().length);
+ }
+
+ public void testDefaultEvent() throws IntrospectionException {
+ Class beanClass = MockClassForDefaultEvent.class;
+ BeanInfo info = Introspector.getBeanInfo(beanClass);
+ assertEquals(-1, info.getDefaultEventIndex());
+ assertEquals(-1, info.getDefaultPropertyIndex());
+ EventSetDescriptor[] events = info.getEventSetDescriptors();
+ for (EventSetDescriptor event : events) {
+ assertFalse(event.isUnicast());
+ assertTrue(event.isInDefaultEventSet());
+ assertFalse(event.isExpert());
+ assertFalse(event.isHidden());
+ assertFalse(event.isPreferred());
+ }
+ }
+
+ public void testDefaultIndex() throws IntrospectionException {
+ Introspector
+ .setBeanInfoSearchPath(new String[] { "org.apache.harmony.beans.tests.support" });
+
+ BeanInfo dummyInfo = Introspector.getBeanInfo(FakeFox031.class);
+ assertEquals(-1, dummyInfo.getDefaultPropertyIndex());
+ assertEquals(-1, dummyInfo.getDefaultEventIndex());
+ }
+
+ static class MockBaseClassForPorpertiesStandard {
+ int a = 0;
+
+ int b = 1;
+ }
+
+ static class MockSubClassForPorpertiesStandard extends
+ MockBaseClassForPorpertiesStandard {
+ int a = 2;
+
+ int b = 3;
+
+ public int getName() {
+ return a;
+ }
+
+ public void setName(int i) {
+ a = i;
+ }
+ }
+ static class MockClassForDefaultEvent {
+ public void addPropertyChangeListener(PropertyChangeListener a) {
+ }
+
+ public void removePropertyChangeListener(PropertyChangeListener a) {
+ }
+ }
+ static class MockBaseClassForPorperties {
+ int a = 0;
+
+ int b = 1;
+ }
+
+ static class MockSubClassForPorperties extends MockBaseClassForPorperties {
+ int a = 2;
+
+ int b = 3;
+
+ int c = 3;
+
+ public int getName() {
+ return a;
+ }
+
+ public void setName(int i) {
+ a = i;
+ }
+ }
+
+ public void testGetIcon() throws IntrospectionException {
+ Class<MockSubClassForPorperties> beanClass = MockSubClassForPorperties.class;
+ BeanInfo info = Introspector.getBeanInfo(beanClass);
+ assertNotNull(info.getIcon(BeanInfo.ICON_COLOR_16x16));
+ }
+
+ public static class MockBaseClassForPorpertiesBeanInfo extends
+ SimpleBeanInfo {
+
+ @Override
+ public MethodDescriptor[] getMethodDescriptors() {
+ MethodDescriptor md = null;
+ try {
+ Class<MockSubClassForPorperties> clz = MockSubClassForPorperties.class;
+ Method m = clz.getMethod("getName", new Class[] {});
+ md = new MethodDescriptor(m);
+ } catch (Exception e) {
+
+ }
+ return new MethodDescriptor[] { md };
+ }
+
+ @Override
+ public PropertyDescriptor[] getPropertyDescriptors() {
+ PropertyDescriptor[] pds = new PropertyDescriptor[2];
+ Class<MockSubClassForPorperties> clazz = MockSubClassForPorperties.class;
+ try {
+ Method getter = clazz.getMethod("getName");
+ Method setter = clazz.getMethod("setName", Integer.TYPE);
+ pds[0] = new PropertyDescriptor("a", getter, setter);
+ pds[0].setConstrained(true);
+ pds[0].setBound(true);
+ pds[0].setExpert(true);
+ pds[0].setHidden(true);
+ pds[1] = new PropertyDescriptor("b", getter, setter);
+ } catch (IntrospectionException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+
+ return pds;
+ }
+
+ public Image getIcon(int iconKind) {
+ return null;
+ }
+ }
+
+ public static class MockSubClassForPorpertiesBeanInfo extends
+ SimpleBeanInfo {
+
+ @Override
+ public MethodDescriptor[] getMethodDescriptors() {
+ MethodDescriptor md = null;
+ try {
+ Class<MockSubClassForPorperties> clz = MockSubClassForPorperties.class;
+ Method m = clz.getMethod("getName", new Class[] {});
+ md = new MethodDescriptor(m);
+ } catch (Exception e) {
+
+ }
+ return new MethodDescriptor[] { md };
+ }
+
+ @Override
+ public PropertyDescriptor[] getPropertyDescriptors() {
+ PropertyDescriptor[] pds = new PropertyDescriptor[2];
+ Class<MockSubClassForPorperties> clazz = MockSubClassForPorperties.class;
+ try {
+ Method getter = clazz.getMethod("getName");
+ Method setter = clazz.getMethod("setName", Integer.TYPE);
+ pds[0] = new PropertyDescriptor("a", getter, setter);
+ pds[1] = new PropertyDescriptor("b", getter, setter);
+ } catch (IntrospectionException e) {
+ e.printStackTrace();
+ } catch (SecurityException e) {
+ e.printStackTrace();
+ } catch (NoSuchMethodException e) {
+ e.printStackTrace();
+ }
+ return pds;
+ }
+
+ public Image getIcon(int iconKind) {
+ return new BufferedImage(16, 16, 1);
+ }
+
}
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PersistenceDelegateTest.java Thu Jul 19 01:09:53 2007
@@ -17,9 +17,15 @@
package org.apache.harmony.beans.tests.java.beans;
+import java.awt.*;
+import java.awt.event.*;
+import java.awt.font.TextAttribute;
+import java.awt.dnd.DropTarget;
import java.beans.Encoder;
import java.beans.Expression;
import java.beans.PersistenceDelegate;
+import java.beans.PropertyChangeEvent;
+import java.beans.PropertyChangeListener;
import java.beans.Statement;
import java.beans.XMLDecoder;
import java.beans.XMLEncoder;
@@ -32,12 +38,17 @@
import java.lang.reflect.Method;
import java.util.EmptyStackException;
import java.util.LinkedList;
+import java.util.Locale;
import java.util.Stack;
+import java.util.TreeMap;
+
+import javax.swing.*;
import junit.framework.TestCase;
import org.apache.harmony.beans.tests.support.mock.MockFoo;
import org.apache.harmony.beans.tests.support.mock.MockFooStop;
+
/**
* Test java.beans.PersistenceDelegate
*/
@@ -59,7 +70,7 @@
MockFoo foo = new MockFoo();
pd.writeObject(foo, enc);
-
+
assertEquals("initialize", pd.popMethod());
assertEquals("mutatesTo", pd.popMethod());
}
@@ -74,7 +85,7 @@
MockFoo foo = new MockFoo();
pd.writeObject(foo, enc);
-
+
assertEquals("instantiate", pd.popMethod());
assertEquals("mutatesTo", pd.popMethod());
assertWasAdded(MockFoo.class.getClass(), "new", null, enc);
@@ -84,8 +95,8 @@
* Tests writeObject() when object is null.
*/
public void testWriteObject_NullObject() {
- MockPersistenceDelegate2 pd = new MockPersistenceDelegate2();
- Encoder enc = new Encoder();
+ MockPersistenceDelegate2 pd = new MockPersistenceDelegate2();
+ Encoder enc = new Encoder();
try {
pd.writeObject(null, enc);
@@ -99,7 +110,7 @@
* Tests writeObject() when encoder is null.
*/
public void testWriteObject_NullEncoder() {
- MockPersistenceDelegate2 pd = new MockPersistenceDelegate2();
+ MockPersistenceDelegate2 pd = new MockPersistenceDelegate2();
try {
pd.writeObject(new MockFoo(), null);
@@ -116,17 +127,18 @@
DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
MockPersistenceDelegate3 pd3 = new MockPersistenceDelegate3();
Encoder enc = new Encoder();
-
+
enc.setPersistenceDelegate(MockFooStop.class, pd3);
pd.initialize(MockFoo.class, new MockFoo(), new MockFoo(), enc);
assertEquals("initialize", pd3.popMethod());
assertFalse("Extra statement has been detected", pd3.hasMoreMethods());
-
+
// test interface
pd3 = new MockPersistenceDelegate3();
enc.setPersistenceDelegate(MockInterface.class, pd3);
- pd.initialize(MockObject.class, new MockObject(), new MockObject(),
- enc);
+ pd
+ .initialize(MockObject.class, new MockObject(),
+ new MockObject(), enc);
assertFalse("Extra statement has been detected", pd3.hasMoreMethods());
}
@@ -139,7 +151,7 @@
enc.setPersistenceDelegate(MockFooStop.class,
new DummyPersistenceDelegate());
-
+
try {
pd.initialize(null, new Object(), new Object(), enc);
fail("Should throw NullPointerException!");
@@ -176,13 +188,13 @@
}
/**
- * Circular redundancy check. Should not hang.
- * Regression test for HARMONY-2073
+ * Circular redundancy check. Should not hang. Regression test for
+ * HARMONY-2073
*/
public void testInitialize_circularRedundancy() {
Encoder enc = new Encoder();
DummyPersistenceDelegate pd = new DummyPersistenceDelegate();
-
+
enc.setPersistenceDelegate(MockFooStop.class, pd);
pd.initialize(MockFoo.class, new MockFoo(), new MockFoo(), enc);
}
@@ -213,50 +225,56 @@
assertFalse(pd.mutatesTo(null, "test"));
}
- public void test_writeObject_Null_LXMLEncoder() throws Exception{
+ public void test_writeObject_Null_LXMLEncoder() throws Exception {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(byteArrayOutputStream));
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
encoder.writeObject(null);
encoder.close();
- DataInputStream stream = new DataInputStream(new ByteArrayInputStream(byteArrayOutputStream.toByteArray()));
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
XMLDecoder decoder = new XMLDecoder(stream);
assertNull(decoder.readObject());
- stream = new DataInputStream(PersistenceDelegateTest.class.getResourceAsStream("/xml/null.xml"));
+ stream = new DataInputStream(PersistenceDelegateTest.class
+ .getResourceAsStream("/xml/null.xml"));
decoder = new XMLDecoder(stream);
assertNull(decoder.readObject());
}
class Bar {
public int value;
+
public void barTalk() {
System.out.println("Bar is coming!");
}
}
+
public void test_writeObject_java_lang_reflect_Field()
- throws SecurityException, NoSuchFieldException, IOException {
- ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
- XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
- byteArrayOutputStream));
- Field value = Bar.class.getField("value");
- encoder.writeObject(value);
- encoder.close();
-
- DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
- byteArrayOutputStream.toByteArray()));
-
- XMLDecoder decoder = new XMLDecoder(stream); Field field = (Field)
- decoder.readObject();
+ throws SecurityException, NoSuchFieldException, IOException {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Field value = Bar.class.getField("value");
+ encoder.writeObject(value);
+ encoder.close();
+
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Field field = (Field) decoder.readObject();
assertEquals(value, field);
- assertEquals(value.getName(), field.getName());
- }
-
- public void test_writeObject_java_lang_reflect_Method() throws SecurityException, NoSuchMethodException{
+ assertEquals(value.getName(), field.getName());
+ }
+
+ public void test_writeObject_java_lang_reflect_Method()
+ throws SecurityException, NoSuchMethodException {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
- byteArrayOutputStream));
- Method method = Bar.class.getMethod("barTalk", (Class[])null);
+ byteArrayOutputStream));
+ Method method = Bar.class.getMethod("barTalk", (Class[]) null);
encoder.writeObject(method);
encoder.close();
@@ -268,11 +286,12 @@
assertEquals(method.getName(), aMethod.getName());
assertEquals("barTalk", aMethod.getName());
}
-
+
+ @SuppressWarnings("unchecked")
public void test_writeObject_java_util_Collection() {
ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
- byteArrayOutputStream));
+ byteArrayOutputStream));
LinkedList<Integer> list = new LinkedList<Integer>();
list.add(10);
list.addFirst(2);
@@ -287,13 +306,523 @@
assertEquals(list, l);
assertEquals(2, l.size());
assertEquals(new Integer(10), l.get(1));
+
+ }
+
+ public void test_writeObject_java_awt_Choice() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Choice choice = new Choice();
+ choice.setBackground(Color.blue);
+ choice.setFocusTraversalKeysEnabled(true);
+ choice.setBounds(0, 0, 10, 10);
+ choice.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+ choice.setCursor(new Cursor(Cursor.WAIT_CURSOR));
+ choice.setFocusTraversalKeysEnabled(true);
+ choice.setFocusable(true);
+ choice.setFont(new Font("Arial Bold", Font.ITALIC, 0));
+ choice.setForeground(Color.green);
+ choice.setIgnoreRepaint(true);
+ choice.setLocation(1, 2);
+ choice.setName("choice");
+ choice.setSize(new Dimension(200, 100));
+ choice.addItem("addItem");
+ choice.add("add");
+
+ ComponentListener cl = new ComponentAdapter() {
+ };
+ choice.addComponentListener(cl);
+ FocusListener fl = new FocusAdapter() {
+ };
+ choice.addFocusListener(fl);
+ HierarchyBoundsListener hbl = new HierarchyBoundsAdapter() {
+ };
+ choice.addHierarchyBoundsListener(hbl);
+ HierarchyListener hl = new HierarchyListener() {
+ public void hierarchyChanged(HierarchyEvent e) {
+ }
+ };
+ choice.addHierarchyListener(hl);
+ InputMethodListener il = new InputMethodListener() {
+ public void caretPositionChanged(InputMethodEvent e) {
+ }
+
+ public void inputMethodTextChanged(InputMethodEvent e) {
+ }
+ };
+ choice.addInputMethodListener(il);
+ ItemListener il2 = new ItemListener() {
+ public void itemStateChanged(ItemEvent e) {
+ }
+ };
+ choice.addItemListener(il2);
+ KeyListener kl = new KeyAdapter() {
+ };
+ choice.addKeyListener(kl);
+ MouseListener ml = new MouseAdapter() {
+ };
+ choice.addMouseListener(ml);
+ MouseMotionListener mml = new MouseMotionAdapter() {
+ };
+ choice.addMouseMotionListener(mml);
+ MouseWheelListener mwl = new MouseWheelListener() {
+ public void mouseWheelMoved(MouseWheelEvent e) {
+ }
+ };
+ choice.addMouseWheelListener(mwl);
+ PropertyChangeListener pcl = new PropertyChangeListener() {
+ public void propertyChange(PropertyChangeEvent event) {
+ }
+ };
+ choice.addPropertyChangeListener(pcl);
+ System.out.println(encoder.getPersistenceDelegate(Choice.class));
+ encoder.writeObject(choice);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Choice aChoice = (Choice) decoder.readObject();
+ assertEquals(choice.getFocusTraversalKeysEnabled(), aChoice
+ .getFocusTraversalKeysEnabled());
+ assertEquals(Color.blue, aChoice.getBackground());
+ assertEquals(new Rectangle(1, 2, 200, 100), aChoice.getBounds());
+ // ComponentOrientation is not persistent
+ assertTrue(aChoice.getComponentOrientation().isLeftToRight());
+
+ // Cursor will not be persisted
+ assertEquals(Cursor.DEFAULT_CURSOR, aChoice.getCursor().getType());
+ // DropTarget will not be persisted
+ assertNull(aChoice.getDropTarget());
+
+ assertEquals(choice.getName(), aChoice.getName());
+
+ assertEquals(choice.getItem(0), aChoice.getItem(0));
+ assertEquals(1, choice.getComponentListeners().length);
+ assertEquals(0, aChoice.getComponentListeners().length);
+ assertEquals(1, choice.getFocusListeners().length);
+ assertEquals(0, aChoice.getFocusListeners().length);
+ assertEquals(1, choice.getHierarchyBoundsListeners().length);
+ assertEquals(0, aChoice.getHierarchyBoundsListeners().length);
+ assertEquals(1, choice.getInputMethodListeners().length);
+ assertEquals(0, aChoice.getInputMethodListeners().length);
+ assertEquals(1, choice.getItemListeners().length);
+ assertEquals(0, aChoice.getItemListeners().length);
+ assertEquals(1, choice.getKeyListeners().length);
+ assertEquals(0, aChoice.getKeyListeners().length);
+ assertEquals(1, choice.getMouseListeners().length);
+ assertEquals(0, aChoice.getMouseListeners().length);
+ assertEquals(1, choice.getMouseMotionListeners().length);
+ assertEquals(0, aChoice.getMouseMotionListeners().length);
+ assertEquals(1, choice.getMouseWheelListeners().length);
+ assertEquals(0, aChoice.getMouseWheelListeners().length);
+ assertEquals(1, choice.getPropertyChangeListeners().length);
+ assertEquals(0, aChoice.getPropertyChangeListeners().length);
+
+ stream = new DataInputStream(PersistenceDelegateTest.class
+ .getResourceAsStream("/xml/Choice.xml"));
+
+ decoder = new XMLDecoder(stream);
+ aChoice = (Choice) decoder.readObject();
+ assertEquals(choice.getFocusTraversalKeysEnabled(), aChoice
+ .getFocusTraversalKeysEnabled());
+ assertEquals(Color.blue, aChoice.getBackground());
+ assertEquals(new Rectangle(1, 2, 200, 100), aChoice.getBounds());
+ // ComponentOrientation is not persistent
+ assertTrue(aChoice.getComponentOrientation().isLeftToRight());
+
+ // Cursor will not be persisted
+ assertEquals(Cursor.DEFAULT_CURSOR, aChoice.getCursor().getType());
+ // DropTarget will not be persisted
+ assertNull(aChoice.getDropTarget());
+
+ assertEquals(choice.getName(), aChoice.getName());
+
+ assertEquals(choice.getItem(0), aChoice.getItem(0));
+ }
+
+ public void test_writeObject_java_awt_SystemColor() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ encoder.writeObject(SystemColor.activeCaption);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ SystemColor color = (SystemColor) decoder.readObject();
+ assertEquals(SystemColor.activeCaption, color);
+ }
+
+ public void test_writeObject_java_awt_font_TextAttribute() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ encoder.writeObject(TextAttribute.BACKGROUND);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ TextAttribute attribute = (TextAttribute) decoder.readObject();
+ assertEquals(TextAttribute.BACKGROUND, attribute);
+ }
+
+ public void test_writeObject_java_awt_MenuShortcut() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ MenuShortcut shortCut = new MenuShortcut(2);
+
+ encoder.writeObject(shortCut);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ MenuShortcut aMenuShortcut = (MenuShortcut) decoder.readObject();
+ assertEquals(shortCut, aMenuShortcut);
+ assertEquals(shortCut.getKey(), aMenuShortcut.getKey());
+ }
+
+ public static class MockComponent extends Component {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 1L;
+ }
+ public void test_writeObject_java_awt_Component() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ Component component = new MockComponent();
+ component.add(new PopupMenu("PopupMenu"));
+ component.setBackground(Color.black);
+ component.setBounds(new Rectangle(1, 1, 10, 10));
+ component.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+ component.setEnabled(true);
+ component.setFocusable(true);
+ component.setFont(new Font("Arial", 1, 1));
+ component.setForeground(Color.blue);
+ component.setIgnoreRepaint(true);
+ component.setLocale(Locale.CANADA);
+ component.setName("MockComponent");
+ component.setVisible(true);
+ component.setCursor(new Cursor(Cursor.TEXT_CURSOR));
+ component.setDropTarget(new DropTarget());
+
+ encoder.writeObject(component);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Component aComponent = (Component) decoder.readObject();
+ assertEquals(component.getBackground(), aComponent.getBackground());
+ assertEquals(component.getForeground(), aComponent.getForeground());
+ assertEquals(component.getFont().getFamily(), aComponent.getFont().getFamily());
+ assertEquals(component.getFont().getStyle(), aComponent.getFont().getStyle());
+ assertEquals(component.getFont().getSize(), aComponent.getFont().getSize());
+ assertEquals(component.getName(), aComponent.getName());
+ assertEquals(component.getBounds(), aComponent.getBounds());
+ }
+
+ public void test_writeObject_java_awt_Container() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Container container = new Container();
+ container.setBackground(Color.blue);
+ container.setFocusTraversalKeysEnabled(true);
+ container.setBounds(0, 0, 10, 10);
+ container.setComponentOrientation(ComponentOrientation.RIGHT_TO_LEFT);
+ container.setComponentZOrder(new Label("label"), 0);
+ container.setComponentZOrder(new JTabbedPane(), 1);
+ container.setCursor(new Cursor(Cursor.WAIT_CURSOR));
+ container.setFocusTraversalKeysEnabled(true);
+ container.setFocusable(true);
+ container.setFocusTraversalPolicyProvider(true);
+ container.setFocusTraversalPolicy(new LayoutFocusTraversalPolicy());
+ container.setFont(new Font("Arial Bold", Font.ITALIC, 0));
+ container.setForeground(Color.green);
+ container.setIgnoreRepaint(true);
+ container.setLocation(1, 2);
+ container.setName("container");
+ container.setSize(new Dimension(200, 100));
+ container.setEnabled(true);
+ container.setFocusCycleRoot(true);
+ container.setLayout(new BorderLayout());
+ container.setLocale(Locale.CANADA);
+ container.setVisible(true);
+ container.add(new Label("label"));
+ container.add(new JTabbedPane());
+
+ encoder.writeObject(container);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Container aContainer = (Container) decoder.readObject();
+ assertEquals(container.getFocusTraversalKeysEnabled(), aContainer
+ .getFocusTraversalKeysEnabled());
+ assertEquals(Color.blue, aContainer.getBackground());
+ assertEquals(new Rectangle(1, 2, 200, 100), aContainer.getBounds());
+
+ // ComponentOrientation is not persistent
+ assertTrue(aContainer.getComponentOrientation().isLeftToRight());
+ Component [] components = aContainer.getComponents();
+ assertTrue(components[0] instanceof Label);
+ assertEquals(0, aContainer.getComponentZOrder(components[0]));
+ assertTrue(components[1] instanceof JTabbedPane);
+ assertEquals(1, aContainer.getComponentZOrder(components[1]));
+
+ // Cursor will not be persisted
+ assertEquals(Cursor.DEFAULT_CURSOR, aContainer.getCursor().getType());
+ // DropTarget will not be persisted
+ assertNull(aContainer.getDropTarget());
+
+ assertEquals(container.getFocusTraversalPolicy().getClass(), aContainer
+ .getFocusTraversalPolicy().getClass());
+ assertEquals(container.getName(), aContainer.getName());
+
+ container = new Container();
+ container.setFocusCycleRoot(true);
+ byteArrayOutputStream = new ByteArrayOutputStream();
+ encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ encoder.writeObject(container);
+ encoder.close();
+ stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ decoder = new XMLDecoder(stream);
+ aContainer = (Container) decoder.readObject();
+ assertTrue(aContainer.isFocusCycleRoot());
}
+
+ public void test_writeObject_java_awt_Menu() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Menu menu = new Menu();
+ String action = "menu action command";
+ menu.setActionCommand(action);
+ menu.setEnabled(true);
+ menu.setFont(new Font("Arial Black", Font.BOLD, 10));
+ menu.setLabel("menu");
+ menu.setName("menu");
+ menu.setShortcut(new MenuShortcut(10));
+ menu.insertSeparator(1);
+
+ encoder.writeObject(menu);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Menu aMenu = (Menu) decoder.readObject();
+ assertTrue(aMenu.isEnabled());
+ assertEquals(action, aMenu.getActionCommand());
+ assertEquals(menu.getFont().getSize(), aMenu.getFont().getSize());
+ assertEquals(menu.getFont().getStyle(), aMenu.getFont().getStyle());
+ assertEquals(menu.getLabel(), aMenu.getLabel());
+ assertEquals(menu.getName(), aMenu.getName());
+ assertEquals(menu.getShortcut().getKey(), aMenu.getShortcut().getKey());
+ assertEquals(1, menu.getItemCount());
+ assertEquals(menu.getItem(0).getLabel(), aMenu.getItem(0).getLabel());
+ assertEquals(menu.getItem(0).getName(), aMenu.getItem(0).getName());
+ assertEquals(menu.getItem(0).getFont().getStyle(), aMenu.getItem(0).getFont().getStyle());
+ assertEquals(menu.getFont().getSize(), aMenu.getItem(0).getFont().getSize());
+
+ }
+
+ public void test_writeObject_java_awt_MenuBar() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ MenuBar bar = new MenuBar();
+ bar.add(new Menu("menu1"));
+
+ encoder.writeObject(bar);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ MenuBar aBar = (MenuBar) decoder.readObject();
+ assertEquals(bar.getMenu(0).getName(), aBar.getMenu(0).getName());
+
+ }
+
+ public void test_writeObject_java_awt_List() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ java.awt.List list = new List();
+ list.setBounds(0, 0, 10, 10);
+ list.add(new PopupMenu("popupMenu"));
+ list.add("1");
+ list.add("2", 2);
+ list.setBackground(Color.BLUE);
+ encoder.writeObject(list);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ List aList = (List) decoder.readObject();
+ assertEquals(list.getItem(0), aList.getItem(0));
+ assertEquals(list.getHeight(), aList.getHeight());
+ assertEquals(list.getBackground(), aList.getBackground());
+ }
+
+ public void test_writeObject_java_awt_BorderLayout(){
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ BorderLayout layout = new BorderLayout();
+ layout.setHgap(2);
+ layout.setVgap(3);
+ encoder.writeObject(layout);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ BorderLayout aLayout = (BorderLayout) decoder.readObject();
+ assertEquals(layout.getHgap(), aLayout.getHgap());
+ assertEquals(layout.getVgap(), aLayout.getVgap());
+ }
+
+ public void test_writeObject_java_awt_CardLayout(){
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ CardLayout layout = new CardLayout();
+ layout.addLayoutComponent(new Label("label"), "constraints");
+ layout.setHgap(2);
+ layout.setVgap(3);
+ encoder.writeObject(layout);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ CardLayout aLayout = (CardLayout) decoder.readObject();
+ assertEquals(layout.getHgap(), aLayout.getHgap());
+ assertEquals(layout.getVgap(), aLayout.getVgap());
+ }
+
+ public void test_writeObject_java_awt_GridBagLayout() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+
+ GridBagLayout layout = new GridBagLayout();
+ layout.addLayoutComponent(new Label("label"), new GridBagConstraints(0,
+ 0, 100, 60, 0.1, 0.1, GridBagConstraints.WEST,
+ GridBagConstraints.NONE, new Insets(0,0, 99, 59), 0, 0));
+ encoder.writeObject(layout);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ GridBagLayout aLayout = (GridBagLayout) decoder.readObject();
+ assertEquals(layout.getConstraints(new Label("label")).weightx, aLayout
+ .getConstraints(new Label("label")).weightx);
+ assertEquals(layout.getConstraints(new Label("label")).insets.left, aLayout
+ .getConstraints(new Label("label")).insets.left);
+ }
+
+ public void test_writeObject_java_awt_Cursor() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Cursor cursor = new Cursor(Cursor.CROSSHAIR_CURSOR);
+
+ encoder.writeObject(cursor);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Cursor aCursor = (Cursor) decoder.readObject();
+ assertEquals(cursor.getName(), aCursor
+ .getName());
+ assertEquals(cursor.getType(), aCursor.getType());
+ }
+
+ public void test_writeObject_java_awt_Insets() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Insets inset = new Insets(0, 0, 10, 10);
+
+ encoder.writeObject(inset);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Insets aInset = (Insets) decoder.readObject();
+ assertEquals(inset.left, aInset.left);
+ assertEquals(inset.top, aInset.top);
+ }
+
+ public void test_writeObject_java_awt_point() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ Point point = new Point(10, 20);
+
+ encoder.writeObject(point);
+ encoder.close();
+
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ Point aPoint = (Point) decoder.readObject();
+ assertEquals(point, aPoint);
+ }
+
+ public void test_writeObject_java_awt_ScrollPane() {
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ ScrollPane scrollPane = new ScrollPane();
+
+ encoder.writeObject(scrollPane);
+ encoder.close();
+
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ ScrollPane aScrollPane = (ScrollPane) decoder.readObject();
+ assertEquals(scrollPane.getAlignmentX(), aScrollPane.getAlignmentX());
+ assertEquals(scrollPane.getAlignmentY(), aScrollPane.getAlignmentY());
+ assertEquals(scrollPane.getScrollbarDisplayPolicy(), aScrollPane
+ .getScrollbarDisplayPolicy());
+ }
+
+ public void test_writeObject_java_util_Map(){
+ ByteArrayOutputStream byteArrayOutputStream = new ByteArrayOutputStream();
+ XMLEncoder encoder = new XMLEncoder(new BufferedOutputStream(
+ byteArrayOutputStream));
+ TreeMap<Integer, String> map = new TreeMap<Integer, String>();
+ map.put(new Integer(10), "first element");
+
+ encoder.writeObject(map);
+ encoder.close();
+ DataInputStream stream = new DataInputStream(new ByteArrayInputStream(
+ byteArrayOutputStream.toByteArray()));
+ XMLDecoder decoder = new XMLDecoder(stream);
+ TreeMap aMap = (TreeMap) decoder.readObject();
+ assertEquals(map.size(), aMap.size());
+ assertEquals(map.get(10), aMap.get(10));
+ }
// <--
private void assertWasAdded(Class<?> targetClass, String methodName,
- Object[] args, MockEncoder2 enc) {
+ Object[] args, MockEncoder2 enc) {
try {
while (true) {
Statement stmt = enc.pop();
@@ -308,8 +837,8 @@
}
private boolean equals(Statement stmt, Class<?> targetClass,
- String methodName, Object[] args) {
-
+ String methodName, Object[] args) {
+
if (stmt == null || !methodName.equals(stmt.getMethodName())) {
return false;
}
@@ -324,10 +853,10 @@
return false;
}
}
-
+
if (args != null) {
- if (stmt.getArguments() == null ||
- args.length != stmt.getArguments().length) {
+ if (stmt.getArguments() == null
+ || args.length != stmt.getArguments().length) {
return false;
}
@@ -348,7 +877,7 @@
return false;
}
}
-
+
return true;
}
@@ -368,7 +897,7 @@
static class MockEncoder2 extends Encoder {
Stack<Statement> stmts = new Stack<Statement>();
-
+
@Override
public void writeExpression(Expression expr) {
stmts.push(expr);
@@ -380,7 +909,7 @@
stmts.push(stmt);
super.writeStatement(stmt);
}
-
+
@Override
public void writeObject(Object obj) {
super.writeObject(obj);
@@ -394,10 +923,12 @@
static class MockPersistenceDelegate2 extends PersistenceDelegate {
private Boolean mutatesToFlag = null;
+
Stack<String> methods = new Stack<String>();
- public MockPersistenceDelegate2() {}
-
+ public MockPersistenceDelegate2() {
+ }
+
public MockPersistenceDelegate2(boolean mutatesToFlag) {
this.mutatesToFlag = Boolean.valueOf(mutatesToFlag);
}
@@ -408,13 +939,13 @@
methods.push("initialize");
super.initialize(type, oldInstance, newInstance, enc);
}
-
+
@Override
public Expression instantiate(Object oldInstance, Encoder out) {
methods.push("instantiate");
return new Expression(oldInstance.getClass(), "new", null);
}
-
+
@Override
public boolean mutatesTo(Object oldInstance, Object newInstance) {
methods.push("mutatesTo");
@@ -424,11 +955,11 @@
}
return super.mutatesTo(oldInstance, newInstance);
}
-
+
String popMethod() {
return methods.pop();
}
-
+
boolean hasMoreMethods() {
return !methods.empty();
}
Modified: harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java
URL: http://svn.apache.org/viewvc/harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java?view=diff&rev=557518&r1=557517&r2=557518
==============================================================================
--- harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java (original)
+++ harmony/enhanced/classlib/branches/java6/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/PropertyEditorManagerTest.java Thu Jul 19 01:09:53 2007
@@ -17,7 +17,9 @@
package org.apache.harmony.beans.tests.java.beans;
+import java.awt.Color;
import java.awt.Component;
+import java.awt.Font;
import java.awt.Graphics;
import java.awt.Rectangle;
import java.beans.PropertyChangeListener;
@@ -723,6 +725,37 @@
assertNotNull("No property editor found", pe);
assertTrue(pe instanceof AnotherSamplePropertyEditor);
+ }
+
+ public void testFontEditor() throws Exception{
+ PropertyEditor e2 = PropertyEditorManager.findEditor(Font.class);
+ Font font = new Font("Helvetica", Font.PLAIN, 12);
+ e2.setValue(font);
+ assertNull(e2.getAsText());
+ assertNull(e2.getTags());
+ assertSame(font, e2.getValue());
+ assertTrue(e2.isPaintable());
+ Component c = (Component) e2.getCustomEditor();
+ assertSame(c, e2);
+ }
+
+ public void testColorEditor() throws Exception{
+ PropertyEditor e2 = PropertyEditorManager.findEditor(Color.class);
+ e2.setValue(Color.RED);
+ e2.setAsText(e2.getAsText());
+ assertNull(e2.getTags());
+ assertNotSame(Color.RED, e2.getValue());
+ assertEquals(Color.RED, e2.getValue());
+ assertTrue(e2.isPaintable());
+ }
+
+ public void testGetSetEditorPath() throws Exception{
+ String[] s = new String[]{"path1", "path2"};
+ PropertyEditorManager.setEditorSearchPath(s);
+ s[1] = "path3";
+ String[] s2 = PropertyEditorManager.getEditorSearchPath();
+ assertFalse(s==s2);
+ assertEquals("path1", s2[0]);
}
String[] defaultSearchPath;