1 44 45 package org.jfree.chart.title.junit; 46 47 import java.awt.Color ; 48 import java.awt.Font ; 49 import java.awt.GradientPaint ; 50 import java.io.ByteArrayInputStream ; 51 import java.io.ByteArrayOutputStream ; 52 import java.io.ObjectInput ; 53 import java.io.ObjectInputStream ; 54 import java.io.ObjectOutput ; 55 import java.io.ObjectOutputStream ; 56 57 import junit.framework.Test; 58 import junit.framework.TestCase; 59 import junit.framework.TestSuite; 60 61 import org.jfree.chart.title.TextTitle; 62 import org.jfree.ui.HorizontalAlignment; 63 64 67 public class TextTitleTests extends TestCase { 68 69 74 public static Test suite() { 75 return new TestSuite(TextTitleTests.class); 76 } 77 78 83 public TextTitleTests(String name) { 84 super(name); 85 } 86 87 90 public void testEquals() { 91 TextTitle t1 = new TextTitle(); 92 TextTitle t2 = new TextTitle(); 93 assertEquals(t1, t2); 94 95 t1.setText("Test 1"); 96 assertFalse(t1.equals(t2)); 97 t2.setText("Test 1"); 98 assertTrue(t1.equals(t2)); 99 100 Font f = new Font ("SansSerif", Font.PLAIN, 15); 101 t1.setFont(f); 102 assertFalse(t1.equals(t2)); 103 t2.setFont(f); 104 assertTrue(t1.equals(t2)); 105 106 t1.setTextAlignment(HorizontalAlignment.RIGHT); 107 assertFalse(t1.equals(t2)); 108 t2.setTextAlignment(HorizontalAlignment.RIGHT); 109 assertTrue(t1.equals(t2)); 110 111 t1.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 113 3.0f, 4.0f, Color.blue)); 114 assertFalse(t1.equals(t2)); 115 t2.setPaint(new GradientPaint (1.0f, 2.0f, Color.red, 116 3.0f, 4.0f, Color.blue)); 117 assertTrue(t1.equals(t2)); 118 119 t1.setBackgroundPaint(new GradientPaint (4.0f, 3.0f, Color.red, 121 2.0f, 1.0f, Color.blue)); 122 assertFalse(t1.equals(t2)); 123 t2.setBackgroundPaint(new GradientPaint (4.0f, 3.0f, Color.red, 124 2.0f, 1.0f, Color.blue)); 125 assertTrue(t1.equals(t2)); 126 127 } 128 129 132 public void testHashcode() { 133 TextTitle t1 = new TextTitle(); 134 TextTitle t2 = new TextTitle(); 135 assertTrue(t1.equals(t2)); 136 int h1 = t1.hashCode(); 137 int h2 = t2.hashCode(); 138 assertEquals(h1, h2); 139 } 140 141 144 public void testCloning() { 145 TextTitle t1 = new TextTitle(); 146 TextTitle t2 = null; 147 try { 148 t2 = (TextTitle) t1.clone(); 149 } 150 catch (CloneNotSupportedException e) { 151 System.err.println("TextTitleTests.testCloning: failed to clone."); 152 } 153 assertTrue(t1 != t2); 154 assertTrue(t1.getClass() == t2.getClass()); 155 assertTrue(t1.equals(t2)); 156 } 157 158 161 public void testSerialization() { 162 163 TextTitle t1 = new TextTitle("Test"); 164 TextTitle t2 = null; 165 166 try { 167 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 168 ObjectOutput out = new ObjectOutputStream (buffer); 169 out.writeObject(t1); 170 out.close(); 171 172 ObjectInput in = new ObjectInputStream ( 173 new ByteArrayInputStream (buffer.toByteArray()) 174 ); 175 t2 = (TextTitle) in.readObject(); 176 in.close(); 177 } 178 catch (Exception e) { 179 System.out.println(e.toString()); 180 } 181 assertEquals(t1, t2); 182 183 } 184 185 } 186 | Popular Tags |