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.ListBox;
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.ListBox</code> component.
040: */
041: public class ListBoxTest 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: * Test Adding/Removing <code>ActionListener</code>s and
054: * receiving events.
055: */
056: public void testActionListeners() {
057: ListBox listBox = new ListBox();
058: listBox.setActionCommand("action!");
059:
060: assertFalse(listBox.hasActionListeners());
061:
062: ActionHandler actionHandler = new ActionHandler();
063: listBox.addActionListener(actionHandler);
064:
065: assertTrue(listBox.hasActionListeners());
066:
067: listBox.processInput(ListBox.INPUT_ACTION, null);
068: assertNotNull(actionHandler.lastEvent);
069: assertEquals(listBox, actionHandler.lastEvent.getSource());
070: assertEquals("action!", actionHandler.lastEvent
071: .getActionCommand());
072:
073: listBox.removeActionListener(actionHandler);
074:
075: assertFalse(listBox.hasActionListeners());
076: }
077:
078: /**
079: * Test property accessors and mutators.
080: */
081: public void testProperties() {
082: ListBox listBox = new ListBox();
083: listBox.setActionCommand("action!");
084: listBox.setBorder(TestConstants.BORDER_THICK_ORANGE);
085: listBox.setHeight(TestConstants.EXTENT_30_PX);
086: listBox.setInsets(TestConstants.INSETS_1234);
087: listBox.setRolloverEnabled(true);
088: listBox.setRolloverBackground(Color.GREEN);
089: listBox.setRolloverFont(TestConstants.MONOSPACE_12);
090: listBox.setRolloverForeground(Color.YELLOW);
091: listBox.setWidth(TestConstants.EXTENT_100_PX);
092: assertEquals("action!", listBox.getActionCommand());
093: assertEquals(TestConstants.BORDER_THICK_ORANGE, listBox
094: .getBorder());
095: assertEquals(Color.GREEN, listBox.getRolloverBackground());
096: assertEquals(true, listBox.isRolloverEnabled());
097: assertEquals(TestConstants.MONOSPACE_12, listBox
098: .getRolloverFont());
099: assertEquals(Color.YELLOW, listBox.getRolloverForeground());
100: assertEquals(TestConstants.EXTENT_30_PX, listBox.getHeight());
101: assertEquals(TestConstants.INSETS_1234, listBox.getInsets());
102: assertEquals(TestConstants.EXTENT_100_PX, listBox.getWidth());
103: }
104: }
|