1 43 44 package org.jfree.util.junit; 45 46 import java.awt.Color ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.util.ObjectList; 59 60 63 public class ObjectListTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(ObjectListTests.class); 72 } 73 74 79 public ObjectListTests(final String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 88 final ObjectList l1 = new ObjectList(); 89 l1.set(0, Color.blue); 90 l1.set(1, Color.red); 91 92 final ObjectList l2 = new ObjectList(); 93 l2.set(0, Color.blue); 94 l2.set(1, Color.red); 95 96 assertTrue(l1.equals(l2)); 97 assertTrue(l2.equals(l2)); 98 99 } 100 101 105 public void testEquals2() { 106 107 final ObjectList l1 = new ObjectList(20); 108 l1.set(0, Color.blue); 109 l1.set(1, Color.red); 110 111 final ObjectList l2 = new ObjectList(); 112 l2.set(0, Color.blue); 113 l2.set(1, Color.red); 114 115 assertTrue(l1.equals(l2)); 116 assertTrue(l2.equals(l2)); 117 118 } 119 120 123 public void testCloning() { 124 125 final ObjectList l1 = new ObjectList(); 126 l1.set(0, Color.blue); 127 l1.set(1, Color.red); 128 129 ObjectList l2 = null; 130 try { 131 l2 = (ObjectList) l1.clone(); 132 } 133 catch (CloneNotSupportedException e) { 134 System.err.println("ObjectListTests.testCloning: failed to clone."); 135 } 136 assertTrue(l1 != l2); 137 assertTrue(l1.getClass() == l2.getClass()); 138 assertTrue(l1.equals(l2)); 139 140 l2.set(0, Color.green); 141 assertFalse(l1.equals(l2)); 142 143 } 144 145 148 public void testSerialization() { 149 150 final ObjectList l1 = new ObjectList(); 151 l1.set(0, Color.red); 152 l1.set(1, Color.blue); 153 l1.set(2, null); 154 155 ObjectList l2 = null; 156 157 try { 158 final ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 159 final ObjectOutput out = new ObjectOutputStream (buffer); 160 out.writeObject(l1); 161 out.close(); 162 163 final ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 164 l2 = (ObjectList) in.readObject(); 165 in.close(); 166 } 167 catch (Exception e) { 168 System.out.println(e.toString()); 169 } 170 assertEquals(l1, l2); 171 172 } 173 174 178 public void testExpand() { 179 final ObjectList l1 = new ObjectList(); 180 l1.set(10, Color.blue); 181 final Color c = (Color ) l1.get(10); 182 assertTrue(c.equals(Color.blue)); 183 } 184 185 } 186 | Popular Tags |