001: /*
002: * This file is part of the Echo Web Application Framework (hereinafter "Echo").
003: * Copyright (C) 2002-2005 NextApp, Inc.
004: *
005: * Version: MPL 1.1/GPL 2.0/LGPL 2.1
006: *
007: * The contents of this file are subject to the Mozilla Public License Version
008: * 1.1 (the "License"); you may not use this file except in compliance with
009: * the License. You may obtain a copy of the License at
010: * http://www.mozilla.org/MPL/
011: *
012: * Software distributed under the License is distributed on an "AS IS" basis,
013: * WITHOUT WARRANTY OF ANY KIND, either express or implied. See the License
014: * for the specific language governing rights and limitations under the
015: * License.
016: *
017: * Alternatively, the contents of this file may be used under the terms of
018: * either the GNU General Public License Version 2 or later (the "GPL"), or
019: * the GNU Lesser General Public License Version 2.1 or later (the "LGPL"),
020: * in which case the provisions of the GPL or the LGPL are applicable instead
021: * of those above. If you wish to allow use of your version of this file only
022: * under the terms of either the GPL or the LGPL, and not to allow others to
023: * use your version of this file under the terms of the MPL, indicate your
024: * decision by deleting the provisions above and replace them with the notice
025: * and other provisions required by the GPL or the LGPL. If you do not delete
026: * the provisions above, a recipient may use your version of this file under
027: * the terms of any one of the MPL, the GPL or the LGPL.
028: */
029:
030: package nextapp.echo2.app.test;
031:
032: import nextapp.echo2.app.Color;
033: import nextapp.echo2.app.SelectField;
034: import nextapp.echo2.app.event.ActionEvent;
035: import nextapp.echo2.app.event.ActionListener;
036: import junit.framework.TestCase;
037:
038: /**
039: * Unit tests for the <code>nextapp.echo2.app.SelectField</code> component.
040: */
041: public class SelectFieldTest extends TestCase {
042:
043: private class ActionHandler implements ActionListener {
044:
045: private ActionEvent lastEvent;
046:
047: public void actionPerformed(ActionEvent e) {
048: lastEvent = e;
049: }
050: }
051:
052: /**
053: * Ensures that invoking <code>getSelectedItem</code> on a
054: * <code>SelectField</code> with no selected items returns null.
055: */
056: public void testGetSelectedItemNull() {
057: SelectField selectField = new SelectField();
058: assertNull(selectField.getSelectedItem());
059: }
060:
061: /**
062: * Test Adding/Removing <code>ActionListener</code>s and
063: * receiving events.
064: */
065: public void testActionListeners() {
066: SelectField selectField = new SelectField();
067: selectField.setActionCommand("action!");
068:
069: assertFalse(selectField.hasActionListeners());
070:
071: ActionHandler actionHandler = new ActionHandler();
072: selectField.addActionListener(actionHandler);
073:
074: assertTrue(selectField.hasActionListeners());
075:
076: selectField.processInput(SelectField.INPUT_ACTION, null);
077: assertNotNull(actionHandler.lastEvent);
078: assertEquals(selectField, actionHandler.lastEvent.getSource());
079: assertEquals("action!", actionHandler.lastEvent
080: .getActionCommand());
081:
082: selectField.removeActionListener(actionHandler);
083:
084: assertFalse(selectField.hasActionListeners());
085: }
086:
087: /**
088: * Test property accessors and mutators.
089: */
090: public void testProperties() {
091: SelectField selectField = new SelectField();
092: selectField.setActionCommand("action!");
093: selectField.setBorder(TestConstants.BORDER_THICK_ORANGE);
094: selectField.setHeight(TestConstants.EXTENT_30_PX);
095: selectField.setInsets(TestConstants.INSETS_1234);
096: selectField.setRolloverEnabled(true);
097: selectField.setRolloverBackground(Color.GREEN);
098: selectField.setRolloverFont(TestConstants.MONOSPACE_12);
099: selectField.setRolloverForeground(Color.YELLOW);
100: selectField.setWidth(TestConstants.EXTENT_100_PX);
101: assertEquals("action!", selectField.getActionCommand());
102: assertEquals(TestConstants.BORDER_THICK_ORANGE, selectField
103: .getBorder());
104: assertEquals(Color.GREEN, selectField.getRolloverBackground());
105: assertEquals(true, selectField.isRolloverEnabled());
106: assertEquals(TestConstants.MONOSPACE_12, selectField
107: .getRolloverFont());
108: assertEquals(Color.YELLOW, selectField.getRolloverForeground());
109: assertEquals(TestConstants.EXTENT_30_PX, selectField
110: .getHeight());
111: assertEquals(TestConstants.INSETS_1234, selectField.getInsets());
112: assertEquals(TestConstants.EXTENT_100_PX, selectField
113: .getWidth());
114: }
115: }
|