1 39 40 package org.jfree.chart.renderer.junit; 41 42 import java.awt.Color ; 43 import java.io.ByteArrayInputStream ; 44 import java.io.ByteArrayOutputStream ; 45 import java.io.ObjectInput ; 46 import java.io.ObjectInputStream ; 47 import java.io.ObjectOutput ; 48 import java.io.ObjectOutputStream ; 49 50 import junit.framework.Test; 51 import junit.framework.TestCase; 52 import junit.framework.TestSuite; 53 54 import org.jfree.chart.renderer.BarRenderer; 55 56 61 public class BarRendererTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(BarRendererTests.class); 70 } 71 72 77 public BarRendererTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 BarRenderer r1 = new BarRenderer(); 86 BarRenderer r2 = new BarRenderer(); 87 assertEquals(r1, r2); 88 } 89 90 93 public void testHashcode() { 94 BarRenderer r1 = new BarRenderer(); 95 BarRenderer r2 = new BarRenderer(); 96 assertTrue(r1.equals(r2)); 97 int h1 = r1.hashCode(); 98 int h2 = r2.hashCode(); 99 assertEquals(h1, h2); 100 } 101 102 105 public void testCloning() { 106 BarRenderer r1 = new BarRenderer(); 107 BarRenderer r2 = null; 108 try { 109 r2 = (BarRenderer) r1.clone(); 110 } 111 catch (CloneNotSupportedException e) { 112 System.err.println("BarRendererTests.testCloning: failed to clone."); 113 } 114 assertTrue(r1 != r2); 115 assertTrue(r1.getClass() == r2.getClass()); 116 assertTrue(r1.equals(r2)); 117 } 118 119 122 public void testSerialization() { 123 124 BarRenderer r1 = new BarRenderer(); 125 BarRenderer r2 = null; 126 127 try { 128 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 129 ObjectOutput out = new ObjectOutputStream (buffer); 130 out.writeObject(r1); 131 out.close(); 132 133 ObjectInput in = new ObjectInputStream (new ByteArrayInputStream (buffer.toByteArray())); 134 r2 = (BarRenderer) in.readObject(); 135 in.close(); 136 } 137 catch (Exception e) { 138 System.out.println(e.toString()); 139 } 140 assertEquals(r1, r2); 141 142 } 143 144 147 public void testEventNotification() { 148 149 RendererChangeDetector detector = new RendererChangeDetector(); 150 BarRenderer r1 = new BarRenderer(); 151 r1.addChangeListener(detector); 152 153 detector.setNotified(false); 154 r1.setPaint(Color.red); 155 assertTrue(detector.getNotified()); 156 157 } 158 159 } 160 | Popular Tags |