1 42 43 package org.jfree.chart.axis.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 import java.util.TimeZone ; 52 53 import junit.framework.Test; 54 import junit.framework.TestCase; 55 import junit.framework.TestSuite; 56 57 import org.jfree.chart.axis.QuarterDateFormat; 58 59 62 public class QuarterDateFormatTests extends TestCase { 63 64 69 public static Test suite() { 70 return new TestSuite(QuarterDateFormatTests.class); 71 } 72 73 78 public QuarterDateFormatTests(String name) { 79 super(name); 80 } 81 82 85 public void testEquals() { 86 QuarterDateFormat qf1 = new QuarterDateFormat( 87 TimeZone.getTimeZone("GMT"), new String [] {"1", "2", "3", "4"} 88 ); 89 QuarterDateFormat qf2 = new QuarterDateFormat( 90 TimeZone.getTimeZone("GMT"), new String [] {"1", "2", "3", "4"} 91 ); 92 assertTrue(qf1.equals(qf2)); 93 assertTrue(qf2.equals(qf1)); 94 95 qf1 = new QuarterDateFormat( 96 TimeZone.getTimeZone("PST"), new String [] {"1", "2", "3", "4"} 97 ); 98 assertFalse(qf1.equals(qf2)); 99 qf2 = new QuarterDateFormat( 100 TimeZone.getTimeZone("PST"), new String [] {"1", "2", "3", "4"} 101 ); 102 assertTrue(qf1.equals(qf2)); 103 104 qf1 = new QuarterDateFormat( 105 TimeZone.getTimeZone("PST"), new String [] {"A", "2", "3", "4"} 106 ); 107 assertFalse(qf1.equals(qf2)); 108 qf2 = new QuarterDateFormat( 109 TimeZone.getTimeZone("PST"), new String [] {"A", "2", "3", "4"} 110 ); 111 assertTrue(qf1.equals(qf2)); 112 113 } 114 115 118 public void testHashCode() { 119 QuarterDateFormat qf1 = new QuarterDateFormat( 120 TimeZone.getTimeZone("GMT"), new String [] {"1", "2", "3", "4"} 121 ); 122 QuarterDateFormat qf2 = new QuarterDateFormat( 123 TimeZone.getTimeZone("GMT"), new String [] {"1", "2", "3", "4"} 124 ); 125 assertTrue(qf1.equals(qf2)); 126 int h1 = qf1.hashCode(); 127 int h2 = qf2.hashCode(); 128 assertEquals(h1, h2); 129 } 130 131 134 public void testCloning() { 135 QuarterDateFormat qf1 = new QuarterDateFormat( 136 TimeZone.getTimeZone("GMT"), new String [] {"1", "2", "3", "4"} 137 ); 138 QuarterDateFormat qf2 = null; 139 qf2 = (QuarterDateFormat) qf1.clone(); 140 assertTrue(qf1 != qf2); 141 assertTrue(qf1.getClass() == qf2.getClass()); 142 assertTrue(qf1.equals(qf2)); 143 } 144 145 148 public void testSerialization() { 149 QuarterDateFormat qf1 = new QuarterDateFormat( 150 TimeZone.getTimeZone("GMT"), new String [] {"1", "2", "3", "4"} 151 ); 152 QuarterDateFormat qf2 = null; 153 try { 154 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 155 ObjectOutput out = new ObjectOutputStream (buffer); 156 out.writeObject(qf1); 157 out.close(); 158 159 ObjectInput in = new ObjectInputStream ( 160 new ByteArrayInputStream (buffer.toByteArray()) 161 ); 162 qf2 = (QuarterDateFormat) in.readObject(); 163 in.close(); 164 } 165 catch (Exception e) { 166 fail(e.toString()); 167 } 168 assertTrue(qf1.equals(qf2)); 169 } 170 171 } 172 | Popular Tags |