1 45 46 package org.jfree.chart.renderer.xy.junit; 47 48 import java.awt.Color ; 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 import java.util.Date ; 56 57 import junit.framework.Test; 58 import junit.framework.TestCase; 59 import junit.framework.TestSuite; 60 61 import org.jfree.chart.renderer.xy.HighLowRenderer; 62 import org.jfree.data.Range; 63 import org.jfree.data.xy.DefaultOHLCDataset; 64 import org.jfree.data.xy.OHLCDataItem; 65 import org.jfree.data.xy.OHLCDataset; 66 67 70 public class HighLowRendererTests extends TestCase { 71 72 77 public static Test suite() { 78 return new TestSuite(HighLowRendererTests.class); 79 } 80 81 86 public HighLowRendererTests(String name) { 87 super(name); 88 } 89 90 93 public void testEquals() { 94 HighLowRenderer r1 = new HighLowRenderer(); 95 HighLowRenderer r2 = new HighLowRenderer(); 96 assertEquals(r1, r2); 97 98 r1.setDrawOpenTicks(false); 100 assertFalse(r1.equals(r2)); 101 r2.setDrawOpenTicks(false); 102 assertTrue(r1.equals(r2)); 103 104 r1.setDrawCloseTicks(false); 106 assertFalse(r1.equals(r2)); 107 r2.setDrawCloseTicks(false); 108 assertTrue(r1.equals(r2)); 109 110 r1.setOpenTickPaint(Color.red); 112 assertFalse(r1.equals(r2)); 113 r2.setOpenTickPaint(Color.red); 114 assertTrue(r1.equals(r2)); 115 116 r1.setCloseTickPaint(Color.blue); 118 assertFalse(r1.equals(r2)); 119 r2.setCloseTickPaint(Color.blue); 120 assertTrue(r1.equals(r2)); 121 } 122 123 126 public void testHashcode() { 127 HighLowRenderer r1 = new HighLowRenderer(); 128 HighLowRenderer r2 = new HighLowRenderer(); 129 assertTrue(r1.equals(r2)); 130 int h1 = r1.hashCode(); 131 int h2 = r2.hashCode(); 132 assertEquals(h1, h2); 133 } 134 135 138 public void testCloning() { 139 HighLowRenderer r1 = new HighLowRenderer(); 140 r1.setCloseTickPaint(Color.green); 141 HighLowRenderer r2 = null; 142 try { 143 r2 = (HighLowRenderer) r1.clone(); 144 } 145 catch (CloneNotSupportedException e) { 146 e.printStackTrace(); 147 } 148 assertTrue(r1 != r2); 149 assertTrue(r1.getClass() == r2.getClass()); 150 assertTrue(r1.equals(r2)); 151 } 152 153 156 public void testSerialization() { 157 158 HighLowRenderer r1 = new HighLowRenderer(); 159 r1.setCloseTickPaint(Color.green); 160 HighLowRenderer r2 = null; 161 162 try { 163 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 164 ObjectOutput out = new ObjectOutputStream (buffer); 165 out.writeObject(r1); 166 out.close(); 167 168 ObjectInput in = new ObjectInputStream ( 169 new ByteArrayInputStream (buffer.toByteArray()) 170 ); 171 r2 = (HighLowRenderer) in.readObject(); 172 in.close(); 173 } 174 catch (Exception e) { 175 e.printStackTrace(); 176 } 177 assertEquals(r1, r2); 178 179 } 180 181 184 public void testFindRangeBounds() { 185 HighLowRenderer renderer = new HighLowRenderer(); 186 187 OHLCDataItem item1 = new OHLCDataItem(new Date (1L), 2.0, 4.0, 1.0, 3.0, 188 100); 189 OHLCDataset dataset = new DefaultOHLCDataset("S1", 190 new OHLCDataItem[] {item1}); 191 Range range = renderer.findRangeBounds(dataset); 192 assertEquals(new Range(1.0, 4.0), range); 193 194 OHLCDataItem item2 = new OHLCDataItem(new Date (1L), -1.0, 3.0, -1.0, 195 3.0, 100); 196 dataset = new DefaultOHLCDataset("S1", new OHLCDataItem[] {item1, 197 item2}); 198 range = renderer.findRangeBounds(dataset); 199 assertEquals(new Range(-1.0, 4.0), range); 200 201 dataset = new DefaultOHLCDataset("S1", new OHLCDataItem[] {}); 203 range = renderer.findRangeBounds(dataset); 204 assertNull(range); 205 206 range = renderer.findRangeBounds(null); 208 assertNull(range); 209 } 210 211 212 } 213 | Popular Tags |