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.metal;
021:
022: import java.awt.Dimension;
023: import java.util.Arrays;
024: import java.util.List;
025: import javax.swing.ActionMap;
026: import javax.swing.JButton;
027: import javax.swing.JFileChooser;
028: import javax.swing.JList;
029: import javax.swing.JPanel;
030: import javax.swing.JScrollPane;
031: import javax.swing.SwingTestCase;
032:
033: public class MetalFileChooserUITest extends SwingTestCase {
034: private MetalFileChooserUI ui;
035:
036: private JFileChooser fc;
037:
038: public MetalFileChooserUITest(final String name) {
039: super (name);
040: }
041:
042: @Override
043: protected void setUp() throws Exception {
044: fc = new JFileChooser();
045: ui = new MetalFileChooserUI(fc);
046: }
047:
048: @Override
049: protected void tearDown() throws Exception {
050: ui = null;
051: fc = null;
052: }
053:
054: public void testCreateUI() throws Exception {
055: assertNotSame(MetalFileChooserUI.createUI(fc),
056: MetalFileChooserUI.createUI(fc));
057: }
058:
059: public void testGetButtonPanel() throws Exception {
060: JPanel buttonPanel = ui.getButtonPanel();
061: assertNotNull(buttonPanel);
062: assertEquals(0, buttonPanel.getComponentCount());
063: assertEquals(ui.getButtonPanel(), ui.getButtonPanel());
064: }
065:
066: public void testGetBottomPanel() throws Exception {
067: JPanel bottomPanel = ui.getBottomPanel();
068: assertNotNull(bottomPanel);
069: assertEquals(0, bottomPanel.getComponentCount());
070: assertEquals(ui.getBottomPanel(), ui.getBottomPanel());
071: }
072:
073: public void testGetActionMap() throws Exception {
074: ActionMap actionMap = ui.getActionMap();
075: assertNotNull(actionMap);
076: assertNotSame(ui.getActionMap(), ui.getActionMap());
077: }
078:
079: public void testCreateActionMap() throws Exception {
080: ui.installUI(fc);
081: ActionMap map = ui.createActionMap();
082: List<Object> allKeys = Arrays.asList(map.allKeys());
083: assertEquals(3, allKeys.size());
084: assertTrue(allKeys.contains("approveSelection"));
085: assertEquals(ui.getApproveSelectionAction(), map
086: .get("approveSelection"));
087: assertTrue(allKeys.contains("cancelSelection"));
088: assertEquals(ui.getCancelSelectionAction(), map
089: .get("cancelSelection"));
090: assertTrue(allKeys.contains("Go Up"));
091: assertEquals(ui.getChangeToParentDirectoryAction(), map
092: .get("Go Up"));
093: }
094:
095: public void testCreateList() throws Exception {
096: ui.installUI(fc);
097: JPanel listPanel = ui.createList(fc);
098: assertNotNull(listPanel);
099: if (isHarmony()) {
100: assertEquals(2, listPanel.getComponentCount());
101: }
102: assertTrue(listPanel.getComponent(0) instanceof JScrollPane);
103: assertTrue(((JScrollPane) listPanel.getComponent(0))
104: .getViewport().getView() instanceof JList);
105: JList list = (JList) ((JScrollPane) listPanel.getComponent(0))
106: .getViewport().getView();
107: assertEquals(ui.getModel(), list.getModel());
108: assertNotSame(ui.createList(fc), ui.createList(fc));
109: }
110:
111: // TODO: detail view is not implemented yet
112: public void testCreateDetailsView() throws Exception {
113: ui.installUI(fc);
114: // JPanel detailsView = ui.createDetailsView(fc);
115: // assertNotNull(detailsView);
116: // assertEquals(1, detailsView.getComponentCount());
117: // assertTrue(detailsView.getComponent(0) instanceof JScrollPane);
118: // assertTrue(((JScrollPane)detailsView.getComponent(0)).getViewport().getView() instanceof JTable);
119: // JTable table = (JList)((JScrollPane)listPanel.getComponent(0)).getViewport().getView();
120: // assertEquals(ui.getModel(), list.getModel());
121: // assertNotSame(ui.createList(fc), ui.createList(fc));
122: }
123:
124: public void testCreateListSelectionListener() throws Exception {
125: assertNotNull(ui.createListSelectionListener(null));
126: assertNotSame(ui.createListSelectionListener(null), ui
127: .createListSelectionListener(null));
128: }
129:
130: public void testGetPreferredSize() throws Exception {
131: assertNotNull(ui.getPreferredSize(fc));
132: }
133:
134: public void testGetMinimumSize() throws Exception {
135: assertNotNull(ui.getMinimumSize(fc));
136: }
137:
138: public void testGetMaxiumumSize() throws Exception {
139: assertNotNull(ui.getMaximumSize(null));
140: assertEquals(
141: new Dimension(Integer.MAX_VALUE, Integer.MAX_VALUE), ui
142: .getMaximumSize(null));
143: }
144:
145: public void testCreatePropertyChangeListener() throws Exception {
146: assertNotNull(ui.createPropertyChangeListener(null));
147: }
148:
149: public void testGetApproveSelectionButton() throws Exception {
150: ui.installUI(fc);
151: JButton button = ui.getApproveButton(null);
152: assertNotNull(button);
153: assertEquals(ui.getApproveButtonText(fc), button.getText());
154: }
155:
156: public void testGetApproveButton() throws Exception {
157: ui.installUI(fc);
158: assertNotNull(ui.getApproveButton(fc));
159: assertEquals(ui.getApproveButton(fc), ui.getApproveButton(fc));
160: }
161: // private void traverse(final Container cont) {
162: // for (int i = 0; i < cont.getComponentCount(); i++) {
163: // Component child = cont.getComponent(i);
164: // if (child instanceof JButton) {
165: // System.err.println("Button " + ((JButton)child).getText());
166: // }
167: //
168: // if (child instanceof Container) {
169: // traverse((Container)child);
170: // }
171: // }
172: // }
173: }
|