1 42 43 package org.jfree.chart.renderer.category.junit; 44 45 import java.awt.Color ; 46 import java.io.ByteArrayInputStream ; 47 import java.io.ByteArrayOutputStream ; 48 import java.io.ObjectInput ; 49 import java.io.ObjectInputStream ; 50 import java.io.ObjectOutput ; 51 import java.io.ObjectOutputStream ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.renderer.category.WaterfallBarRenderer; 58 59 62 public class WaterfallBarRendererTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(WaterfallBarRendererTests.class); 71 } 72 73 78 public WaterfallBarRendererTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 WaterfallBarRenderer r1 = new WaterfallBarRenderer(); 87 WaterfallBarRenderer r2 = new WaterfallBarRenderer(); 88 assertEquals(r1, r2); 89 90 r1.setFirstBarPaint(Color.cyan); 92 assertFalse(r1.equals(r2)); 93 r2.setFirstBarPaint(Color.cyan); 94 assertTrue(r1.equals(r2)); 95 96 r1.setLastBarPaint(Color.cyan); 98 assertFalse(r1.equals(r2)); 99 r2.setLastBarPaint(Color.cyan); 100 assertTrue(r1.equals(r2)); 101 102 r1.setPositiveBarPaint(Color.cyan); 104 assertFalse(r1.equals(r2)); 105 r2.setPositiveBarPaint(Color.cyan); 106 assertTrue(r1.equals(r2)); 107 108 r1.setNegativeBarPaint(Color.cyan); 110 assertFalse(r1.equals(r2)); 111 r2.setNegativeBarPaint(Color.cyan); 112 assertTrue(r1.equals(r2)); 113 114 } 115 116 119 public void testHashcode() { 120 WaterfallBarRenderer r1 = new WaterfallBarRenderer(); 121 WaterfallBarRenderer r2 = new WaterfallBarRenderer(); 122 assertTrue(r1.equals(r2)); 123 int h1 = r1.hashCode(); 124 int h2 = r2.hashCode(); 125 assertEquals(h1, h2); 126 } 127 128 131 public void testCloning() { 132 WaterfallBarRenderer r1 = new WaterfallBarRenderer(); 133 WaterfallBarRenderer r2 = null; 134 try { 135 r2 = (WaterfallBarRenderer) r1.clone(); 136 } 137 catch (CloneNotSupportedException e) { 138 System.err.println("Failed to clone."); 139 } 140 assertTrue(r1 != r2); 141 assertTrue(r1.getClass() == r2.getClass()); 142 assertTrue(r1.equals(r2)); 143 144 r1.setFirstBarPaint(Color.yellow); 146 assertFalse(r1.equals(r2)); 147 r2.setFirstBarPaint(Color.yellow); 148 assertTrue(r1.equals(r2)); 149 150 } 151 152 155 public void testSerialization() { 156 157 WaterfallBarRenderer r1 = new WaterfallBarRenderer(); 158 WaterfallBarRenderer r2 = null; 159 160 try { 161 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 162 ObjectOutput out = new ObjectOutputStream (buffer); 163 out.writeObject(r1); 164 out.close(); 165 166 ObjectInput in = new ObjectInputStream ( 167 new ByteArrayInputStream (buffer.toByteArray()) 168 ); 169 r2 = (WaterfallBarRenderer) in.readObject(); 170 in.close(); 171 } 172 catch (Exception e) { 173 System.out.println(e.toString()); 174 } 175 assertEquals(r1, r2); 176 177 } 178 179 } 180 | Popular Tags |