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.text.SimpleDateFormat ; 52 import java.util.Locale ; 53 import java.util.TimeZone ; 54 55 import junit.framework.Test; 56 import junit.framework.TestCase; 57 import junit.framework.TestSuite; 58 59 import org.jfree.chart.axis.MonthDateFormat; 60 61 64 public class MonthDateFormatTests extends TestCase { 65 66 71 public static Test suite() { 72 return new TestSuite(MonthDateFormatTests.class); 73 } 74 75 80 public MonthDateFormatTests(String name) { 81 super(name); 82 } 83 84 87 public void testEquals() { 88 MonthDateFormat mf1 = new MonthDateFormat(); 89 MonthDateFormat mf2 = new MonthDateFormat(); 90 assertTrue(mf1.equals(mf2)); 91 assertTrue(mf2.equals(mf1)); 92 93 boolean[] showYear1 = new boolean [12]; 94 showYear1[0] = true; 95 boolean[] showYear2 = new boolean [12]; 96 showYear1[1] = true; 97 98 mf1 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.US, 1, 100 showYear1, new SimpleDateFormat ("yy")); 101 assertFalse(mf1.equals(mf2)); 102 mf2 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.US, 1, 103 showYear1, new SimpleDateFormat ("yy")); 104 assertTrue(mf1.equals(mf2)); 105 106 mf1 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 1, 108 showYear1, new SimpleDateFormat ("yy")); 109 assertFalse(mf1.equals(mf2)); 110 mf2 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 1, 111 showYear1, new SimpleDateFormat ("yy")); 112 assertTrue(mf1.equals(mf2)); 113 114 mf1 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 2, 116 showYear1, new SimpleDateFormat ("yy")); 117 assertFalse(mf1.equals(mf2)); 118 mf2 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 2, 119 showYear1, new SimpleDateFormat ("yy")); 120 assertTrue(mf1.equals(mf2)); 121 122 mf1 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 2, 124 showYear2, new SimpleDateFormat ("yy")); 125 assertFalse(mf1.equals(mf2)); 126 mf2 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 2, 127 showYear2, new SimpleDateFormat ("yy")); 128 assertTrue(mf1.equals(mf2)); 129 130 mf1 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 2, 132 showYear2, new SimpleDateFormat ("yyyy")); 133 assertFalse(mf1.equals(mf2)); 134 mf2 = new MonthDateFormat(TimeZone.getTimeZone("PST"), Locale.FRANCE, 2, 135 showYear2, new SimpleDateFormat ("yyyy")); 136 assertTrue(mf1.equals(mf2)); 137 138 } 139 140 143 public void testHashCode() { 144 MonthDateFormat mf1 = new MonthDateFormat(); 145 MonthDateFormat mf2 = new MonthDateFormat(); 146 assertTrue(mf1.equals(mf2)); 147 int h1 = mf1.hashCode(); 148 int h2 = mf2.hashCode(); 149 assertEquals(h1, h2); 150 } 151 152 155 public void testCloning() { 156 MonthDateFormat mf1 = new MonthDateFormat(); 157 MonthDateFormat mf2 = null; 158 mf2 = (MonthDateFormat) mf1.clone(); 159 assertTrue(mf1 != mf2); 160 assertTrue(mf1.getClass() == mf2.getClass()); 161 assertTrue(mf1.equals(mf2)); 162 } 163 164 167 public void testSerialization() { 168 MonthDateFormat mf1 = new MonthDateFormat(); 169 MonthDateFormat mf2 = null; 170 try { 171 ByteArrayOutputStream buffer = new ByteArrayOutputStream (); 172 ObjectOutput out = new ObjectOutputStream (buffer); 173 out.writeObject(mf1); 174 out.close(); 175 176 ObjectInput in = new ObjectInputStream ( 177 new ByteArrayInputStream (buffer.toByteArray()) 178 ); 179 mf2 = (MonthDateFormat) in.readObject(); 180 in.close(); 181 } 182 catch (Exception e) { 183 fail(e.toString()); 184 } 185 assertTrue(mf1.equals(mf2)); 186 } 187 188 } 189 | Popular Tags |