1 42 43 package org.jfree.chart.renderer.category.junit; 44 45 import java.io.ByteArrayInputStream ; 46 import java.io.ByteArrayOutputStream ; 47 import java.io.ObjectInput ; 48 import java.io.ObjectInputStream ; 49 import java.io.ObjectOutput ; 50 import java.io.ObjectOutputStream ; 51 52 import junit.framework.Test; 53 import junit.framework.TestCase; 54 import junit.framework.TestSuite; 55 56 import org.jfree.chart.renderer.category.CategoryStepRenderer; 57 58 61 public class CategoryStepRendererTests extends TestCase { 62 63 68 public static Test suite() { 69 return new TestSuite(CategoryStepRendererTests.class); 70 } 71 72 77 public CategoryStepRendererTests(String name) { 78 super(name); 79 } 80 81 84 public void testEquals() { 85 CategoryStepRenderer r1 = new CategoryStepRenderer(false); 86 CategoryStepRenderer r2 = new CategoryStepRenderer(false); 87 assertEquals(r1, r2); 88 89 r1 = new CategoryStepRenderer(true); 90 assertFalse(r1.equals(r2)); 91 r2 = new CategoryStepRenderer(true); 92 assertTrue(r1.equals(r2)); 93 } 94 95 98 public void testCloning() { 99 CategoryStepRenderer r1 = new CategoryStepRenderer(false); 100 CategoryStepRenderer r2 = null; 101 try { 102 r2 = (CategoryStepRenderer) r1.clone(); 103 } 104 catch (CloneNotSupportedException e) { 105 System.err.println("Failed to clone."); 106 } 107 assertTrue(r1 != r2); 108 assertTrue(r1.getClass() == r2.getClass()); 109 assertTrue(r1.equals(r2)); 110 } 111 112 115 public void testSerialization() { 116 117 CategoryStepRenderer r1 = new CategoryStepRenderer(); 118 CategoryStepRenderer r2 = null; 119 120 try { 121 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 122 ObjectOutput out = new ObjectOutputStream (buffer); 123 out.writeObject(r1); 124 out.close(); 125 126 ObjectInput in = new ObjectInputStream ( 127 new ByteArrayInputStream (buffer.toByteArray()) 128 ); 129 r2 = (CategoryStepRenderer) in.readObject(); 130 in.close(); 131 } 132 catch (Exception e) { 133 System.out.println(e.toString()); 134 } 135 assertEquals(r1, r2); 136 137 } 138 139 } 140 | Popular Tags |