001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: /**
018: * @author Anton Avtamonov
019: * @version $Revision$
020: */package javax.swing.plaf.basic;
021:
022: import java.awt.event.ActionEvent;
023: import java.awt.event.ActionListener;
024: import javax.swing.JTextField;
025: import javax.swing.SwingTestCase;
026: import javax.swing.text.JTextComponent;
027:
028: public class BasicComboBoxEditorTest extends SwingTestCase {
029: private BasicComboBoxEditor editor;
030:
031: public BasicComboBoxEditorTest(final String name) {
032: super (name);
033: }
034:
035: @Override
036: protected void setUp() throws Exception {
037: editor = new BasicComboBoxEditor();
038: }
039:
040: @Override
041: protected void tearDown() throws Exception {
042: editor = null;
043: }
044:
045: public void testBasicComboBoxEditor() throws Exception {
046: assertNotNull(editor.editor);
047: }
048:
049: public void testAddRemoveActionListener() throws Exception {
050: ActionController controller = new ActionController();
051: assertEquals(0, editor.editor.getActionListeners().length);
052: editor.addActionListener(controller);
053: assertEquals(1, editor.editor.getActionListeners().length);
054: editor.addActionListener(new ActionController());
055: assertEquals(2, editor.editor.getActionListeners().length);
056: editor.removeActionListener(controller);
057: assertEquals(1, editor.editor.getActionListeners().length);
058: }
059:
060: public void testGetEditorComponent() throws Exception {
061: assertNotNull(editor.getEditorComponent());
062: assertEquals(editor.editor, editor.getEditorComponent());
063: assertTrue(editor.getEditorComponent() instanceof JTextField);
064: }
065:
066: public void testGetSetItem() throws Exception {
067: assertEquals("", editor.getItem());
068: assertEquals("", editor.editor.getText());
069: Object item = "any";
070: editor.setItem(item);
071: assertEquals(item, editor.getItem());
072: assertEquals(item, editor.editor.getText());
073: item = "another";
074: editor.editor.setText(item.toString());
075: assertEquals(item, editor.editor.getText());
076: assertEquals(item, editor.getItem());
077: }
078:
079: public void testSelectAll() throws Exception {
080: assertNull(editor.editor.getSelectedText());
081: editor.setItem("any");
082: assertNull(editor.editor.getSelectedText());
083: editor.selectAll();
084: assertEquals("any", editor.editor.getSelectedText());
085: }
086:
087: private class ActionController implements ActionListener {
088: public void actionPerformed(final ActionEvent e) {
089: }
090: }
091:
092: /**
093: * Regression test for HARMONY-2651
094: * */
095: public void testRGetSetItem() {
096: editor.selectAll();
097: assertEquals("", editor.getItem());
098:
099: Object obj1 = new java.util.jar.Attributes.Name(
100: "AAAAAAAAAAAAAAA");
101: String obj2 = "BBBBBBBBBBBBB";
102: JTextComponent editorComponent = (JTextComponent) editor
103: .getEditorComponent();
104: editorComponent.setText(obj2);
105: editor.setItem(obj1);
106: assertSame(obj1, editor.getItem());
107: assertEquals(obj1.toString(), editorComponent.getText());
108: editor.setItem(null);
109: assertEquals("", editor.getItem());
110: }
111:
112: /**
113: * Regression test for HARMONY-2651
114: * */
115: public void testGetItem() {
116: editor.selectAll();
117: Object obj1 = new java.util.jar.Attributes.Name(
118: "AAAAAAAAAAAAAAA");
119: Object obj2 = "BBBBBBBBBBBBBB";
120: editor.setItem(obj1);
121: JTextComponent editorComponent = (JTextComponent) editor
122: .getEditorComponent();
123: editorComponent.setText((String) obj2);
124: assertNotSame(obj2, editor.getItem());
125: assertEquals(obj2, editor.getItem());
126: }
127:
128: }
|