harmony-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From telli...@apache.org
Subject svn commit: r452415 [7/12] - in /incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test: java-internal/java/beans/beancontext/ java-internal/org/apache/harmony/beans/ java/org/apache/harmony/beans/tests/ java/org/apache/harmony/beans/tests/ja...
Date Tue, 03 Oct 2006 11:06:03 GMT
Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VetoableChangeSupportTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VetoableChangeSupportTest.java?view=diff&rev=452415&r1=452414&r2=452415
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VetoableChangeSupportTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/VetoableChangeSupportTest.java
Tue Oct  3 04:05:57 2006
@@ -23,18 +23,17 @@
 import java.beans.VetoableChangeListener;
 import java.beans.VetoableChangeListenerProxy;
 import java.beans.VetoableChangeSupport;
-
 import java.beans.beancontext.BeanContextChildSupport;
-
-import java.io.IOException;
-import java.io.Serializable;
-import java.util.ArrayList;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
+import java.io.IOException;
 import java.io.ObjectInputStream;
 import java.io.ObjectOutputStream;
+import java.io.Serializable;
+import java.util.ArrayList;
 
 import junit.framework.TestCase;
+
 import org.apache.harmony.beans.tests.support.beancontext.mock.MockVetoableChangeListener;
 import org.apache.harmony.beans.tests.support.mock.NonSerializedVCListener;
 import org.apache.harmony.beans.tests.support.mock.SerializedVCListener;
@@ -183,7 +182,8 @@
         try {
             support.addVetoableChangeListener(propertyName, proxy);
             fail("Should throw NullPointerException.");
-        } catch (NullPointerException e) {}
+        } catch (NullPointerException e) {
+        }
     }
 
     /*
@@ -327,8 +327,8 @@
         assertEquals(2, listeners1.length);
         assertEquals(0, listeners2.length);
         assertEquals(0, listeners3.length);
-        for (int i = 0; i < listeners1.length; i++) {
-            assertSame(proxy, listeners1[i]);
+        for (VetoableChangeListener element : listeners1) {
+            assertSame(proxy, element);
         }
     }
 
@@ -359,8 +359,8 @@
         assertEquals(2, listeners1.length);
         assertEquals(0, listeners2.length);
         assertEquals(0, listeners3.length);
-        for (int i = 0; i < listeners1.length; i++) {
-            assertTrue((proxy == listeners1[i]) || (proxy2 == listeners1[i]));
+        for (VetoableChangeListener element : listeners1) {
+            assertTrue((proxy == element) || (proxy2 == element));
         }
     }
 
@@ -1133,41 +1133,42 @@
     }
 
     public void testFireVetoableChangeException_revert_event() {
-	        final VetoableChangeSupport support = new VetoableChangeSupport(new Object());
-		final StringBuffer sb = new StringBuffer();
-		final String A_IN = "a", B_IN="b", A_THROW="A", B_THROW="B";
-
-                support.addVetoableChangeListener(new VetoableChangeListener() {
-                        public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
{
-                      		sb.append(A_IN);
-                                if(sb.length() == 4) {
-					sb.append(A_THROW);
-                                        throw new PropertyVetoException(A_THROW, e);
-                                }
-                        }
-                });
-
-                
-                support.addVetoableChangeListener(new VetoableChangeListener() {
-                        public void vetoableChange(PropertyChangeEvent e) throws PropertyVetoException
{
-				sb.append(B_IN);
-                                if(sb.length() == 2) {
-					sb.append(B_THROW);
-                                        throw new PropertyVetoException(B_THROW, e);
-                                }
-                        }
-                });
-
-
-                try {
-			support.fireVetoableChange("propName", 0, 1);
-                } catch(PropertyVetoException pve) {
-			assertTrue("Illegal sequence:"+sb, sb.toString().equals("abBaAb"));
-			String message = pve.getMessage();
-			assertTrue("Illegal exception:"+message, message.equals(B_THROW));
-			return;
+        final VetoableChangeSupport support = new VetoableChangeSupport(
+                new Object());
+        final StringBuffer sb = new StringBuffer();
+        final String A_IN = "a", B_IN = "b", A_THROW = "A", B_THROW = "B";
+
+        support.addVetoableChangeListener(new VetoableChangeListener() {
+            public void vetoableChange(PropertyChangeEvent e)
+                    throws PropertyVetoException {
+                sb.append(A_IN);
+                if (sb.length() == 4) {
+                    sb.append(A_THROW);
+                    throw new PropertyVetoException(A_THROW, e);
+                }
+            }
+        });
+
+        support.addVetoableChangeListener(new VetoableChangeListener() {
+            public void vetoableChange(PropertyChangeEvent e)
+                    throws PropertyVetoException {
+                sb.append(B_IN);
+                if (sb.length() == 2) {
+                    sb.append(B_THROW);
+                    throw new PropertyVetoException(B_THROW, e);
                 }
-		assertFalse("Unreachable path:"+sb, true);
+            }
+        });
+
+        try {
+            support.fireVetoableChange("propName", 0, 1);
+        } catch (PropertyVetoException pve) {
+            assertTrue("Illegal sequence:" + sb, sb.toString().equals("abBaAb"));
+            String message = pve.getMessage();
+            assertTrue("Illegal exception:" + message, message.equals(B_THROW));
+            return;
+        }
+        assertFalse("Unreachable path:" + sb, true);
     }
 
     /*
@@ -1561,7 +1562,8 @@
         try {
             vcs.fireVetoableChange(vlistener.vetoedPropName, 0, 1);
             fail("PropertyVetoException expected");
-        } catch (PropertyVetoException ok) {}
+        } catch (PropertyVetoException ok) {
+        }
 
         assertEquals(1, vlistener.event.getOldValue());
         assertEquals(0, vlistener.event.getNewValue());
@@ -1837,7 +1839,8 @@
         try {
             new VetoableChangeSupport(null);
             fail("Should throw NullPointerException.");
-        } catch (NullPointerException e) {}
+        } catch (NullPointerException e) {
+        }
     }
 
     /**
@@ -1873,7 +1876,8 @@
         VetoableChangeSupport vcs = new VetoableChangeSupport("bean1");
         VetoableChangeListener vcl = new VetoableChangeListener() {
 
-            public void vetoableChange(PropertyChangeEvent pce) {}
+            public void vetoableChange(PropertyChangeEvent pce) {
+            }
         };
         vcs.addVetoableChangeListener(vcl);
         VetoableChangeListener[] vcls = vcs.getVetoableChangeListeners();
@@ -1890,7 +1894,8 @@
         VetoableChangeSupport vcs = new VetoableChangeSupport("bean1");
         VetoableChangeListener vcl = new VetoableChangeListener() {
 
-            public void vetoableChange(PropertyChangeEvent pce) {}
+            public void vetoableChange(PropertyChangeEvent pce) {
+            }
         };
         vcs.addVetoableChangeListener("property1", vcl);
         VetoableChangeListener[] vcls = vcs
@@ -1908,7 +1913,8 @@
         VetoableChangeSupport vcs = new VetoableChangeSupport("bean1");
         VetoableChangeListener vcl = new VetoableChangeListener() {
 
-            public void vetoableChange(PropertyChangeEvent pce) {}
+            public void vetoableChange(PropertyChangeEvent pce) {
+            }
         };
         vcs.addVetoableChangeListener("property1", vcl);
         VetoableChangeListener[] vcls = vcs.getVetoableChangeListeners();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java?view=diff&rev=452415&r1=452414&r2=452415
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLDecoderTest.java
Tue Oct  3 04:05:57 2006
@@ -18,9 +18,9 @@
 package org.apache.harmony.beans.tests.java.beans;
 
 import java.beans.ExceptionListener;
+import java.beans.Introspector;
 import java.beans.XMLDecoder;
 import java.beans.XMLEncoder;
-import java.beans.Introspector;
 import java.io.BufferedInputStream;
 import java.io.ByteArrayInputStream;
 import java.io.ByteArrayOutputStream;
@@ -29,6 +29,7 @@
 import junit.framework.Test;
 import junit.framework.TestCase;
 import junit.framework.TestSuite;
+
 import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
 import org.apache.harmony.beans.tests.java.beans.XMLEncoderTest.DependencyBean;
 import org.apache.harmony.beans.tests.support.mock.MockBean4Codec;
@@ -59,12 +60,13 @@
     }
 
     static class MockClassLoader extends ClassLoader {
+        @Override
         public Class<?> loadClass(String name) throws ClassNotFoundException {
             throw new ClassNotFoundException();
         }
-        
-        protected Class<?> findClass(String name)
-                throws ClassNotFoundException {
+
+        @Override
+        protected Class<?> findClass(String name) throws ClassNotFoundException {
             throw new ClassNotFoundException();
         }
 
@@ -79,15 +81,15 @@
                 exceptions.addElement(e);
             }
         };
-        
-        dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this,
-              el, Thread.currentThread().getContextClassLoader());
+
+        dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this, el,
+                Thread.currentThread().getContextClassLoader());
         assertEquals(Integer.valueOf("1"), dec.readObject());
         assertEquals(0, exceptions.size());
         dec.close();
-        
-        dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this,
-              el, new MockClassLoader());
+
+        dec = new XMLDecoder(new ByteArrayInputStream(xml123bytes), this, el,
+                new MockClassLoader());
         try {
             dec.readObject();
             assertTrue(exceptions.size() > 0);
@@ -379,9 +381,7 @@
     /*
      * The test checks the code generation for XML from MainTest.xml
      * 
-     public void testMain() {
-     decode("xml/MainTest.xml");
-     }
+     * public void testMain() { decode("xml/MainTest.xml"); }
      */
 
     /**

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java?view=diff&rev=452415&r1=452414&r2=452415
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/XMLEncoderTest.java
Tue Oct  3 04:05:57 2006
@@ -19,8 +19,8 @@
 
 import java.beans.DefaultPersistenceDelegate;
 import java.beans.Encoder;
-import java.beans.Expression;
 import java.beans.ExceptionListener;
+import java.beans.Expression;
 import java.beans.PersistenceDelegate;
 import java.beans.Statement;
 import java.beans.XMLEncoder;
@@ -32,9 +32,8 @@
 import java.io.PrintWriter;
 
 import junit.framework.TestCase;
-//import junit.framework.TestSuite;
-import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
 
+import org.apache.harmony.beans.tests.java.beans.EncoderTest.SampleBean;
 import org.apache.harmony.beans.tests.support.AType;
 import org.apache.harmony.beans.tests.support.StandardBean;
 import org.apache.harmony.beans.tests.support.TestEventHandler;
@@ -52,316 +51,316 @@
  */
 public class XMLEncoderTest extends TestCase {
 
-	public static void main(String[] args) {
+    public static void main(String[] args) {
+
+        // VerboseEncoder enc = new VerboseEncoder();
+        //
+        // MockBean4Codec b = new MockBean4Codec();
+        // b.getBornFriend().getZarr()[0] = 888;
+        // b.setNill(b.getBornFriend());
+        //
+        // enc.writeObject(b);
+        // enc.flush();
+
+        junit.textui.TestRunner.run(XMLEncoderTest.class);
+    }
+
+    public static class DependencyBean {
+        private int ints[] = new int[] { 1 };
+
+        private Object ref;
+
+        public int[] getInts() {
+            return ints;
+        }
+
+        public void setInts(int[] ints) {
+            this.ints = ints;
+        }
+
+        public Object getRef() {
+            return ref;
+        }
+
+        public void setRef(Object ref) {
+            this.ref = ref;
+        }
+    }
+
+    public static class VerboseEncoder extends XMLEncoder {
+
+        private PrintWriter out;
+
+        private boolean ident;
+
+        public VerboseEncoder() {
+            this(new PrintWriter(System.out, true), true);
+        }
+
+        public VerboseEncoder(PrintWriter out, boolean ident) {
+            super(System.out);
+            this.out = out;
+            this.ident = ident;
+        }
+
+        public Object get(Object arg0) {
+            String identStr = ident ? ident() : "";
+            out.println(identStr + "get()> " + arg0);
+            Object result = super.get(arg0);
+            out.println(identStr + "get()< " + result);
+            return result;
+        }
+
+        public PersistenceDelegate getPersistenceDelegate(Class type) {
+            PersistenceDelegate result = super.getPersistenceDelegate(type);
+            return result;
+        }
 
-		// VerboseEncoder enc = new VerboseEncoder();
-		//
-		// MockBean4Codec b = new MockBean4Codec();
-		// b.getBornFriend().getZarr()[0] = 888;
-		// b.setNill(b.getBornFriend());
-		//
-		// enc.writeObject(b);
-		// enc.flush();
-
-		junit.textui.TestRunner.run(XMLEncoderTest.class);
-	}
-
-	public static class DependencyBean {
-		private int ints[] = new int[] { 1 };
-
-		private Object ref;
-
-		public int[] getInts() {
-			return ints;
-		}
-
-		public void setInts(int[] ints) {
-			this.ints = ints;
-		}
-
-		public Object getRef() {
-			return ref;
-		}
-
-		public void setRef(Object ref) {
-			this.ref = ref;
-		}
-	}
-
-	public static class VerboseEncoder extends XMLEncoder {
-
-		private PrintWriter out;
-
-		private boolean ident;
-
-		public VerboseEncoder() {
-			this(new PrintWriter(System.out, true), true);
-		}
-
-		public VerboseEncoder(PrintWriter out, boolean ident) {
-			super(System.out);
-			this.out = out;
-			this.ident = ident;
-		}
-
-		public Object get(Object arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "get()> " + arg0);
-			Object result = super.get(arg0);
-			out.println(identStr + "get()< " + result);
-			return result;
-		}
-
-		public PersistenceDelegate getPersistenceDelegate(Class type) {
-			PersistenceDelegate result = super.getPersistenceDelegate(type);
-			return result;
-		}
-
-		public Object remove(Object arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "remove()> " + arg0);
-			Object result = super.remove(arg0);
-			out.println(identStr + "remove()< " + result);
-			return result;
-		}
-
-		public void writeExpression(Expression arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "writeExpression()> " + string(arg0));
-			super.writeExpression(arg0);
-			out.println(identStr + "writeExpression()< ");
-		}
-
-		public void writeStatement(Statement arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "writeStatement()> " + string(arg0));
-			super.writeStatement(arg0);
-			out.println(identStr + "writeStatement()< ");
-		}
-
-		public void writeObject(Object arg0) {
-			String identStr = ident ? ident() : "";
-			out.println(identStr + "writeObject()> " + arg0);
-			super.writeObject(arg0);
-			out.println(identStr + "writeObject()< ");
-		}
-	}
+        public Object remove(Object arg0) {
+            String identStr = ident ? ident() : "";
+            out.println(identStr + "remove()> " + arg0);
+            Object result = super.remove(arg0);
+            out.println(identStr + "remove()< " + result);
+            return result;
+        }
+
+        public void writeExpression(Expression arg0) {
+            String identStr = ident ? ident() : "";
+            out.println(identStr + "writeExpression()> " + string(arg0));
+            super.writeExpression(arg0);
+            out.println(identStr + "writeExpression()< ");
+        }
+
+        public void writeStatement(Statement arg0) {
+            String identStr = ident ? ident() : "";
+            out.println(identStr + "writeStatement()> " + string(arg0));
+            super.writeStatement(arg0);
+            out.println(identStr + "writeStatement()< ");
+        }
+
+        public void writeObject(Object arg0) {
+            String identStr = ident ? ident() : "";
+            out.println(identStr + "writeObject()> " + arg0);
+            super.writeObject(arg0);
+            out.println(identStr + "writeObject()< ");
+        }
+    }
 
     public XMLEncoderTest() {
         super();
     }
-    
+
     public XMLEncoderTest(String s) {
         super(s);
     }
-    
-	public static String ident() {
-		Exception ex = new Exception();
-		int level = ex.getStackTrace().length;
-		StringBuffer buf = new StringBuffer();
-		for (int i = 0; i < level; i++) {
-			buf.append("  ");
-		}
-		return buf.toString();
-	}
-
-	public static String string(Statement stat) {
-		String str = "(" + stat.getTarget() + ")." + stat.getMethodName() + "(";
-		Object args[] = stat.getArguments();
-		for (int i = 0; i < args.length; i++) {
-			if (i > 0) {
-				str += ", ";
-			}
-			str += args[i];
-		}
-		str = str + ")";
-		return str;
-	}
-
-	public static String string(Expression exp) {
-		String str = "";
-		try {
-			str += str + exp.getValue();
-		} catch (Exception e) {
-			e.printStackTrace();
-		}
-		str += "=" + string((Statement) exp);
-		return str;
-	}
-
-	public void testWriteExpression() {
-		// covered by testWriteObject
-	}
-
-	public void testWriteStatement() {
-		// coverd by testWriteStatement
-	}
-
-	public void testWriteObject_Null() throws Exception {
-		assertCodedXML(null, "/xml/null.xml");
-	}
-
-	public void testWriteObject_Integer() throws Exception {
-		assertCodedXML(new Integer(3), "/xml/int.xml");
-	}
-
-	public void testWriteObject_StringCodec() throws Exception {
-		SampleBean b = new SampleBean();
-		b.setMyid("<Li Yang> & \"liyang'");
-		SampleBean c = new SampleBean();
-		c.setMyid("a child");
-		b.setRef(c);
-		assertCodedXML(b, "/xml/SampleBean_StringCodec.xml");
-	}
-
-	public void testWriteObject_IntArray() throws Exception {
-		assertCodedXML(new int[] { 1, 2, 3 }, "/xml/IntArray.xml");
-	}
-
-	public void testWriteObject_PropertyDependency() throws Exception {
-		DependencyBean b = new DependencyBean();
-		b.getInts()[0] = 888;
-		b.setRef(b.getInts());
-		assertCodedXML(b, "/xml/DependencyBean.xml");
-	}
-
-	public void testWriteObject_NoChange() throws Exception {
-		assertCodedXML(new MockBean4Codec(), "/xml/MockBean4Codec_NoChange.xml");
-	}
-
-	public void testWriteObject_BornFriendChange() throws Exception {
-		MockBean4Codec b = new MockBean4Codec();
-		b.getBornFriend().getZarr()[0] = 888;
-		b.setNill(b.getBornFriend());
-
-		assertCodedXML(b, "/xml/MockBean4Codec_BornFriendChange.xml");
-	}
-
-	public void testWriteObject_ManyChanges() throws Exception {
-		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges(),
-				"/xml/MockBean4Codec_ManyChanges.xml");
-	}
-
-	public void testWriteObject_ManyChanges_2() throws Exception {
-		assertCodedXML(MockBean4Codec.getInstanceOfManyChanges2(),
-				"/xml/MockBean4Codec_ManyChanges_2.xml");
-	}
-
-	public void testWriteObject_SetOwner() throws Exception {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		MockBean4Owner_Target t = new MockBean4Owner_Target();
-		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
-		t.setV(o);
-		enc.setOwner(o);
-
-		assertCodedXML(t, "/xml/MockBean4Owner_SetOwner.xml", temp, enc);
-
-	}
-
-	public void testWriteObject_SetOwnerWithWriteStatement() throws Exception {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		MockBean4Owner_Target t = new MockBean4Owner_Target();
-		MockBean4Owner_Owner o = new MockBean4Owner_Owner();
-		t.setV(o);
-		enc.setOwner(o);
-
-		enc.writeStatement(new Statement(o, "loading", new Object[] {}));
-
-		assertCodedXML(t, "/xml/MockBean4Owner_SetOwnerWithWriteStatement.xml",
-				temp, enc);
-
-	}
-
-	public void testWriteObject_StaticField() throws Exception {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
-
-		enc.setPersistenceDelegate(MockBean4StaticField.class,
-				new MockBean4StaticField_PD());
-
-		assertCodedXML(MockBean4StaticField.inst, "/xml/MockBean4StaticField.xml",
-				temp, enc);
-
-	}
-
-	public void testClose() {
-		ByteArrayOutputStream out = new ByteArrayOutputStream() {
-			boolean closeCalled = false;
-
-			public void close() throws IOException {
-				if (closeCalled) {
-					throw new IOException("close already called!");
-				} else {
-					closeCalled = true;
-					super.close();
-				}
-			}
-		};
-		XMLEncoder enc = new XMLEncoder(out);
-		enc.writeObject(new Integer(3));
-		assertTrue(out.size() == 0);
-
-		enc.close();
-
-		assertTrue(out.size() > 0);
-		try {
-			out.close();
-			fail();
-		} catch (IOException e) {
-			assertEquals("close already called!", e.getMessage());
-		}
-	}
-
-	public void testFlush() {
-		ByteArrayOutputStream out = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(out);
-		Integer i = new Integer(3);
-		enc.writeObject(i);
-		assertTrue(out.size() == 0);
-		assertNotNull(enc.get(i));
-
-		enc.flush();
-
-		assertTrue(out.size() > 0);
-		assertNull(enc.get(i));
-	}
-
-        public void testXMLEncoder_Null() throws NullPointerException {
-                new XMLEncoder(null);
-        }
-
-	public void testGetOwner() {
-		XMLEncoder enc = new XMLEncoder(System.out);
-		assertNull(enc.getOwner());
-	}
-
-	public void testSetOwner() {
-		XMLEncoder enc = new XMLEncoder(System.out);
-		Object owner = Boolean.FALSE;
-
-		enc.setOwner(owner);
-		assertSame(owner, enc.getOwner());
-
-		enc.setOwner(null);
-		assertNull(enc.getOwner());
-	}
-
-	private void assertCodedXML(Object obj, String xmlFile) throws Exception {
-		ByteArrayOutputStream temp = new ByteArrayOutputStream();
-		XMLEncoder enc = new XMLEncoder(temp);
 
-		assertCodedXML(obj, xmlFile, temp, enc);
-	}
+    public static String ident() {
+        Exception ex = new Exception();
+        int level = ex.getStackTrace().length;
+        StringBuffer buf = new StringBuffer();
+        for (int i = 0; i < level; i++) {
+            buf.append("  ");
+        }
+        return buf.toString();
+    }
+
+    public static String string(Statement stat) {
+        String str = "(" + stat.getTarget() + ")." + stat.getMethodName() + "(";
+        Object args[] = stat.getArguments();
+        for (int i = 0; i < args.length; i++) {
+            if (i > 0) {
+                str += ", ";
+            }
+            str += args[i];
+        }
+        str = str + ")";
+        return str;
+    }
+
+    public static String string(Expression exp) {
+        String str = "";
+        try {
+            str += str + exp.getValue();
+        } catch (Exception e) {
+            e.printStackTrace();
+        }
+        str += "=" + string((Statement) exp);
+        return str;
+    }
+
+    public void testWriteExpression() {
+        // covered by testWriteObject
+    }
+
+    public void testWriteStatement() {
+        // coverd by testWriteStatement
+    }
+
+    public void testWriteObject_Null() throws Exception {
+        assertCodedXML(null, "/xml/null.xml");
+    }
+
+    public void testWriteObject_Integer() throws Exception {
+        assertCodedXML(new Integer(3), "/xml/int.xml");
+    }
+
+    public void testWriteObject_StringCodec() throws Exception {
+        SampleBean b = new SampleBean();
+        b.setMyid("<Li Yang> & \"liyang'");
+        SampleBean c = new SampleBean();
+        c.setMyid("a child");
+        b.setRef(c);
+        assertCodedXML(b, "/xml/SampleBean_StringCodec.xml");
+    }
+
+    public void testWriteObject_IntArray() throws Exception {
+        assertCodedXML(new int[] { 1, 2, 3 }, "/xml/IntArray.xml");
+    }
+
+    public void testWriteObject_PropertyDependency() throws Exception {
+        DependencyBean b = new DependencyBean();
+        b.getInts()[0] = 888;
+        b.setRef(b.getInts());
+        assertCodedXML(b, "/xml/DependencyBean.xml");
+    }
+
+    public void testWriteObject_NoChange() throws Exception {
+        assertCodedXML(new MockBean4Codec(), "/xml/MockBean4Codec_NoChange.xml");
+    }
+
+    public void testWriteObject_BornFriendChange() throws Exception {
+        MockBean4Codec b = new MockBean4Codec();
+        b.getBornFriend().getZarr()[0] = 888;
+        b.setNill(b.getBornFriend());
+
+        assertCodedXML(b, "/xml/MockBean4Codec_BornFriendChange.xml");
+    }
+
+    public void testWriteObject_ManyChanges() throws Exception {
+        assertCodedXML(MockBean4Codec.getInstanceOfManyChanges(),
+                "/xml/MockBean4Codec_ManyChanges.xml");
+    }
+
+    public void testWriteObject_ManyChanges_2() throws Exception {
+        assertCodedXML(MockBean4Codec.getInstanceOfManyChanges2(),
+                "/xml/MockBean4Codec_ManyChanges_2.xml");
+    }
+
+    public void testWriteObject_SetOwner() throws Exception {
+        ByteArrayOutputStream temp = new ByteArrayOutputStream();
+        XMLEncoder enc = new XMLEncoder(temp);
 
-	private void assertCodedXML(Object obj, String xmlFile,
-			ByteArrayOutputStream temp, XMLEncoder enc) throws Exception {
+        MockBean4Owner_Target t = new MockBean4Owner_Target();
+        MockBean4Owner_Owner o = new MockBean4Owner_Owner();
+        t.setV(o);
+        enc.setOwner(o);
+
+        assertCodedXML(t, "/xml/MockBean4Owner_SetOwner.xml", temp, enc);
+
+    }
+
+    public void testWriteObject_SetOwnerWithWriteStatement() throws Exception {
+        ByteArrayOutputStream temp = new ByteArrayOutputStream();
+        XMLEncoder enc = new XMLEncoder(temp);
+
+        MockBean4Owner_Target t = new MockBean4Owner_Target();
+        MockBean4Owner_Owner o = new MockBean4Owner_Owner();
+        t.setV(o);
+        enc.setOwner(o);
+
+        enc.writeStatement(new Statement(o, "loading", new Object[] {}));
+
+        assertCodedXML(t, "/xml/MockBean4Owner_SetOwnerWithWriteStatement.xml",
+                temp, enc);
+
+    }
+
+    public void testWriteObject_StaticField() throws Exception {
+        ByteArrayOutputStream temp = new ByteArrayOutputStream();
+        XMLEncoder enc = new XMLEncoder(temp);
+
+        enc.setPersistenceDelegate(MockBean4StaticField.class,
+                new MockBean4StaticField_PD());
+
+        assertCodedXML(MockBean4StaticField.inst,
+                "/xml/MockBean4StaticField.xml", temp, enc);
+
+    }
+
+    public void testClose() {
+        ByteArrayOutputStream out = new ByteArrayOutputStream() {
+            boolean closeCalled = false;
+
+            public void close() throws IOException {
+                if (closeCalled) {
+                    throw new IOException("close already called!");
+                } else {
+                    closeCalled = true;
+                    super.close();
+                }
+            }
+        };
+        XMLEncoder enc = new XMLEncoder(out);
+        enc.writeObject(new Integer(3));
+        assertTrue(out.size() == 0);
+
+        enc.close();
+
+        assertTrue(out.size() > 0);
+        try {
+            out.close();
+            fail();
+        } catch (IOException e) {
+            assertEquals("close already called!", e.getMessage());
+        }
+    }
+
+    public void testFlush() {
+        ByteArrayOutputStream out = new ByteArrayOutputStream();
+        XMLEncoder enc = new XMLEncoder(out);
+        Integer i = new Integer(3);
+        enc.writeObject(i);
+        assertTrue(out.size() == 0);
+        assertNotNull(enc.get(i));
+
+        enc.flush();
+
+        assertTrue(out.size() > 0);
+        assertNull(enc.get(i));
+    }
+
+    public void testXMLEncoder_Null() throws NullPointerException {
+        new XMLEncoder(null);
+    }
+
+    public void testGetOwner() {
+        XMLEncoder enc = new XMLEncoder(System.out);
+        assertNull(enc.getOwner());
+    }
+
+    public void testSetOwner() {
+        XMLEncoder enc = new XMLEncoder(System.out);
+        Object owner = Boolean.FALSE;
+
+        enc.setOwner(owner);
+        assertSame(owner, enc.getOwner());
+
+        enc.setOwner(null);
+        assertNull(enc.getOwner());
+    }
+
+    private void assertCodedXML(Object obj, String xmlFile) throws Exception {
+        ByteArrayOutputStream temp = new ByteArrayOutputStream();
+        XMLEncoder enc = new XMLEncoder(temp);
+
+        assertCodedXML(obj, xmlFile, temp, enc);
+    }
+
+    private void assertCodedXML(Object obj, String xmlFile,
+            ByteArrayOutputStream temp, XMLEncoder enc) throws Exception {
 
         InputStream refIn;
-	    InputStreamReader xml;
+        InputStreamReader xml;
         InputStreamReader refXml;
 
         XMLReader xmlReader;
@@ -369,32 +368,32 @@
         TestEventHandler handler = new TestEventHandler();
         TestEventHandler refHandler = new TestEventHandler();
         String saxParserClassName = System.getProperty("org.xml.sax.driver");
-        
-		if (enc == null || temp == null) {
-			temp = new ByteArrayOutputStream();
-			enc = new XMLEncoder(temp);
-		}
-		enc.writeObject(obj);
-		enc.close();
-		byte bytes[] = temp.toByteArray();
-
-		refIn = XMLEncoderTest.class.getResourceAsStream(xmlFile);
-		if (refIn == null) {
-			throw new Error("resource " + xmlFile + " not exist in "
-					+ XMLEncoderTest.class.getPackage());
-		}
-		xml = new InputStreamReader(new ByteArrayInputStream(bytes), "UTF-8");
-		refXml = new InputStreamReader(refIn, "UTF-8");
+
+        if (enc == null || temp == null) {
+            temp = new ByteArrayOutputStream();
+            enc = new XMLEncoder(temp);
+        }
+        enc.writeObject(obj);
+        enc.close();
+        byte bytes[] = temp.toByteArray();
+
+        refIn = XMLEncoderTest.class.getResourceAsStream(xmlFile);
+        if (refIn == null) {
+            throw new Error("resource " + xmlFile + " not exist in "
+                    + XMLEncoderTest.class.getPackage());
+        }
+        xml = new InputStreamReader(new ByteArrayInputStream(bytes), "UTF-8");
+        refXml = new InputStreamReader(refIn, "UTF-8");
 
         if (saxParserClassName == null) {
             saxParserClassName = "org.apache.xerces.parsers.SAXParser";
         }
-        
+
         xmlReader = XMLReaderFactory.createXMLReader(saxParserClassName);
         xmlReader.setContentHandler(handler);
         xmlReader.setErrorHandler(handler);
         xmlReader.parse(new InputSource(xml));
-        
+
         refXmlReader = XMLReaderFactory.createXMLReader(saxParserClassName);
         refXmlReader.setContentHandler(refHandler);
         refXmlReader.setErrorHandler(refHandler);
@@ -402,9 +401,8 @@
 
         assertEquals("Generated XML differs from the sample,", refHandler.root,
                 handler.root);
-	}
+    }
 
-    
     /**
      * The test checks that java.lang.Boolean exemplar store is correct
      */
@@ -412,21 +410,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Boolean(true));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Byte exemplar store is correct
      */
@@ -434,21 +432,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Byte((byte) 123));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Character exemplar store is correct
      */
@@ -456,21 +454,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Character('a'));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Class exemplar store is correct
      */
@@ -478,21 +476,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(Object.class);
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Double exemplar store is correct
      */
@@ -500,21 +498,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Double(0.01));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Float exemplar store is correct
      */
@@ -522,21 +520,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Float((float) 0.01));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Integer exemplar store is correct
      */
@@ -544,21 +542,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Integer(1));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Long exemplar store is correct
      */
@@ -566,21 +564,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Long(1));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.Short exemplar store is correct
      */
@@ -588,21 +586,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new Short((short) 1));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that java.lang.String exemplar store is correct
      */
@@ -610,21 +608,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(new String("hello"));
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that array exemplar store is correct
      */
@@ -632,21 +630,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
-            e.writeObject(new int[] {1, 2, 3});
+            e.writeObject(new int[] { 1, 2, 3 });
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that null exemplar store is correct
      */
@@ -654,21 +652,21 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             e.writeObject(null);
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that complex scenario store is correct
      */
@@ -676,30 +674,30 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
 
         StandardBean bean1 = new StandardBean("bean1");
-        
+
         StandardBean bean2 = new StandardBean();
         bean2.setText(null);
-        
+
         bean1.setPeer(bean2);
         bean2.setPeer(bean1);
-        
+
         try {
             e.writeObject(bean1);
             e.writeObject(bean2);
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();
         }
     }
-    
+
     /**
      * The test checks that encoder can handle writeExpression in initialize
      */
@@ -707,32 +705,29 @@
         XMLEncoder e = new XMLEncoder(System.out);
         e.setExceptionListener(new ExceptionListener() {
             public void exceptionThrown(Exception e) {
-                fail("Exception " + e.getClass() +" is thrown: "
+                fail("Exception " + e.getClass() + " is thrown: "
                         + e.getMessage());
             }
         });
-        
+
         try {
             final Object object = new Object();
             e.setPersistenceDelegate(AType.class,
                     new DefaultPersistenceDelegate() {
-                        protected void initialize(
-                                Class type,
-                                Object oldInstance,
-                                Object newInstance,
+                        protected void initialize(Class type,
+                                Object oldInstance, Object newInstance,
                                 Encoder out) {
-                            out.writeExpression(new Expression(
-                                    object, oldInstance, "go", new Object[] {}
-                                    ));
+                            out.writeExpression(new Expression(object,
+                                    oldInstance, "go", new Object[] {}));
                         }
                     });
             AType a = new AType();
 
-            //e.writeObject(object);
+            // e.writeObject(object);
             e.writeObject(a);
             e.writeObject(object);
         } catch (Exception excp) {
-            fail("Exception " + excp.getClass() +" is thrown: "
+            fail("Exception " + excp.getClass() + " is thrown: "
                     + excp.getMessage());
         } finally {
             e.close();

Modified: incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java
URL: http://svn.apache.org/viewvc/incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java?view=diff&rev=452415&r1=452414&r2=452415
==============================================================================
--- incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java
(original)
+++ incubator/harmony/enhanced/classlib/trunk/modules/beans/src/test/java/org/apache/harmony/beans/tests/java/beans/beancontext/AllTests.java
Tue Oct  3 04:05:57 2006
@@ -25,22 +25,22 @@
  */
 public class AllTests {
 
-	public static void main(String[] args) {
-		junit.textui.TestRunner.run(suite());
-	}
+    public static void main(String[] args) {
+        junit.textui.TestRunner.run(suite());
+    }
 
-	public static Test suite() {
-		TestSuite suite = new TestSuite(
+    public static Test suite() {
+        TestSuite suite = new TestSuite(
                 "Suite for org.apache.harmony.beans.tests.java.beans.beancontext");
-		// $JUnit-BEGIN$
-		suite.addTestSuite(BeanContextChildSupportTest.class);
-		suite.addTestSuite(BeanContextEventTest.class);
-		suite.addTestSuite(BeanContextMembershipEventTest.class);
-		suite.addTestSuite(BeanContextServiceAvailableEventTest.class);
-		suite.addTestSuite(BeanContextServiceRevokedEventTest.class);
-		suite.addTestSuite(BeanContextServicesSupportTest.class);
-		suite.addTestSuite(BeanContextSupportTest.class);
-		// $JUnit-END$
-		return suite;
-	}
+        // $JUnit-BEGIN$
+        suite.addTestSuite(BeanContextChildSupportTest.class);
+        suite.addTestSuite(BeanContextEventTest.class);
+        suite.addTestSuite(BeanContextMembershipEventTest.class);
+        suite.addTestSuite(BeanContextServiceAvailableEventTest.class);
+        suite.addTestSuite(BeanContextServiceRevokedEventTest.class);
+        suite.addTestSuite(BeanContextServicesSupportTest.class);
+        suite.addTestSuite(BeanContextSupportTest.class);
+        // $JUnit-END$
+        return suite;
+    }
 }



Mime
View raw message