1 43 44 package org.jfree.util.junit; 45 46 import java.awt.Color ; 47 import java.awt.GradientPaint ; 48 import java.awt.Paint ; 49 import java.io.ByteArrayInputStream ; 50 import java.io.ByteArrayOutputStream ; 51 import java.io.ObjectInput ; 52 import java.io.ObjectInputStream ; 53 import java.io.ObjectOutput ; 54 import java.io.ObjectOutputStream ; 55 56 import junit.framework.Test; 57 import junit.framework.TestCase; 58 import junit.framework.TestSuite; 59 60 import org.jfree.util.PaintList; 61 62 65 public class PaintListTests extends TestCase { 66 67 72 public static Test suite() { 73 return new TestSuite(PaintListTests.class); 74 } 75 76 81 public PaintListTests(final String name) { 82 super(name); 83 } 84 85 88 public void testEquals() { 89 final PaintList l1 = new PaintList(); 90 l1.setPaint(0, Color.red); 91 l1.setPaint(1, Color.blue); 92 l1.setPaint(2, null); 93 94 final PaintList l2 = new PaintList(); 95 l2.setPaint(0, Color.red); 96 l2.setPaint(1, Color.blue); 97 l2.setPaint(2, null); 98 99 assertTrue(l1.equals(l2)); 100 assertTrue(l2.equals(l2)); 101 } 102 103 106 public void testEquals2() { 107 final PaintList l1 = new PaintList(); 109 final Color color1 = new Color (200, 200, 200); 110 l1.setPaint(0, color1); 111 final PaintList l2 = new PaintList(); 112 final Color color2 = new Color (200, 200, 200); 113 l2.setPaint(0, color2); 114 assertEquals(l1, l2); 115 } 116 117 121 public void testEquals3() { 122 PaintList l1 = new PaintList(); 124 Paint p1 = new GradientPaint (1.0f, 2.0f, Color.red, 125 3.0f, 4.0f, Color.blue); 126 l1.setPaint(0, p1); 127 PaintList l2 = new PaintList(); 128 Paint p2 = new GradientPaint (1.0f, 2.0f, Color.red, 129 3.0f, 4.0f, Color.blue); 130 l2.setPaint(0, p2); 131 assertEquals(l1, l2); 132 } 133 134 137 public void testCloning() { 138 139 final PaintList l1 = new PaintList(); 140 l1.setPaint(0, Color.red); 141 l1.setPaint(1, Color.blue); 142 l1.setPaint(2, null); 143 144 PaintList l2 = null; 145 try { 146 l2 = (PaintList) l1.clone(); 147 } 148 catch (CloneNotSupportedException e) { 149 System.err.println("PaintListTests.testCloning: failed to clone."); 150 } 151 assertTrue(l1 != l2); 152 assertTrue(l1.getClass() == l2.getClass()); 153 assertTrue(l1.equals(l2)); 154 155 l2.setPaint(0, Color.green); 156 assertFalse(l1.equals(l2)); 157 158 } 159 160 163 public void testSerialization() { 164 165 final PaintList l1 = new PaintList(); 166 l1.setPaint(0, Color.red); 167 l1.setPaint(1, Color.blue); 168 l1.setPaint(2, null); 169 170 PaintList l2 = null; 171 172 try { 173 final ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 174 final ObjectOutput out = new ObjectOutputStream (buffer); 175 out.writeObject(l1); 176 out.close(); 177 178 final ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 179 l2 = (PaintList) in.readObject(); 180 in.close(); 181 } 182 catch (Exception e) { 183 System.out.println(e.toString()); 184 } 185 assertEquals(l1, l2); 186 187 } 188 189 } 190 | Popular Tags |