001: /* ========================================================================
002: * JCommon : a free general purpose class 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/jcommon/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: * ObjectTableTests.java
029: * --------------------
030: * (C) Copyright 2003-2005, by Object Refinery Limited and Contributors.
031: *
032: * Original Author: David Gilbert (for Object Refinery Limited);
033: * Contributor(s): -;
034: *
035: * $Id: ObjectTableTests.java,v 1.5 2005/10/18 13:25:14 mungady Exp $
036: *
037: * Changes
038: * -------
039: * 29-Apr-2003 : Version 1 (DG);
040: *
041: */
042:
043: package org.jfree.util.junit;
044:
045: import java.awt.Color;
046:
047: import junit.framework.Test;
048: import junit.framework.TestCase;
049: import junit.framework.TestSuite;
050:
051: import org.jfree.util.ObjectTable;
052:
053: /**
054: * Tests for the {@link ObjectTable} class.
055: */
056: public class ObjectTableTests extends TestCase {
057:
058: /**
059: * Basic object table.
060: */
061: public class TObjectTable extends ObjectTable {
062:
063: /**
064: * Constructor.
065: */
066: public TObjectTable() {
067: super ();
068: }
069:
070: /**
071: * Returns the object from a particular cell in the table.
072: * Returns null, if there is no object at the given position.
073: *
074: * @param row the row index (zero-based).
075: * @param column the column index (zero-based).
076: *
077: * @return The object.
078: */
079: public Object getObject(final int row, final int column) {
080: return super .getObject(row, column);
081: }
082:
083: /**
084: * Sets the object for a cell in the table. The table is expanded if necessary.
085: *
086: * @param row the row index (zero-based).
087: * @param column the column index (zero-based).
088: * @param object the object.
089: */
090: public void setObject(final int row, final int column,
091: final Object object) {
092: super .setObject(row, column, object);
093: }
094: }
095:
096: /**
097: * Returns the tests as a test suite.
098: *
099: * @return The test suite.
100: */
101: public static Test suite() {
102: return new TestSuite(ObjectTableTests.class);
103: }
104:
105: /**
106: * Constructs a new set of tests.
107: *
108: * @param name the name of the tests.
109: */
110: public ObjectTableTests(final String name) {
111: super (name);
112: }
113:
114: /**
115: * When an ObjectTable is created, it should be empty and return null for all lookups.
116: */
117: public void testCreate() {
118:
119: final TObjectTable t = new TObjectTable();
120:
121: // the new table should have zero rows and zero columns...
122: assertEquals(t.getColumnCount(), 0);
123: assertEquals(t.getRowCount(), 0);
124:
125: // ...and should return null for any lookup
126: assertNull(t.getObject(0, 0));
127: assertNull(t.getObject(12, 12));
128:
129: }
130:
131: /**
132: * When an object is added to the table outside the current bounds, the table
133: * should resize automatically.
134: */
135: public void testSetObject1() {
136:
137: final TObjectTable t = new TObjectTable();
138: t.setObject(8, 5, Color.red);
139: assertEquals(6, t.getColumnCount());
140: assertEquals(9, t.getRowCount());
141: assertNull(t.getObject(7, 4));
142: assertEquals(Color.red, t.getObject(8, 5));
143:
144: }
145:
146: }
|