1 42 43 package org.jfree.chart.title.junit; 44 45 import java.awt.Color ; 46 import java.awt.Font ; 47 import java.io.ByteArrayInputStream ; 48 import java.io.ByteArrayOutputStream ; 49 import java.io.ObjectInput ; 50 import java.io.ObjectInputStream ; 51 import java.io.ObjectOutput ; 52 import java.io.ObjectOutputStream ; 53 54 import junit.framework.Test; 55 import junit.framework.TestCase; 56 import junit.framework.TestSuite; 57 58 import org.jfree.chart.title.DateTitle; 59 60 63 public class DateTitleTests extends TestCase { 64 65 70 public static Test suite() { 71 return new TestSuite(DateTitleTests.class); 72 } 73 74 79 public DateTitleTests(String name) { 80 super(name); 81 } 82 83 86 public void testEquals() { 87 DateTitle t1 = new DateTitle(); 88 DateTitle t2 = new DateTitle(); 89 assertEquals(t1, t2); 90 91 t1.setText("Test 1"); 92 assertFalse(t1.equals(t2)); 93 t2.setText("Test 1"); 94 assertTrue(t1.equals(t2)); 95 96 Font f = new Font ("SansSerif", Font.PLAIN, 15); 97 t1.setFont(f); 98 assertFalse(t1.equals(t2)); 99 t2.setFont(f); 100 assertTrue(t1.equals(t2)); 101 102 t1.setPaint(Color.blue); 103 assertFalse(t1.equals(t2)); 104 t2.setPaint(Color.blue); 105 assertTrue(t1.equals(t2)); 106 107 t1.setBackgroundPaint(Color.blue); 108 assertFalse(t1.equals(t2)); 109 t2.setBackgroundPaint(Color.blue); 110 assertTrue(t1.equals(t2)); 111 112 } 113 114 117 public void testHashcode() { 118 DateTitle t1 = new DateTitle(); 119 DateTitle t2 = new DateTitle(); 120 assertTrue(t1.equals(t2)); 121 int h1 = t1.hashCode(); 122 int h2 = t2.hashCode(); 123 assertEquals(h1, h2); 124 } 125 126 129 public void testCloning() { 130 DateTitle t1 = new DateTitle(); 131 DateTitle t2 = null; 132 try { 133 t2 = (DateTitle) t1.clone(); 134 } 135 catch (CloneNotSupportedException e) { 136 System.err.println("DateTitleTests.testCloning: failed to clone."); 137 } 138 assertTrue(t1 != t2); 139 assertTrue(t1.getClass() == t2.getClass()); 140 assertTrue(t1.equals(t2)); 141 } 142 143 146 public void testSerialization() { 147 148 DateTitle t1 = new DateTitle(); 149 DateTitle t2 = null; 150 151 try { 152 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 153 ObjectOutput out = new ObjectOutputStream (buffer); 154 out.writeObject(t1); 155 out.close(); 156 157 ObjectInput in = new ObjectInputStream ( 158 new ByteArrayInputStream (buffer.toByteArray()) 159 ); 160 t2 = (DateTitle) in.readObject(); 161 in.close(); 162 } 163 catch (Exception e) { 164 System.out.println(e.toString()); 165 } 166 assertEquals(t1, t2); 167 168 } 169 170 } 171 | Popular Tags |