1 43 44 package org.jfree.chart.plot.junit; 45 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.event.MarkerChangeEvent; 58 import org.jfree.chart.event.MarkerChangeListener; 59 import org.jfree.chart.plot.IntervalMarker; 60 import org.jfree.ui.GradientPaintTransformType; 61 import org.jfree.ui.GradientPaintTransformer; 62 import org.jfree.ui.StandardGradientPaintTransformer; 63 64 67 public class IntervalMarkerTests 68 extends TestCase 69 implements MarkerChangeListener { 70 71 MarkerChangeEvent lastEvent; 72 73 public void markerChanged(MarkerChangeEvent event) { 74 this.lastEvent = event; 75 } 76 77 82 public static Test suite() { 83 return new TestSuite(IntervalMarkerTests.class); 84 } 85 86 91 public IntervalMarkerTests(String name) { 92 super(name); 93 } 94 95 98 public void testEquals() { 99 100 IntervalMarker m1 = new IntervalMarker(45.0, 50.0); 101 IntervalMarker m2 = new IntervalMarker(45.0, 50.0); 102 assertTrue(m1.equals(m2)); 103 assertTrue(m2.equals(m1)); 104 105 m1 = new IntervalMarker(44.0, 50.0); 106 assertFalse(m1.equals(m2)); 107 m2 = new IntervalMarker(44.0, 50.0); 108 assertTrue(m1.equals(m2)); 109 110 m1 = new IntervalMarker(44.0, 55.0); 111 assertFalse(m1.equals(m2)); 112 m2 = new IntervalMarker(44.0, 55.0); 113 assertTrue(m1.equals(m2)); 114 115 GradientPaintTransformer t = new StandardGradientPaintTransformer( 116 GradientPaintTransformType.HORIZONTAL); 117 m1.setGradientPaintTransformer(t); 118 assertFalse(m1.equals(m2)); 119 m2.setGradientPaintTransformer(t); 120 assertTrue(m1.equals(m2)); 121 122 } 123 124 127 public void testCloning() { 128 IntervalMarker m1 = new IntervalMarker(45.0, 50.0); 129 IntervalMarker m2 = null; 130 try { 131 m2 = (IntervalMarker) m1.clone(); 132 } 133 catch (CloneNotSupportedException e) { 134 e.printStackTrace(); 135 } 136 assertTrue(m1 != m2); 137 assertTrue(m1.getClass() == m2.getClass()); 138 assertTrue(m1.equals(m2)); 139 } 140 141 144 public void testSerialization() { 145 146 IntervalMarker m1 = new IntervalMarker(45.0, 50.0); 147 IntervalMarker m2 = null; 148 try { 149 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 150 ObjectOutput out = new ObjectOutputStream (buffer); 151 out.writeObject(m1); 152 out.close(); 153 154 ObjectInput in = new ObjectInputStream ( 155 new ByteArrayInputStream (buffer.toByteArray())); 156 m2 = (IntervalMarker) in.readObject(); 157 in.close(); 158 } 159 catch (Exception e) { 160 e.printStackTrace(); 161 } 162 boolean b = m1.equals(m2); 163 assertTrue(b); 164 165 } 166 167 private static final double EPSILON = 0.0000000001; 168 169 172 public void testGetSetStartValue() { 173 IntervalMarker m = new IntervalMarker(1.0, 2.0); 174 m.addChangeListener(this); 175 this.lastEvent = null; 176 assertEquals(1.0, m.getStartValue(), EPSILON); 177 m.setStartValue(0.5); 178 assertEquals(0.5, m.getStartValue(), EPSILON); 179 assertEquals(m, this.lastEvent.getMarker()); 180 } 181 182 185 public void testGetSetEndValue() { 186 IntervalMarker m = new IntervalMarker(1.0, 2.0); 187 m.addChangeListener(this); 188 this.lastEvent = null; 189 assertEquals(2.0, m.getEndValue(), EPSILON); 190 m.setEndValue(0.5); 191 assertEquals(0.5, m.getEndValue(), EPSILON); 192 assertEquals(m, this.lastEvent.getMarker()); 193 } 194 } 195 | Popular Tags |