001: /* ===========================================================
002: * JFreeChart : a free chart library for the Java(tm) platform
003: * ===========================================================
004: *
005: * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
006: *
007: * Project Info: http://www.jfree.org/jfreechart/index.html
008: *
009: * This library is free software; you can redistribute it and/or modify it
010: * under the terms of the GNU Lesser General Public License as published by
011: * the Free Software Foundation; either version 2.1 of the License, or
012: * (at your option) any later version.
013: *
014: * This library is distributed in the hope that it will be useful, but
015: * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
016: * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public
017: * License for more details.
018: *
019: * You should have received a copy of the GNU Lesser General Public
020: * License along with this library; if not, write to the Free Software
021: * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301,
022: * USA.
023: *
024: * [Java is a trademark or registered trademark of Sun Microsystems, Inc.
025: * in the United States and other countries.]
026: *
027: * --------------------------
028: * FixedMillisecondTests.java
029: * --------------------------
030: * (C) Copyright 2002-2005 by Object Refinery Limited.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: FixedMillisecondTests.java,v 1.1.2.1 2006/10/03 15:41:39 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 29-Jan-2002 : Version 1 (DG);
040: * 17-Oct-2002 : Fixed errors reported by Checkstyle (DG);
041: * 21-Oct-2003 : Added hashCode test (DG);
042: *
043: */
044:
045: package org.jfree.data.time.junit;
046:
047: import java.io.ByteArrayInputStream;
048: import java.io.ByteArrayOutputStream;
049: import java.io.ObjectInput;
050: import java.io.ObjectInputStream;
051: import java.io.ObjectOutput;
052: import java.io.ObjectOutputStream;
053:
054: import junit.framework.Test;
055: import junit.framework.TestCase;
056: import junit.framework.TestSuite;
057:
058: import org.jfree.data.time.FixedMillisecond;
059:
060: /**
061: * Tests for the {@link FixedMillisecond} class.
062: */
063: public class FixedMillisecondTests extends TestCase {
064:
065: /**
066: * Returns the tests as a test suite.
067: *
068: * @return The test suite.
069: */
070: public static Test suite() {
071: return new TestSuite(FixedMillisecondTests.class);
072: }
073:
074: /**
075: * Constructs a new set of tests.
076: *
077: * @param name the name of the tests.
078: */
079: public FixedMillisecondTests(String name) {
080: super (name);
081: }
082:
083: /**
084: * Serialize an instance, restore it, and check for equality.
085: */
086: public void testSerialization() {
087:
088: FixedMillisecond m1 = new FixedMillisecond();
089: FixedMillisecond m2 = null;
090:
091: try {
092: ByteArrayOutputStream buffer = new ByteArrayOutputStream();
093: ObjectOutput out = new ObjectOutputStream(buffer);
094: out.writeObject(m1);
095: out.close();
096:
097: ObjectInput in = new ObjectInputStream(
098: new ByteArrayInputStream(buffer.toByteArray()));
099: m2 = (FixedMillisecond) in.readObject();
100: in.close();
101: } catch (Exception e) {
102: System.out.println(e.toString());
103: }
104: assertEquals(m1, m2);
105:
106: }
107:
108: /**
109: * Two objects that are equal are required to return the same hashCode.
110: */
111: public void testHashcode() {
112: FixedMillisecond m1 = new FixedMillisecond(500000L);
113: FixedMillisecond m2 = new FixedMillisecond(500000L);
114: assertTrue(m1.equals(m2));
115: int h1 = m1.hashCode();
116: int h2 = m2.hashCode();
117: assertEquals(h1, h2);
118: }
119:
120: /**
121: * The {@link FixedMillisecond} class is immutable, so should not be
122: * {@link Cloneable}.
123: */
124: public void testNotCloneable() {
125: FixedMillisecond m = new FixedMillisecond(500000L);
126: assertFalse(m instanceof Cloneable);
127: }
128:
129: }
|