1 42 43 package org.jfree.chart.plot.junit; 44 45 import java.awt.BasicStroke ; 46 import java.awt.Color ; 47 import java.awt.Paint ; 48 import java.awt.Shape ; 49 import java.awt.Stroke ; 50 import java.awt.geom.Rectangle2D ; 51 import java.io.ByteArrayInputStream ; 52 import java.io.ByteArrayOutputStream ; 53 import java.io.ObjectInput ; 54 import java.io.ObjectInputStream ; 55 import java.io.ObjectOutput ; 56 import java.io.ObjectOutputStream ; 57 58 import junit.framework.Test; 59 import junit.framework.TestCase; 60 import junit.framework.TestSuite; 61 62 import org.jfree.chart.plot.DefaultDrawingSupplier; 63 64 67 public class DefaultDrawingSupplierTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(DefaultDrawingSupplierTests.class); 76 } 77 78 83 public DefaultDrawingSupplierTests(String name) { 84 super(name); 85 } 86 87 90 public void testEquals() { 91 DefaultDrawingSupplier r1 = new DefaultDrawingSupplier(); 92 DefaultDrawingSupplier r2 = new DefaultDrawingSupplier(); 93 assertTrue(r1.equals(r2)); 94 assertTrue(r2.equals(r1)); 95 96 Paint [] ps1A = new Paint [] {Color.red, Color.blue}; 98 Paint [] ps2A = new Paint [] {Color.green, Color.yellow, Color.white}; 99 Paint [] ops1A = new Paint [] {Color.lightGray, Color.blue}; 100 Paint [] ops2A = new Paint [] {Color.black, Color.yellow, Color.cyan}; 101 Stroke [] ss1A = new Stroke [] {new BasicStroke (1.1f)}; 102 Stroke [] ss2A 103 = new Stroke [] {new BasicStroke (2.2f), new BasicStroke (3.3f)}; 104 Stroke [] oss1A = new Stroke [] {new BasicStroke (4.4f)}; 105 Stroke [] oss2A 106 = new Stroke [] {new BasicStroke (5.5f), new BasicStroke (6.6f)}; 107 Shape [] shapes1A = new Shape [] { 108 new Rectangle2D.Double (1.0, 1.0, 1.0, 1.0) 109 }; 110 Shape [] shapes2A = new Shape [] { 111 new Rectangle2D.Double (2.0, 2.0, 2.0, 2.0), 112 new Rectangle2D.Double (2.0, 2.0, 2.0, 2.0) 113 }; 114 Paint [] ps1B = new Paint [] {Color.red, Color.blue}; 115 Paint [] ps2B = new Paint [] {Color.green, Color.yellow, Color.white}; 116 Paint [] ops1B = new Paint [] {Color.lightGray, Color.blue}; 117 Paint [] ops2B = new Paint [] {Color.black, Color.yellow, Color.cyan}; 118 Stroke [] ss1B = new Stroke [] {new BasicStroke (1.1f)}; 119 Stroke [] ss2B 120 = new Stroke [] {new BasicStroke (2.2f), new BasicStroke (3.3f)}; 121 Stroke [] oss1B = new Stroke [] {new BasicStroke (4.4f)}; 122 Stroke [] oss2B 123 = new Stroke [] {new BasicStroke (5.5f), new BasicStroke (6.6f)}; 124 Shape [] shapes1B = new Shape [] { 125 new Rectangle2D.Double (1.0, 1.0, 1.0, 1.0) 126 }; 127 Shape [] shapes2B = new Shape [] { 128 new Rectangle2D.Double (2.0, 2.0, 2.0, 2.0), 129 new Rectangle2D.Double (2.0, 2.0, 2.0, 2.0) 130 }; 131 132 r1 = new DefaultDrawingSupplier(ps1A, ops1A, ss1A, oss1A, shapes1A); 133 r2 = new DefaultDrawingSupplier(ps1B, ops1B, ss1B, oss1B, shapes1B); 134 assertTrue(r1.equals(r2)); 135 136 r1 = new DefaultDrawingSupplier(ps2A, ops1A, ss1A, oss1A, shapes1A); 138 assertFalse(r1.equals(r2)); 139 r2 = new DefaultDrawingSupplier(ps2B, ops1B, ss1B, oss1B, shapes1B); 140 assertTrue(r1.equals(r2)); 141 r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss1A, oss1A, shapes1A); 143 assertFalse(r1.equals(r2)); 144 r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss1B, oss1B, shapes1B); 145 assertTrue(r1.equals(r2)); 146 r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss2A, oss1A, shapes1A); 148 assertFalse(r1.equals(r2)); 149 r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss2B, oss1B, shapes1B); 150 assertTrue(r1.equals(r2)); 151 r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss2A, oss2A, shapes1A); 153 assertFalse(r1.equals(r2)); 154 r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss2B, oss2B, shapes1B); 155 assertTrue(r1.equals(r2)); 156 r1 = new DefaultDrawingSupplier(ps2A, ops2A, ss2A, oss2A, shapes2A); 158 assertFalse(r1.equals(r2)); 159 r2 = new DefaultDrawingSupplier(ps2B, ops2B, ss2B, oss2B, shapes2B); 160 assertTrue(r1.equals(r2)); 161 162 r1.getNextPaint(); 164 assertFalse(r1.equals(r2)); 165 r2.getNextPaint(); 166 assertTrue(r1.equals(r2)); 167 168 r1.getNextOutlinePaint(); 170 assertFalse(r1.equals(r2)); 171 r2.getNextOutlinePaint(); 172 assertTrue(r1.equals(r2)); 173 174 r1.getNextStroke(); 176 assertFalse(r1.equals(r2)); 177 r2.getNextStroke(); 178 assertTrue(r1.equals(r2)); 179 180 r1.getNextOutlineStroke(); 182 assertFalse(r1.equals(r2)); 183 r2.getNextOutlineStroke(); 184 assertTrue(r1.equals(r2)); 185 186 r1.getNextShape(); 188 assertFalse(r1.equals(r2)); 189 r2.getNextShape(); 190 assertTrue(r1.equals(r2)); 191 } 192 193 196 public void testCloning() { 197 DefaultDrawingSupplier r1 = new DefaultDrawingSupplier(); 198 DefaultDrawingSupplier r2 = null; 199 try { 200 r2 = (DefaultDrawingSupplier) r1.clone(); 201 } 202 catch (CloneNotSupportedException e) { 203 e.printStackTrace(); 204 System.err.println("Failed to clone."); 205 } 206 assertTrue(r1 != r2); 207 assertTrue(r1.getClass() == r2.getClass()); 208 assertTrue(r1.equals(r2)); 209 } 210 211 214 public void testSerialization() { 215 216 DefaultDrawingSupplier r1 = new DefaultDrawingSupplier(); 217 DefaultDrawingSupplier r2 = null; 218 219 try { 220 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 221 ObjectOutput out = new ObjectOutputStream (buffer); 222 out.writeObject(r1); 223 out.close(); 224 225 ObjectInput in = new ObjectInputStream ( 226 new ByteArrayInputStream (buffer.toByteArray()) 227 ); 228 r2 = (DefaultDrawingSupplier) in.readObject(); 229 in.close(); 230 } 231 catch (Exception e) { 232 System.out.println(e.toString()); 233 } 234 assertEquals(r1, r2); 235 236 } 237 238 } 239 | Popular Tags |