01: package org.uispec4j.interception.ui;
02:
03: import org.uispec4j.utils.UnitTestCase;
04:
05: import javax.swing.*;
06: import java.lang.reflect.Method;
07: import java.util.Arrays;
08: import java.util.Enumeration;
09: import java.util.List;
10:
11: public class UISpecLFTest extends UnitTestCase {
12:
13: private List exceptions = Arrays.asList(new String[] {
14: "TabbedPaneUI", "ViewportUI" });
15:
16: // This test only works when run alone
17: public void disabled_testAllComponentUIClassesAreOverriden()
18: throws Exception {
19: UISpecLF.init();
20: UIDefaults defaults = UIManager.getDefaults();
21: for (Enumeration dfkeys = defaults.keys(); dfkeys
22: .hasMoreElements();) {
23: String key = dfkeys.nextElement().toString();
24: if (key.endsWith("UI")) {
25: Object value = defaults.get(key);
26: if ((value != null)
27: && (value.toString().indexOf("UISpec") < 0)
28: && (!exceptions.contains(key))) {
29: fail(key + " is not overriden (value: " + value
30: + ")");
31: }
32: }
33: }
34: }
35:
36: public void testSwingComponentsUseUISpecUIs() throws Exception {
37: checkUI(new JButton(), UISpecButtonUI.class);
38: checkUI(new JCheckBoxMenuItem(), UISpecCheckBoxMenuItemUI.class);
39: checkUI(new JCheckBox(), UISpecCheckBoxUI.class);
40: checkUI(new JColorChooser(), UISpecColorChooserUI.class);
41: checkUI(new JComboBox(), UISpecComboBoxUI.class);
42: checkUI(new JDesktopPane(), UISpecDesktopPaneUI.class);
43: checkUI(new JEditorPane(), UISpecEditorPaneUI.class);
44: checkUI(new JFileChooser(), UISpecFileChooserUI.class);
45: checkUI(new JFormattedTextField(),
46: UISpecFormattedTextFieldUI.class);
47: checkUI(new JInternalFrame(), UISpecInternalFrameUI.class);
48: checkUI(new JLabel(), UISpecLabelUI.class);
49: checkUI(new JList(), UISpecListUI.class);
50: checkUI(new JMenuBar(), UISpecMenuBarUI.class);
51: checkUI(new JMenuItem(), UISpecMenuItemUI.class);
52: checkUI(new JMenu(), UISpecMenuUI.class);
53: checkUI(new JOptionPane(), UISpecOptionPaneUI.class);
54: checkUI(new JPanel(), UISpecPanelUI.class);
55: checkUI(new JPasswordField(), UISpecPasswordFieldUI.class);
56: checkUI(new JPopupMenu(), UISpecPopupMenuUI.class);
57: checkUI(new JProgressBar(), UISpecProgressBarUI.class);
58: checkUI(new JRadioButtonMenuItem(),
59: UISpecRadioButtonMenuItemUI.class);
60: checkUI(new JRadioButton(), UISpecRadioButtonUI.class);
61: checkUI(new JRootPane(), UISpecRootPaneUI.class);
62: checkUI(new JScrollBar(), UISpecScrollBarUI.class);
63: checkUI(new JScrollPane(), UISpecScrollPaneUI.class);
64: checkUI(new JSeparator(), UISpecSeparatorUI.class);
65: checkUI(new JSlider(), UISpecSliderUI.class);
66: checkUI(new JSpinner(), UISpecSpinnerUI.class);
67: checkUI(new JSplitPane(), UISpecSplitPaneUI.class);
68: checkUI(new JTable(), UISpecTableUI.class);
69: checkUI(new JTextArea(), UISpecTextAreaUI.class);
70: checkUI(new JTextField(), UISpecTextFieldUI.class);
71: checkUI(new JTextPane(), UISpecTextPaneUI.class);
72: checkUI(new JToggleButton(), UISpecToggleButtonUI.class);
73: checkUI(new JToolBar(), UISpecToolBarUI.class);
74: checkUI(new JToolTip(), UISpecToolTipUI.class);
75: checkUI(new JTree(), UISpecTreeUI.class);
76: }
77:
78: private void checkUI(JComponent component, Class expectedUIClass)
79: throws Exception {
80: Method method = component.getClass().getMethod("getUI",
81: new Class[0]);
82: Object result = method.invoke(component, new Object[0]);
83: assertTrue(expectedUIClass.isInstance(result));
84: }
85: }
|