KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jfree > chart > junit > MarkerTests


1 /* ======================================
2  * JFreeChart : a free Java chart library
3  * ======================================
4  *
5  * Project Info: http://www.jfree.org/jfreechart/index.html
6  * Project Lead: David Gilbert (david.gilbert@object-refinery.com);
7  *
8  * (C) Copyright 2000-2003, by Object Refinery Limited and Contributors.
9  *
10  * This library is free software; you can redistribute it and/or modify it under the terms
11  * of the GNU Lesser General Public License as published by the Free Software Foundation;
12  * either version 2.1 of the License, or (at your option) any later version.
13  *
14  * This library is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY;
15  * without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.
16  * See the GNU Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public License along with this
19  * library; if not, write to the Free Software Foundation, Inc., 59 Temple Place, Suite 330,
20  * Boston, MA 02111-1307, USA.
21  *
22  * ----------------
23  * MarkerTests.java
24  * ----------------
25  * (C) Copyright 2003 by Object Refinery Limited and Contributors.
26  *
27  * Original Author: David Gilbert (for Object Refinery Limited);
28  * Contributor(s): -;
29  *
30  * $Id: MarkerTests.java,v 1.1 2003/08/20 11:04:02 mungady Exp $
31  *
32  * Changes
33  * -------
34  * 18-Aug-2003 : Version 1 (DG);
35  *
36  */

37
38 package org.jfree.chart.junit;
39
40 import java.awt.Color JavaDoc;
41 import java.awt.Font JavaDoc;
42 import java.io.ByteArrayInputStream JavaDoc;
43 import java.io.ByteArrayOutputStream JavaDoc;
44 import java.io.ObjectInput JavaDoc;
45 import java.io.ObjectInputStream JavaDoc;
46 import java.io.ObjectOutput JavaDoc;
47 import java.io.ObjectOutputStream JavaDoc;
48
49 import junit.framework.Test;
50 import junit.framework.TestCase;
51 import junit.framework.TestSuite;
52
53 import org.jfree.chart.Marker;
54 import org.jfree.chart.Spacer;
55
56 /**
57  * Tests for the {@link Marker} class.
58  *
59  * @author David Gilbert
60  */

61 public class MarkerTests extends TestCase {
62
63     /**
64      * Returns the tests as a test suite.
65      *
66      * @return the test suite.
67      */

68     public static Test suite() {
69         return new TestSuite(MarkerTests.class);
70     }
71
72     /**
73      * Constructs a new set of tests.
74      *
75      * @param name the name of the tests.
76      */

77     public MarkerTests(String JavaDoc name) {
78         super(name);
79     }
80
81     /**
82      * Confirm that the equals method can distinguish all the required fields.
83      */

84     public void testEquals() {
85         
86         Marker m1 = new Marker(45.0);
87         Marker m2 = new Marker(45.0);
88         assertTrue(m1.equals(m2));
89         
90         m1.setLabel("New Label");
91         assertFalse(m1.equals(m2));
92         m2.setLabel("New Label");
93         assertTrue(m1.equals(m2));
94         
95         m1.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 10));
96         assertFalse(m1.equals(m2));
97         m2.setLabelFont(new Font JavaDoc("SansSerif", Font.PLAIN, 10));
98         assertTrue(m1.equals(m2));
99
100         m1.setLabelPaint(Color.red);
101         assertFalse(m1.equals(m2));
102         m2.setLabelPaint(Color.red);
103         assertTrue(m1.equals(m2));
104
105     }
106         
107     /**
108      * Serialize an instance, restore it, and check for equality.
109      */

110     public void testSerialization() {
111
112         Spacer s1 = new Spacer(Spacer.ABSOLUTE, 0.05, 0.05, 0.05, 0.05);
113         Spacer s2 = null;
114
115         try {
116             ByteArrayOutputStream JavaDoc buffer = new ByteArrayOutputStream JavaDoc();
117             ObjectOutput JavaDoc out = new ObjectOutputStream JavaDoc(buffer);
118             out.writeObject(s1);
119             out.close();
120
121             ObjectInput JavaDoc in = new ObjectInputStream JavaDoc(new ByteArrayInputStream JavaDoc(buffer.toByteArray()));
122             s2 = (Spacer) in.readObject();
123             in.close();
124         }
125         catch (Exception JavaDoc e) {
126             System.out.println(e.toString());
127         }
128         boolean b = s1.equals(s2);
129         assertTrue(b);
130
131     }
132
133 }
134
Popular Tags