~ubuntu-branches/ubuntu/precise/libjcommon-java/precise

« back to all changes in this revision

Viewing changes to source/org/jfree/text/junit/TextFragmentTests.java

  • Committer: Bazaar Package Importer
  • Author(s): Matthias Klose
  • Date: 2006-10-01 14:12:07 UTC
  • mfrom: (1.1.2 upstream) (4 edgy)
  • mto: This revision was merged to the branch mainline in revision 6.
  • Revision ID: james.westby@ubuntu.com-20061001141207-2aipqlhpmn45t3ng
New upstream release.

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
/* ========================================================================
 
2
 * JCommon : a free general purpose class library for the Java(tm) platform
 
3
 * ========================================================================
 
4
 *
 
5
 * (C) Copyright 2000-2005, by Object Refinery Limited and Contributors.
 
6
 * 
 
7
 * Project Info:  http://www.jfree.org/jcommon/index.html
 
8
 *
 
9
 * This library is free software; you can redistribute it and/or modify it 
 
10
 * under the terms of the GNU Lesser General Public License as published by 
 
11
 * the Free Software Foundation; either version 2.1 of the License, or 
 
12
 * (at your option) any later version.
 
13
 *
 
14
 * This library is distributed in the hope that it will be useful, but 
 
15
 * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY 
 
16
 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General Public 
 
17
 * License for more details.
 
18
 *
 
19
 * You should have received a copy of the GNU Lesser General Public
 
20
 * License along with this library; if not, write to the Free Software
 
21
 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301, 
 
22
 * USA.  
 
23
 *
 
24
 * [Java is a trademark or registered trademark of Sun Microsystems, Inc. 
 
25
 * in the United States and other countries.]
 
26
 * 
 
27
 * ----------------------
 
28
 * TextFragmentTests.java
 
29
 * ----------------------
 
30
 * (C) Copyright 2004, 2005, by Object Refinery Limited.
 
31
 *
 
32
 * Original Author:  David Gilbert (for Object Refinery Limited);
 
33
 * Contributor(s):   -;
 
34
 *
 
35
 * $Id: TextFragmentTests.java,v 1.4 2005/11/16 15:58:41 taqua Exp $
 
36
 *
 
37
 * Changes:
 
38
 * --------
 
39
 * 22-Mar-2004 : Version 1 (DG);
 
40
 *
 
41
 */
 
42
 
 
43
package org.jfree.text.junit;
 
44
 
 
45
import java.awt.Color;
 
46
import java.awt.Font;
 
47
import java.io.ByteArrayInputStream;
 
48
import java.io.ByteArrayOutputStream;
 
49
import java.io.ObjectInput;
 
50
import java.io.ObjectInputStream;
 
51
import java.io.ObjectOutput;
 
52
import java.io.ObjectOutputStream;
 
53
 
 
54
import junit.framework.Test;
 
55
import junit.framework.TestCase;
 
56
import junit.framework.TestSuite;
 
57
 
 
58
import org.jfree.text.TextFragment;
 
59
 
 
60
/**
 
61
 * Tests for the {@link TextFragment} class.
 
62
 */
 
63
public class TextFragmentTests extends TestCase {
 
64
 
 
65
    /**
 
66
     * Returns the tests as a test suite.
 
67
     *
 
68
     * @return The test suite.
 
69
     */
 
70
    public static Test suite() {
 
71
        return new TestSuite(TextFragmentTests.class);
 
72
    }
 
73
 
 
74
    /**
 
75
     * Constructs a new set of tests.
 
76
     *
 
77
     * @param name  the name of the tests.
 
78
     */
 
79
    public TextFragmentTests(final String name) {
 
80
        super(name);
 
81
    }
 
82
 
 
83
    /**
 
84
     * Confirm that the equals method can distinguish all the required fields.
 
85
     */
 
86
    public void testEquals() {
 
87
        
 
88
        TextFragment tf1 = new TextFragment("Test");
 
89
        TextFragment tf2 = new TextFragment("Test");
 
90
        assertTrue(tf1.equals(tf2));
 
91
        assertTrue(tf2.equals(tf1));
 
92
 
 
93
        // text
 
94
        tf1 = new TextFragment("Test 1");
 
95
        assertFalse(tf1.equals(tf2));
 
96
        tf2 = new TextFragment("Test 1");
 
97
        assertTrue(tf1.equals(tf2));
 
98
 
 
99
        // font
 
100
        tf1 = new TextFragment("Test 1", new Font("Arial", Font.BOLD, 11));
 
101
        assertFalse(tf1.equals(tf2));
 
102
        tf2 = new TextFragment("Test 1", new Font("Arial", Font.BOLD, 11));
 
103
        assertTrue(tf1.equals(tf2));
 
104
        
 
105
        // paint
 
106
        tf1 = new TextFragment("Test 1", new Font("Arial", Font.BOLD, 11), Color.red);
 
107
        assertFalse(tf1.equals(tf2));
 
108
        tf2 = new TextFragment("Test 1", new Font("Arial", Font.BOLD, 11), Color.red);
 
109
        assertTrue(tf1.equals(tf2));
 
110
 
 
111
    }
 
112
 
 
113
    /**
 
114
     * Serialize an instance, restore it, and check for equality.
 
115
     */
 
116
    public void testSerialization() {
 
117
 
 
118
        final TextFragment tf1 = new TextFragment("Test");
 
119
        TextFragment tf2 = null;
 
120
 
 
121
        try {
 
122
            final ByteArrayOutputStream buffer = new ByteArrayOutputStream();
 
123
            final ObjectOutput out = new ObjectOutputStream(buffer);
 
124
            out.writeObject(tf1);
 
125
            out.close();
 
126
 
 
127
            final ObjectInput in = new ObjectInputStream(new ByteArrayInputStream(buffer.toByteArray()));
 
128
            tf2 = (TextFragment) in.readObject();
 
129
            in.close();
 
130
        }
 
131
        catch (Exception e) {
 
132
            System.out.println(e.toString());
 
133
        }
 
134
        assertEquals(tf1, tf2);
 
135
 
 
136
    }
 
137
 
 
138
}